forked from nus-cs2103-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from tituschewxj/wrap-up-v1.3
Wrap up v1.3.1
- Loading branch information
Showing
15 changed files
with
495 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/seedu/address/logic/autocomplete/AutoCompleteEmail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package seedu.address.logic.autocomplete; | ||
|
||
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
|
||
import seedu.address.commons.util.Trie; | ||
|
||
// TODO: code quality issues | ||
/** | ||
* AutoComplete for major. | ||
*/ | ||
public class AutoCompleteEmail implements AutoComplete { | ||
private static Trie majorTrie; | ||
private static final Pattern MAJOR_FORMAT = Pattern.compile(PREFIX_EMAIL.getPrefix() + "(.*)"); | ||
|
||
/** | ||
* Initializes the major trie with the given majors. This method should be called once at | ||
* the start of the initialization of LogicManager. | ||
* | ||
* @param majors the majors to initialize the trie with | ||
*/ | ||
public static void initialize(String... majors) { | ||
majorTrie = new Trie(Arrays.stream(majors).toArray(String[]::new)); | ||
} | ||
|
||
/** | ||
* Update the majors trie with the given majors. This method is just a wrapper for the | ||
* initialize method in Trie to make the intention clearer. | ||
* | ||
* @param majors the majors to update the trie with | ||
*/ | ||
public static void update(String... majors) { | ||
initialize(majors); | ||
} | ||
|
||
@Override | ||
public AutoCompleteResult getAutoComplete(String input) { | ||
assert majorTrie != null; | ||
|
||
Matcher m = MAJOR_FORMAT.matcher(input); | ||
boolean isMajor = m.find(); | ||
assert isMajor; | ||
|
||
String partialMajor = m.group(1); | ||
List<String> fullMajors = majorTrie.findAllWordsWithPrefix(partialMajor); | ||
|
||
assert fullMajors != null; | ||
if (fullMajors.isEmpty()) { | ||
return new AutoCompleteResult(); | ||
} | ||
|
||
// Strip the input from the full commands and sort the list | ||
return new AutoCompleteResult( | ||
fullMajors.stream() | ||
.map(c -> c.substring(partialMajor.length())) | ||
.sorted() | ||
.collect(Collectors.toList()) | ||
); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/seedu/address/logic/autocomplete/AutoCompleteMajor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package seedu.address.logic.autocomplete; | ||
|
||
import static seedu.address.logic.parser.CliSyntax.PREFIX_MAJOR; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
|
||
import seedu.address.commons.util.Trie; | ||
|
||
// TODO: code quality issues | ||
/** | ||
* AutoComplete for major. | ||
*/ | ||
public class AutoCompleteMajor implements AutoComplete { | ||
private static Trie majorTrie; | ||
private static final Pattern MAJOR_FORMAT = Pattern.compile(PREFIX_MAJOR.getPrefix() + "(.*)"); | ||
|
||
/** | ||
* Initializes the major trie with the given majors. This method should be called once at | ||
* the start of the initialization of LogicManager. | ||
* | ||
* @param majors the majors to initialize the trie with | ||
*/ | ||
public static void initialize(String... majors) { | ||
majorTrie = new Trie(Arrays.stream(majors).toArray(String[]::new)); | ||
} | ||
|
||
/** | ||
* Update the majors trie with the given majors. This method is just a wrapper for the | ||
* initialize method in Trie to make the intention clearer. | ||
* | ||
* @param majors the majors to update the trie with | ||
*/ | ||
public static void update(String... majors) { | ||
initialize(majors); | ||
} | ||
|
||
@Override | ||
public AutoCompleteResult getAutoComplete(String input) { | ||
assert majorTrie != null; | ||
|
||
Matcher m = MAJOR_FORMAT.matcher(input); | ||
boolean isMajor = m.find(); | ||
assert isMajor; | ||
|
||
String partialMajor = m.group(1); | ||
List<String> fullMajors = majorTrie.findAllWordsWithPrefix(partialMajor); | ||
|
||
assert fullMajors != null; | ||
if (fullMajors.isEmpty()) { | ||
return new AutoCompleteResult(); | ||
} | ||
|
||
// Strip the input from the full commands and sort the list | ||
return new AutoCompleteResult( | ||
fullMajors.stream() | ||
.map(c -> c.substring(partialMajor.length())) | ||
.sorted() | ||
.collect(Collectors.toList()) | ||
); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/seedu/address/logic/autocomplete/AutoCompleteName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package seedu.address.logic.autocomplete; | ||
|
||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
|
||
import seedu.address.commons.util.Trie; | ||
|
||
// TODO: code quality issues | ||
/** | ||
* AutoComplete for major. | ||
*/ | ||
public class AutoCompleteName implements AutoComplete { | ||
private static Trie majorTrie; | ||
private static final Pattern MAJOR_FORMAT = Pattern.compile(PREFIX_NAME.getPrefix() + "(.*)"); | ||
|
||
/** | ||
* Initializes the major trie with the given majors. This method should be called once at | ||
* the start of the initialization of LogicManager. | ||
* | ||
* @param majors the majors to initialize the trie with | ||
*/ | ||
public static void initialize(String... majors) { | ||
majorTrie = new Trie(Arrays.stream(majors).toArray(String[]::new)); | ||
} | ||
|
||
/** | ||
* Update the majors trie with the given majors. This method is just a wrapper for the | ||
* initialize method in Trie to make the intention clearer. | ||
* | ||
* @param majors the majors to update the trie with | ||
*/ | ||
public static void update(String... majors) { | ||
initialize(majors); | ||
} | ||
|
||
@Override | ||
public AutoCompleteResult getAutoComplete(String input) { | ||
assert majorTrie != null; | ||
|
||
Matcher m = MAJOR_FORMAT.matcher(input); | ||
boolean isMajor = m.find(); | ||
assert isMajor; | ||
|
||
String partialMajor = m.group(1); | ||
List<String> fullMajors = majorTrie.findAllWordsWithPrefix(partialMajor); | ||
|
||
assert fullMajors != null; | ||
if (fullMajors.isEmpty()) { | ||
return new AutoCompleteResult(); | ||
} | ||
|
||
// Strip the input from the full commands and sort the list | ||
return new AutoCompleteResult( | ||
fullMajors.stream() | ||
.map(c -> c.substring(partialMajor.length())) | ||
.sorted() | ||
.collect(Collectors.toList()) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.