-
Notifications
You must be signed in to change notification settings - Fork 166
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.7][F10-2]Liu Xiaohang #446
base: master
Are you sure you want to change the base?
Changes from all commits
0354270
cc34784
14204a8
6d22986
7cf2e82
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 |
---|---|---|
|
@@ -36,6 +36,16 @@ public static String getMessageForPersonListShownSummary(List<? extends ReadOnly | |
return String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, personsDisplayed.size()); | ||
} | ||
|
||
/** | ||
* Constructs a feedback message to summarise an operation that displayed a list of sorted persons. | ||
* | ||
* @param personsDisplayed used to generate summary | ||
* @return summary message for persons displayed | ||
*/ | ||
public static String getMessageForPersonSortShownSummary(List<? extends ReadOnlyPerson> personsDisplayed) { | ||
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. Hmm... method name is not that intuitive |
||
return String.format(Messages.MESSAGE_SORTED, personsDisplayed.size()); | ||
} | ||
|
||
/** | ||
* Executes the command and returns the result. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ public CommandResult execute() { | |
+ "\n" + ViewAllCommand.MESSAGE_USAGE | ||
+ "\n" + HelpCommand.MESSAGE_USAGE | ||
+ "\n" + ExitCommand.MESSAGE_USAGE | ||
+ "\n" + SortCommand.MESSAGE_USAGE | ||
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. /nit: Why is sort at the end? |
||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package seedu.addressbook.commands; | ||
import java.util.List; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import seedu.addressbook.data.exception.IllegalValueException; | ||
import seedu.addressbook.data.person.Address; | ||
import seedu.addressbook.data.person.Email; | ||
import seedu.addressbook.data.person.Name; | ||
import seedu.addressbook.data.person.Person; | ||
import seedu.addressbook.data.person.Phone; | ||
import seedu.addressbook.data.person.ReadOnlyPerson; | ||
import seedu.addressbook.data.person.UniquePersonList; | ||
import seedu.addressbook.data.tag.Tag; | ||
|
||
/** | ||
* Sort all persons in the address book to the user. | ||
*/ | ||
public class SortCommand extends Command{ | ||
public static final String COMMAND_WORD = "sort"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": sort people in the address book.\n" | ||
+ "Example: " + COMMAND_WORD; | ||
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. Inconsistant '+' alignment. |
||
|
||
//public static final String MESSAGE_SUCCESS = "People sorted."; | ||
|
||
@Override | ||
public CommandResult execute() { | ||
List<ReadOnlyPerson> allPersons = addressBook.getAllPersons().sortedListView(); | ||
return new CommandResult(getMessageForPersonSortShownSummary(allPersons), allPersons); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,17 @@ public List<ReadOnlyPerson> immutableListView() { | |
return Collections.unmodifiableList(internalList); | ||
} | ||
|
||
/** | ||
* Returns an unmodifiable java List view with elements cast as immutable {@link ReadOnlyPerson}s. | ||
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. |
||
* For use with other methods/libraries. | ||
* Any changes to the internal list/elements are immediately visible in the returned list. | ||
*/ | ||
public List<ReadOnlyPerson> sortedListView() { | ||
//internalList.sort(); <--how to make this line work instead of using Collections.sort()? :( | ||
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. https://docs.oracle.com/javase/8/docs/api/java/util/List.html |
||
Collections.sort(internalList); | ||
return Collections.unmodifiableList(internalList); | ||
} | ||
|
||
|
||
/** | ||
* Checks if the list contains an equivalent person as the given argument. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,17 +11,7 @@ | |
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import seedu.addressbook.commands.AddCommand; | ||
import seedu.addressbook.commands.ClearCommand; | ||
import seedu.addressbook.commands.Command; | ||
import seedu.addressbook.commands.DeleteCommand; | ||
import seedu.addressbook.commands.ExitCommand; | ||
import seedu.addressbook.commands.FindCommand; | ||
import seedu.addressbook.commands.HelpCommand; | ||
import seedu.addressbook.commands.IncorrectCommand; | ||
import seedu.addressbook.commands.ListCommand; | ||
import seedu.addressbook.commands.ViewAllCommand; | ||
import seedu.addressbook.commands.ViewCommand; | ||
import seedu.addressbook.commands.*; | ||
import seedu.addressbook.data.exception.IllegalValueException; | ||
|
||
/** | ||
|
@@ -97,7 +87,11 @@ public Command parseCommand(String userInput) { | |
case ExitCommand.COMMAND_WORD: | ||
return new ExitCommand(); | ||
|
||
case SortCommand.COMMAND_WORD: | ||
return new SortCommand(); | ||
|
||
case HelpCommand.COMMAND_WORD: // Fallthrough | ||
|
||
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. Avoid adding unnecessary new line |
||
default: | ||
return new HelpCommand(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package seedu.addressbook.commands; | ||
|
||
//import ... | ||
|
||
public class SortCommandTest { | ||
//TODO: add some tests for sort command. | ||
//assertListSorted(list) { | ||
// assertEqual(list, list.sort()); | ||
// } | ||
} |
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.
summarize (use American spelling), displays