forked from nus-cs2103-AY2122S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nus-cs2103-AY2122S1#64 from KT27Learn/branch-sortC…
…ommand Implement Sort Command
- Loading branch information
Showing
25 changed files
with
878 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,6 @@ public boolean equals(Object other) { | |
public int hashCode() { | ||
return value.hashCode(); | ||
} | ||
|
||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/seedu/address/model/person/comparators/SortByAddress.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package seedu.address.model.person.comparators; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.Comparator; | ||
|
||
import seedu.address.model.person.Person; | ||
|
||
public class SortByAddress implements Comparator<Person> { | ||
private SortDirection direction; | ||
|
||
/** | ||
* @param direction to sort by. Either asc or dsc. | ||
*/ | ||
public SortByAddress(SortDirection direction) { | ||
requireNonNull(direction); | ||
this.direction = direction; | ||
} | ||
|
||
@Override | ||
public int compare(Person a, Person b) { | ||
//cause i need the sort direction here, i implement compareTo in riskAppetite | ||
//cause if not i need double check here for empty values | ||
//wrt person a | ||
if (a.getAddress().value.isEmpty()) { | ||
return 1; | ||
} else { | ||
if (b.getAddress().value.isEmpty()) { | ||
return -1; | ||
} | ||
|
||
int result = a.getAddress().value.compareTo(b.getAddress().value); | ||
return direction.isAscending() ? result : -result; | ||
} | ||
} | ||
} |
Oops, something went wrong.