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

Add sort command #66

Merged
merged 39 commits into from
Oct 14, 2020
Merged

Conversation

bangyiwu
Copy link
Collaborator

@bangyiwu bangyiwu commented Oct 5, 2020

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

@bangyiwu bangyiwu closed this Oct 5, 2020
@bangyiwu bangyiwu reopened this Oct 5, 2020
@bangyiwu
Copy link
Collaborator Author

bangyiwu commented Oct 5, 2020

I will fix the cli fails before reopening

@bangyiwu bangyiwu closed this Oct 5, 2020
@bangyiwu bangyiwu reopened this Oct 5, 2020
@bangyiwu bangyiwu added this to the v1.2 milestone Oct 6, 2020
@bangyiwu bangyiwu linked an issue Oct 6, 2020 that may be closed by this pull request
@LinkedInk
Copy link
Collaborator

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.

@chan-j-d
Copy link
Collaborator

chan-j-d commented Oct 7, 2020

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 model.getFilteredPersonList() method which gives the last shown list.

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-io
Copy link

codecov-io commented Oct 8, 2020

Codecov Report

Merging #66 into master will decrease coverage by 1.75%.
The diff coverage is 10.90%.

Impacted file tree graph

@@             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              
Impacted Files Coverage Δ Complexity Δ
...java/seedu/address/logic/commands/SortCommand.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
.../seedu/address/logic/parser/AddressBookParser.java 69.56% <0.00%> (-3.17%) 12.00 <0.00> (ø)
.../seedu/address/logic/parser/SortCommandParser.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
src/main/java/seedu/address/model/AddressBook.java 84.61% <0.00%> (-7.06%) 12.00 <0.00> (ø)
src/main/java/seedu/address/model/Model.java 100.00% <ø> (ø) 1.00 <0.00> (ø)
...a/seedu/address/model/person/UniquePersonList.java 88.37% <0.00%> (-4.32%) 20.00 <0.00> (ø)
...rc/main/java/seedu/address/model/ModelManager.java 73.52% <50.00%> (-1.86%) 23.00 <1.00> (ø)
...rc/main/java/seedu/address/logic/LogicManager.java 65.21% <100.00%> (ø) 3.00 <1.00> (ø)
...va/seedu/address/logic/commands/DeleteCommand.java 100.00% <100.00%> (ø) 7.00 <0.00> (ø)
...java/seedu/address/logic/commands/EditCommand.java 91.66% <100.00%> (ø) 16.00 <0.00> (ø)
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 52edc97...6de30ea. Read the comment docs.

@bangyiwu bangyiwu linked an issue Oct 8, 2020 that may be closed by this pull request
@bangyiwu
Copy link
Collaborator Author

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

Copy link
Collaborator

@chan-j-d chan-j-d left a 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/");
Copy link
Collaborator

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?

Comment on lines 22 to 27
requireNonNull(args);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_SORT);

Index index;
try {
index = ParserUtil.parseIndex(argMultimap.getPreamble());
Copy link
Collaborator

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

Comment on lines 16 to 20
+ "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"
Copy link
Collaborator

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;

Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

This Javadocs is outdated

Comment on lines +101 to +103
public void sortPersons(Comparator<Person> c) {
internalList.sort(c);
}
Copy link
Collaborator

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

Comment on lines 180 to 182
public void sortPerson(Index index) {
throw new AssertionError("This method should not be called.");
}
Copy link
Collaborator

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) {
Copy link
Collaborator

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

Comment on lines 168 to 198
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);
}
};
Copy link
Collaborator

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?

Comment on lines 200 to 206
if (indexNumber == 1) {
sortedPersons.comparatorProperty().setValue(nameComparator);
} else if (indexNumber == 2) {
sortedPersons.comparatorProperty().setValue(addressComparator);
} else if (indexNumber == 3) {
sortedPersons.comparatorProperty().setValue(tagComparator);
}
Copy link
Collaborator

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.

@chan-j-d chan-j-d linked an issue Oct 14, 2020 that may be closed by this pull request
Copy link
Collaborator

@chan-j-d chan-j-d left a comment

Choose a reason for hiding this comment

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

LGTM!

@chan-j-d chan-j-d merged commit 2d273f7 into AY2021S1-CS2103T-W10-4:master Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement sorting function As a user, I can sort my contacts
4 participants