forked from nus-cs2103-AY2425S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #213 from AbdulrahmanAlRammah/Maintain_Sort_Order
Maintaining Sort order when adding or editing contacts
- Loading branch information
Showing
9 changed files
with
162 additions
and
3 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/main/java/seedu/address/commons/core/SortSettings.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,75 @@ | ||
package seedu.address.commons.core; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
|
||
import seedu.address.commons.util.ToStringBuilder; | ||
import seedu.address.model.person.PersonComparator; | ||
|
||
/** | ||
* A Serializable class that contains the Sort settings. | ||
* Guarantees: immutable. | ||
*/ | ||
public class SortSettings implements Serializable { | ||
|
||
private static final String DEFAULT_SORT_PARAMETER = PersonComparator.NAME; | ||
private static final boolean DEFAULT_IS_ASCENDING_ORDER = true; | ||
|
||
private final String sortParameter; | ||
|
||
private final boolean isAscendingOrder; | ||
|
||
/** | ||
* Constructs a {@code SortSettings} with the default sortParameter and Order. | ||
*/ | ||
public SortSettings() { | ||
sortParameter = DEFAULT_SORT_PARAMETER; | ||
isAscendingOrder = DEFAULT_IS_ASCENDING_ORDER; | ||
} | ||
|
||
/** | ||
* Constructs a {@code SortSettings} with the specified sortParameter and Order. | ||
*/ | ||
public SortSettings(String sortParameter, boolean isAscendingOrder) { | ||
this.sortParameter = sortParameter; | ||
this.isAscendingOrder = isAscendingOrder; | ||
} | ||
|
||
public String getSortParameter() { | ||
return this.sortParameter; | ||
} | ||
|
||
public boolean isAscendingOrder() { | ||
return this.isAscendingOrder; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof SortSettings)) { | ||
return false; | ||
} | ||
|
||
SortSettings otherSortSettings = (SortSettings) other; | ||
return this.sortParameter == otherSortSettings.sortParameter | ||
&& (this.isAscendingOrder == otherSortSettings.isAscendingOrder); | ||
|
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(sortParameter, isAscendingOrder); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("sortParameter", sortParameter) | ||
.add("isAscendingOrder", isAscendingOrder) | ||
.toString(); | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
src/test/java/seedu/address/commons/core/SortSettingsTest.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,16 @@ | ||
package seedu.address.commons.core; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class SortSettingsTest { | ||
@Test | ||
public void toStringMethod() { | ||
SortSettings sortSettings = new SortSettings(); | ||
String expected = SortSettings.class.getCanonicalName() + "{sortParameter=" + sortSettings.getSortParameter() | ||
+ ", isAscendingOrder=" + sortSettings.isAscendingOrder() + "}"; | ||
assertEquals(expected, sortSettings.toString()); | ||
} | ||
} | ||
|
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