-
Notifications
You must be signed in to change notification settings - Fork 36
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
[W7][T11-2]WU PEI HSUAN #30
base: master
Are you sure you want to change the base?
Changes from all commits
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,31 @@ | ||
package seedu.addressbook.commands; | ||
|
||
import seedu.addressbook.data.AddressBook; | ||
|
||
import seedu.addressbook.data.person.ReadOnlyPerson; | ||
|
||
import java.util.*; | ||
import java.lang.*; | ||
|
||
|
||
/** | ||
* Lists all persons in the address book in sorted order to the user. | ||
*/ | ||
public class SortCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "sort"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ":\n" | ||
+ "Displays all persons in the address book as a list sorted in alphabetical order with index numbers.\n\t" | ||
+ "Example: " + COMMAND_WORD; | ||
|
||
|
||
@Override | ||
public CommandResult execute() { | ||
addressBook.sorted(); | ||
|
||
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. Be aware that too many empty lines can be a coding violation. |
||
List<ReadOnlyPerson> allPersons = addressBook.getAllPersons().immutableListView(); | ||
return new CommandResult(getMessageForPersonSortShownSummary(allPersons), allPersons); | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,12 @@ public void removePerson(ReadOnlyPerson toRemove) throws PersonNotFoundException | |
allPersons.remove(toRemove); | ||
} | ||
|
||
/** | ||
* Sorts all persons from the address book. | ||
*/ | ||
|
||
public void sorted() { allPersons.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. The placement of your code is violating the coding convention. Please add logic on new line. Refer to java coding conventions for CS2113/T for more information. |
||
|
||
/** | ||
* Clears all persons from the address book. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,13 +106,27 @@ public void remove(ReadOnlyPerson toRemove) throws PersonNotFoundException { | |
} | ||
} | ||
|
||
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. Again, we consider too many empty lines as a coding violation, as it reduces code readability. |
||
|
||
|
||
/** | ||
* Clears all persons in list. | ||
*/ | ||
public void clear() { | ||
internalList.clear(); | ||
} | ||
|
||
/** | ||
* Sorts all persons in list by name. | ||
*/ | ||
public void sort(){ | ||
Comparator<Person> person = (p1, p2) -> { | ||
Name name1 = p1.getName(); | ||
Name name2 = p2.getName(); | ||
return name1.compareTo(name2); | ||
}; | ||
Collections.sort(internalList, person); | ||
} | ||
|
||
@Override | ||
public Iterator<Person> iterator() { | ||
return internalList.iterator(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,12 @@ public void listCommand_parsedCorrectly() { | |
parseAndAssertCommandType(input, ListCommand.class); | ||
} | ||
|
||
@Test | ||
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. Missing header comment. All non-trivial methods should have java doc format header comments. |
||
public void sortCommand_parsedCorrectly() { | ||
final String input = "sort"; | ||
parseAndAssertCommandType(input, SortCommand.class); | ||
} | ||
|
||
@Test | ||
public void exitCommand_parsedCorrectly() { | ||
final String input = "exit"; | ||
|
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.
Missing header comment. All non-trivial methods should have java doc format header comments.