forked from nus-cs2103-AY1718S1/addressbook-level4-old
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
121 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package seedu.address.logic; | ||
|
||
import java.util.ArrayList; | ||
|
||
import seedu.address.model.Model; | ||
import seedu.address.model.person.ReadOnlyPerson; | ||
|
||
|
||
/** | ||
* AutoComplete class integrated into LogicManager to keep track of current set | ||
* of autocomplete suggestions | ||
*/ | ||
public class AutoComplete { | ||
|
||
private final String[] baseCommands = { "add", "edit", "select", "delete", "clear", | ||
"backup", "find", "list", "history", "exit", "help", "undo", "redo" | ||
}; | ||
private ArrayList<String> personsStringArray; | ||
private String[] autoCompleteList; | ||
private Model model; | ||
|
||
public AutoComplete(Model model) { | ||
this.model = model; | ||
autoCompleteList = baseCommands; | ||
personsStringArray = new ArrayList<String>(); | ||
this.updatePersonsArray(); | ||
} | ||
|
||
/** | ||
* Updates AutoComplete suggestions according to user typed input | ||
* @param userInput | ||
*/ | ||
public void updateAutoCompleteList(String userInput) { | ||
switch (userInput) { | ||
case "": | ||
this.resetAutocompleteList(); | ||
break; | ||
case "find": | ||
this.autoCompleteList = getConcatPersonsArray("find"); | ||
break; | ||
case "edit": | ||
this.autoCompleteList = getConcatPersonsArray("edit"); | ||
break; | ||
case "delete": | ||
this.autoCompleteList = getConcatPersonsArray("delete"); | ||
break; | ||
default: | ||
return; | ||
} | ||
} | ||
|
||
// Concatenate Persons to suggestions when command typed | ||
private String[] getConcatPersonsArray(String command) { | ||
String[] newAutoCompleteList = new String[personsStringArray.size()]; | ||
for (int i = 0; i < personsStringArray.size(); i++) { | ||
if (command.equals("find")) { | ||
newAutoCompleteList[i] = command + " " + personsStringArray.get(i); | ||
} else { | ||
newAutoCompleteList[i] = command + " " + (i + 1); | ||
} | ||
} | ||
return newAutoCompleteList; | ||
} | ||
|
||
/** | ||
* Reset autocomplete suggestions to base commands | ||
*/ | ||
public void resetAutocompleteList() { | ||
this.autoCompleteList = baseCommands; | ||
} | ||
|
||
/** | ||
* Update array of persons suggestions when list modified | ||
*/ | ||
public void updatePersonsArray() { | ||
personsStringArray.clear(); | ||
for (ReadOnlyPerson p: model.getFilteredPersonList()) { | ||
personsStringArray.add(p.getName().toString()); | ||
} | ||
} | ||
|
||
/** | ||
* Getter for auto-complete list suggestions | ||
*/ | ||
// Update array of persons suggestions when list modified | ||
public String[] getAutoCompleteList() { | ||
return autoCompleteList; | ||
} | ||
} |
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