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][W09-3] Sivakumar Bavadharini #156

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Sort command logic
bava98 committed Feb 12, 2019
commit ebe1d73c6d521e8dc6a272bc8dba794da457e906
2 changes: 1 addition & 1 deletion src/seedu/addressbook/commands/Command.java
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ public static String getMessageForPersonListShownSummary(List<? extends ReadOnly
*/
public CommandResult execute(){
throw new UnsupportedOperationException("This method is to be implemented by child classes");
};
}

/**
* Supplies the data the command will operate on.
29 changes: 29 additions & 0 deletions src/seedu/addressbook/commands/SortCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package seedu.addressbook.commands;

import seedu.addressbook.data.person.ReadOnlyPerson;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortCommand extends Command{

Choose a reason for hiding this comment

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

Remember to add a whitespace before the curly brace (:

public static final String COMMAND_WORD = "sort";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Displays all persons in the address book as a list sorted by name with index numbers.\n"
+ "Example: " + COMMAND_WORD;

class SortByName implements Comparator<ReadOnlyPerson> {
public int compare (ReadOnlyPerson person1, ReadOnlyPerson person2) {
return person1.getName().toString().compareTo(person2.getName().toString());
}
}

@Override
public CommandResult execute() {
List<ReadOnlyPerson> allPersons = addressBook.getAllPersons().immutableListView();
Collections.sort(allPersons, new SortByName());
return new CommandResult(getMessageForPersonListShownSummary(allPersons), allPersons);
}
}
4 changes: 2 additions & 2 deletions test/java/seedu/addressbook/commands/FindCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package seedu.addressbook.commands;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
@@ -15,6 +13,8 @@
import seedu.addressbook.data.person.ReadOnlyPerson;
import seedu.addressbook.util.TypicalPersons;

import static org.testng.AssertJUnit.assertEquals;

Choose a reason for hiding this comment

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

Try not to commit unrelated changes in this PR


public class FindCommandTest {

private final AddressBook addressBook = new TypicalPersons().getTypicalAddressBook();