Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,26 @@ Deletes the 2nd person in the address book.
`delete 1` +
Deletes the 1st person in the results of the `find` command.

== Highlighting a person : `group`

Deletes the specified person from the address book. Irreversible. +

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong?

Format: `group INDEX`

****
Highlights(groups) the person at the specified `INDEX`.
The index refers to the index number shown in the most recent listing.
****

Examples:

* `list` +
`group 2` +
Highlights the 2nd person in the address book.

* `find Betsy` +
`group 1` +
Highlights the 1st person in the results of the `find` command.

== View non-private details of a person : `view`

Displays the non-private details of the specified person. +
Expand Down
42 changes: 42 additions & 0 deletions src/seedu/addressbook/commands/GroupCommand.java
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);

Choose a reason for hiding this comment

The 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);
}
}

}
9 changes: 9 additions & 0 deletions src/seedu/addressbook/data/AddressBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ public void removePerson(ReadOnlyPerson toRemove) throws PersonNotFoundException
allPersons.remove(toRemove);
}

/**
* Groups the equivalent person from the address book.
*
* @throws PersonNotFoundException if no such Person could be found.
*/
public void groupPerson(Person toGroup) throws PersonNotFoundException {
allPersons.group(toGroup);
}

/**
* Clears all persons and tags from the address book.
*/
Expand Down
14 changes: 14 additions & 0 deletions src/seedu/addressbook/data/person/UniquePersonList.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public static class PersonNotFoundException extends Exception {}

private final List<Person> internalList = new ArrayList<>();

private final List<Person> groupedPersonList = new ArrayList<>();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add comments to groupedPersonList and explain what it does and why do we need this?


/**
* Constructs empty person list.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down
22 changes: 22 additions & 0 deletions src/seedu/addressbook/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import seedu.addressbook.commands.ClearCommand;
import seedu.addressbook.commands.Command;
import seedu.addressbook.commands.DeleteCommand;
import seedu.addressbook.commands.GroupCommand;

Choose a reason for hiding this comment

The 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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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.
*
Expand Down