-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add sort command #66
Add sort command #66
Conversation
I will fix the cli fails before reopening |
Model should not handle the sortPerson of the addressbook. Should consider moving the function into the excute part of SortCommand and the class in general. Model class has getAddressBook and setAddressBook to help with that. |
Is the sort method supposed to sort the current shown list? Or is it supposed to sort the full list of contacts before showing it? Because the former would be much easier to implement and I believe is what we intended to do originally? There is the Also, I agree with the Hendey's comment about the sortPerson method. I do not think that all the model classes need to have such a method. |
Codecov Report
@@ Coverage Diff @@
## master #66 +/- ##
============================================
- Coverage 61.00% 59.25% -1.76%
Complexity 457 457
============================================
Files 89 91 +2
Lines 1631 1681 +50
Branches 187 193 +6
============================================
+ Hits 995 996 +1
- Misses 586 635 +49
Partials 50 50
Continue to review full report at Codecov.
|
This is to preserve the original tag options. The edit command will then only specify what tags to add and remove. This is also for future-proofing as we intend to add support for searching by tags.
Challenges faced: so far only able to sort the address book permanently, if anyone has an idea on how we can sort the address book temporarily, let me know |
SortedList is used to wrap around the FilteredList as the FilteredList itself is immutable. The getFilteredPersonList() has been changed to return the sortedList instead. This makes it such that both filters and comparators are reflected in the list being shown.
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.
Please take a look at the suggestions
@@ -11,6 +11,7 @@ | |||
public static final Prefix PREFIX_EMAIL = new Prefix("e/"); | |||
public static final Prefix PREFIX_ADDRESS = new Prefix("a/"); | |||
public static final Prefix PREFIX_TAG = new Prefix("t/"); | |||
public static final Prefix PREFIX_SORT = new Prefix("s/"); |
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.
Is the prefix necessary at all?
requireNonNull(args); | ||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_SORT); | ||
|
||
Index index; | ||
try { | ||
index = ParserUtil.parseIndex(argMultimap.getPreamble()); |
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.
Should be able to obtain the index directly similar to the Delete command for example
+ "by the index command entered " | ||
+ "1 will be sort by date added\n" | ||
+ "2 will be sort by alphabetical order of their names\n" | ||
+ "3 will be sort by alphabetical order of their address\n" | ||
+ "4 will be sort by alphabetical order of their first tag\n" |
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 seems to be outdated compared to what is actually implemented
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
|
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.
Would be nice to have a brief Javadocs description of the class
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new {@code RemarkCommand} object |
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 Javadocs is outdated
public void sortPersons(Comparator<Person> c) { | ||
internalList.sort(c); | ||
} |
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.
Should probably remove this as it is only used by the unused sortPersons method in AddressBook
public void sortPerson(Index index) { | ||
throw new AssertionError("This method should not be called."); | ||
} |
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.
Should probably remove this as it is not used at all
@@ -156,15 +163,58 @@ public void setPerson(Person target, Person editedPerson) { | |||
addressBook.setPerson(target, editedPerson); | |||
} | |||
|
|||
@Override | |||
public void sortPerson(Index index) { |
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 method should probably take in a Comparator instead in line with how the updateFilteredPersonList
method works. Model Manager shouldn't need to know exactly which Comparators it needs
Comparator<Person> nameComparator = new Comparator<Person>() { | ||
@Override | ||
public int compare(Person o1, Person o2) { | ||
return o1.getName().fullName.compareToIgnoreCase(o2.getName().fullName); | ||
} | ||
}; | ||
|
||
Comparator<Person> addressComparator = new Comparator<Person>() { | ||
@Override | ||
public int compare(Person o1, Person o2) { | ||
return o1.getAddress().value.compareToIgnoreCase(o2.getAddress().value); | ||
} | ||
}; | ||
|
||
Comparator<Person> tagComparator = new Comparator<Person>() { | ||
@Override | ||
public int compare(Person o1, Person o2) { | ||
System.out.println(o2.getTags().size()); | ||
if (o1.getTags().size() == 0 && o2.getTags().size() != 0) { | ||
return 1; | ||
} | ||
if (o1.getTags().size() != 0 && o2.getTags().size() == 0) { | ||
return -1; | ||
} | ||
if (o1.getTags().size() == 0 && o2.getTags().size() == 0) { | ||
return o1.getName().fullName.compareToIgnoreCase(o2.getName().fullName); | ||
} | ||
return o1.getTags().iterator().next().tagName | ||
.compareToIgnoreCase(o2.getTags().iterator().next().tagName); | ||
} | ||
}; |
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.
The three comparators should probably declared as static constants within the SortCommand
class itself?
if (indexNumber == 1) { | ||
sortedPersons.comparatorProperty().setValue(nameComparator); | ||
} else if (indexNumber == 2) { | ||
sortedPersons.comparatorProperty().setValue(addressComparator); | ||
} else if (indexNumber == 3) { | ||
sortedPersons.comparatorProperty().setValue(tagComparator); | ||
} |
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 should probably be done in the SortCommand class itself. execute
chooses the appropriate Comparator in the execute command to pass to ModelManager
.
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.
LGTM!
First implementation of sorting, sort 1 allows sorting by name, sort 2 allows sorting by address and sort 3 allows sorting by the person's first tag