-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[W5][T12-1]Zhang Chenxi #168
base: master
Are you sure you want to change the base?
Changes from all commits
44f906a
6a5fc17
2631a46
01d55c0
5a1797c
917d6b9
212cba5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package seedu.addressbook.commands; | ||
|
||
import seedu.addressbook.common.Messages; | ||
import seedu.addressbook.data.person.ReadOnlyPerson; | ||
import seedu.addressbook.data.person.UniquePersonList.PersonNotFoundException; | ||
|
||
|
||
/** | ||
* Groups a person identified using it's last displayed index from the address book. | ||
*/ | ||
public class GroupCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "group"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Highlight the person identified by the index number used in the last person listing.\n" | ||
+ "Parameters: INDEX\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_GROUP_PERSON_SUCCESS = "Grouped Person: %1$s"; | ||
|
||
|
||
public GroupCommand(int targetVisibleIndex) { | ||
super(targetVisibleIndex); | ||
} | ||
|
||
|
||
@Override | ||
public CommandResult execute() { | ||
try { | ||
final ReadOnlyPerson target = getTargetPerson(); | ||
addressBook.removePerson(target); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uhm this will remove the target person from address book? |
||
return new CommandResult(String.format(MESSAGE_GROUP_PERSON_SUCCESS, target)); | ||
|
||
} catch (IndexOutOfBoundsException ie) { | ||
return new CommandResult(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} catch (PersonNotFoundException pnfe) { | ||
return new CommandResult(Messages.MESSAGE_PERSON_NOT_IN_ADDRESSBOOK); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,8 @@ public static class PersonNotFoundException extends Exception {} | |
|
||
private final List<Person> internalList = new ArrayList<>(); | ||
|
||
private final List<Person> groupedPersonList = new ArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps add comments to |
||
|
||
/** | ||
* Constructs empty person list. | ||
*/ | ||
|
@@ -122,6 +124,18 @@ public void remove(ReadOnlyPerson toRemove) throws PersonNotFoundException { | |
} | ||
} | ||
|
||
/** | ||
* Groups the equivalent person from the list. | ||
* | ||
* @throws PersonNotFoundException if no such person could be found in the list. | ||
*/ | ||
public void group(Person toGroup) throws PersonNotFoundException { | ||
final boolean personFoundAndGrouped = groupedPersonList.add(toGroup); | ||
if (!personFoundAndGrouped) { | ||
throw new PersonNotFoundException(); | ||
} | ||
} | ||
|
||
/** | ||
* Clears all persons in list. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
import seedu.addressbook.commands.ClearCommand; | ||
import seedu.addressbook.commands.Command; | ||
import seedu.addressbook.commands.DeleteCommand; | ||
import seedu.addressbook.commands.GroupCommand; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This import is in wrong order since import statements are sorted alphabetically :) |
||
import seedu.addressbook.commands.ExitCommand; | ||
import seedu.addressbook.commands.FindCommand; | ||
import seedu.addressbook.commands.HelpCommand; | ||
|
@@ -79,6 +80,9 @@ public Command parseCommand(String userInput) { | |
case DeleteCommand.COMMAND_WORD: | ||
return prepareDelete(arguments); | ||
|
||
case GroupCommand.COMMAND_WORD: | ||
return prepareGroup(arguments); | ||
|
||
case ClearCommand.COMMAND_WORD: | ||
return new ClearCommand(); | ||
|
||
|
@@ -174,6 +178,24 @@ private Command prepareDelete(String args) { | |
} | ||
} | ||
|
||
|
||
/** | ||
* Parses arguments in the context of the group person command. | ||
* | ||
* @param args full command args string | ||
* @return the prepared command | ||
*/ | ||
private Command prepareGroup(String args) { | ||
try { | ||
final int targetIndex = parseArgsAsDisplayedIndex(args); | ||
return new GroupCommand(targetIndex); | ||
} catch (ParseException pe) { | ||
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, GroupCommand.MESSAGE_USAGE)); | ||
} catch (NumberFormatException nfe) { | ||
return new IncorrectCommand(MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); | ||
} | ||
} | ||
|
||
/** | ||
* Parses arguments in the context of the view command. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is wrong?