-
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
Branch improve sort command #119
Branch improve sort command #119
Conversation
…o branch-improve-sort-command
@@ -142,9 +173,62 @@ public void updateFilteredBookList(Predicate<Book> predicate) { | |||
|
|||
@Override | |||
public void sortFilteredBookList(Comparator<Book> comparator) { | |||
if (comparator instanceof BookNameComparator) { | |||
setSortingPreference(PREFIX_NAME.toString()); |
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 we be doing these checks here? An approach worth thinking about could be to get SortCommandParser
to create each SortCommand
s that know what prefix it's sorting by. Then in SortCommand#execute()
we can just call setSortingPreference(PREFIX_XXX)
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.
Thanks for the suggestions Le Yang, I agree with you and I have made the necessary changes 😄
* Returns a comparator based on the input prefix | ||
* @return Comparator based on input prefix | ||
*/ | ||
public Comparator<Book> comparatorGenerator(Prefix inputPrefix) { |
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.
Noticed that this exact method is repeated inside SortCommandParser
also. Can think about abstracting it out as a static utility method, maybe smth like BookComparatorGenerator#comparatorGenerator(Prefix inputPrefix)
* Returns a prefix based on the input string. | ||
* @return Prefix based on the input string. | ||
*/ | ||
public Prefix prefixGenerator(String prefix) { |
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.
I don't think this method belongs here, maybe define it as a utility method in CliSyntax
?
Codecov Report
@@ Coverage Diff @@
## master #119 +/- ##
============================================
- Coverage 74.10% 74.07% -0.04%
- Complexity 669 685 +16
============================================
Files 105 107 +2
Lines 2078 2133 +55
Branches 238 242 +4
============================================
+ Hits 1540 1580 +40
- Misses 455 465 +10
- Partials 83 88 +5 Continue to review full report at Codecov.
|
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!
docs/tutorials/AddRemark.md
Outdated
@@ -292,7 +292,7 @@ While the changes to code may be minimal, the test data will have to be updated | |||
|
|||
<div markdown="span" class="alert alert-warning"> | |||
|
|||
:exclamation: You must delete AddressBook’s storage file located at `/data/addressbook.json` before running it! Not doing so will cause AddressBook to default to an empty address book! | |||
:exclamation: You must delete AddressBook’s storage file located at `/data/library.json` before running it! Not doing so will cause AddressBook to default to an empty address book! |
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.
Perhaps you could change AddressBook to Library for this part.
@@ -87,7 +87,7 @@ At this point, your application is working as intended and all your tests are pa | |||
|
|||
In `src/test/data/`, data meant for testing purposes are stored. While keeping the `address` field in the json files does not cause the tests to fail, it is not good practice to let cruft from old features accumulate. |
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.
Perhaps you can change Address so Genre for this part!
@Override | ||
public String toString() { | ||
return "Reading Progress"; | ||
} |
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.
Maybe the toString() return value can be more meaningful?
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.
I use this toString() value to return "Sorted by: xxxx.toString()", so I think leaving it like this is fine
@@ -71,7 +71,7 @@ public void execute_validCommand_success() throws Exception { | |||
public void execute_storageThrowsIoException_throwsCommandException() { | |||
// Setup LogicManager with JsonAddressBookIoExceptionThrowingStub |
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.
Perhap you could change this to JsonLibraryBook... ?
@@ -71,7 +71,7 @@ public void execute_validCommand_success() throws Exception { | |||
public void execute_storageThrowsIoException_throwsCommandException() { | |||
// Setup LogicManager with JsonAddressBookIoExceptionThrowingStub | |||
JsonLibraryStorage addressBookStorage = |
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.
Perhaps you can change this to libraryStorage?
default: | ||
return PREFIX_DUMMY; | ||
} |
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.
Maybe it will be better if we throw an exception instead of defaulting to a dummy sorting choice?
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.
Exception would be thrown in SortCommandParser if prefix was invalid. But I'll change this to return null in the default case to make it less confusing.
docs/tutorials/AddRemark.md
Outdated
@@ -292,7 +292,7 @@ While the changes to code may be minimal, the test data will have to be updated | |||
|
|||
<div markdown="span" class="alert alert-warning"> | |||
|
|||
:exclamation: You must delete AddressBook’s storage file located at `/data/addressbook.json` before running it! Not doing so will cause AddressBook to default to an empty address book! | |||
:exclamation: You must delete bookmark’s storage file located at `/data/library.json` before running it! Not doing so will cause AddressBook to default to an empty address book! |
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.
Did you miss out 2 AddressBook at the end of the sentence?
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.
Overall LGTM! Just have a question on the use of String instead of Prefix in UserPrefs.
public SortCommand(Comparator<Book> comparator, Prefix inputPrefix) { | ||
this.comparator = comparator; | ||
this.inputPrefix = inputPrefix; |
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.
Perhaps usage of requireNonNull for more defensive code.
docs/tutorials/RemovingFields.md
Outdated
@@ -87,7 +87,7 @@ At this point, your application is working as intended and all your tests are pa | |||
|
|||
In `src/test/data/`, data meant for testing purposes are stored. While keeping the `address` field in the json files does not cause the tests to fail, it is not good practice to let cruft from old features accumulate. | |||
|
|||
**`invalidPersonAddressBook.json`:** | |||
**`invalidPersonLibrary.json`:** |
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 be
**`invalidPersonLibrary.json`:** | |
**`invalidBookLibrary.json`:** |
@@ -15,6 +15,7 @@ | |||
|
|||
private GuiSettings guiSettings = new GuiSettings(); | |||
private Path bookmarkFilePath = Paths.get("data" , "library.json"); | |||
private String sortingPreference = ""; |
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.
You might want to consider using Prefix instead of String. From what I see, you are converting from Prefix to String to set in UserPrefs. In order to get back the Prefix to create a Comparator, you have to convert the String back to a Prefix which seems unnecessary if Prefix was used instead. By using Prefix, you can remove the need for sortingPrefixGenerator and reduce the possibilities of bugs by the back and forth conversions.
Is there any additional benefit to using a String that I have missed out?
@@ -36,6 +39,7 @@ public ModelManager(ReadOnlyLibrary library, ReadOnlyUserPrefs userPrefs) { | |||
|
|||
this.library = new Library(library); | |||
this.userPrefs = new UserPrefs(userPrefs); | |||
this.comparator = comparatorGenerator(sortingPrefixGenerator(userPrefs.getSortingPreference())); |
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.
Relating to my comment on using a Prefix instead of String in UserPrefs below, a Prefix would remove the need for sortingPrefixGenerator()
. This line seems to have too much chaining.
…ybunny123/tp into branch-improve-sort-command
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!
@@ -180,6 +202,7 @@ public void updateFilteredBookList(Predicate<Book> predicate) { | |||
|
|||
@Override | |||
public void sortFilteredBookList(Comparator<Book> comparator) { | |||
this.comparator = comparator; | |||
this.library.sortBooks(comparator); | |||
} |
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.
Could you add this code to the end of the method
historyManager = historyManager.addNewState(State.createState(library, userPrefs, filteredBooks.getPredicate()));
to make the sort command undoable?
Closes #120
Added Sorting Preference field to user preferences, and changed occurrences of addressbook.json to library.json.
Can sort by reading progress using prefix "rp/"
Using the sort command now updates user preference as well, and when the user exits and reopens bookmark, books will still be sorted in the specified order.
Edit and Add book commands will be based on sorting preference of the user.