forked from nus-cs2103-AY2324S1/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 #89 from shishirbychapur/feature/preferences
Add Preferences
- Loading branch information
Showing
30 changed files
with
618 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package seedu.lovebook.model; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.Objects; | ||
|
||
import seedu.lovebook.commons.util.ToStringBuilder; | ||
import seedu.lovebook.model.person.Age; | ||
import seedu.lovebook.model.person.Gender; | ||
import seedu.lovebook.model.person.Height; | ||
import seedu.lovebook.model.person.Income; | ||
|
||
/** | ||
* Represents the preferences of the user for a date. | ||
*/ | ||
public class DatePrefs implements ReadOnlyDatePrefs { | ||
private Age age; | ||
private Gender gender; | ||
private Height height; | ||
private Income income; | ||
|
||
/** | ||
* Creates a {@code DatePrefs} with default values. | ||
*/ | ||
public DatePrefs() { | ||
this.age = new Age("21"); | ||
this.gender = new Gender("F"); | ||
this.height = new Height("170"); | ||
this.income = new Income("10000"); | ||
} | ||
|
||
/** | ||
* Creates a {@code DatePrefs} with the given values. | ||
*/ | ||
public DatePrefs(Age age, Gender gender, Height height, Income income) { | ||
this.age = age; | ||
this.gender = gender; | ||
this.height = height; | ||
this.income = income; | ||
} | ||
|
||
/** | ||
* Creates a {@code DatePrefs} with the given values. | ||
*/ | ||
public DatePrefs(ReadOnlyDatePrefs toBeCopied) { | ||
this(); | ||
resetData(toBeCopied); | ||
} | ||
|
||
/** | ||
* Resets the existing data of this {@code LoveBook} with {@code newData}. | ||
*/ | ||
public void resetData(ReadOnlyDatePrefs newData) { | ||
requireNonNull(newData); | ||
|
||
setPreferences(newData.getPreferences()); | ||
} | ||
|
||
/** | ||
* Replaces the contents of the date list with {@code dates}. | ||
* {@code dates} must not contain duplicate dates. | ||
*/ | ||
public void setPreferences(DatePrefs prefs) { | ||
this.age = prefs.age; | ||
this.gender = prefs.gender; | ||
this.height = prefs.height; | ||
this.income = prefs.income; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof DatePrefs)) { | ||
return false; | ||
} | ||
|
||
DatePrefs otherPrefs = (DatePrefs) other; | ||
return this.age == otherPrefs.age | ||
&& this.height == otherPrefs.height | ||
&& this.gender == otherPrefs.gender | ||
&& this.income == otherPrefs.income; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.age, this.gender, this.height, this.income); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this) | ||
.add("age", age) | ||
.add("gender", gender) | ||
.add("height", height) | ||
.add("income", income) | ||
.toString(); | ||
} | ||
|
||
@Override | ||
public DatePrefs getPreferences() { | ||
return this; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package seedu.lovebook.model; | ||
|
||
/** | ||
* Unmodifiable view of date preferences. | ||
*/ | ||
public interface ReadOnlyDatePrefs { | ||
DatePrefs getPreferences(); | ||
} |
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 was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
src/main/java/seedu/lovebook/model/util/SampleDatePrefUtil.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,20 @@ | ||
package seedu.lovebook.model.util; | ||
|
||
import seedu.lovebook.model.DatePrefs; | ||
import seedu.lovebook.model.person.Age; | ||
import seedu.lovebook.model.person.Gender; | ||
import seedu.lovebook.model.person.Height; | ||
import seedu.lovebook.model.person.Income; | ||
|
||
/** | ||
* A utility class containing a sample {@code DatePrefs} to be used in tests. | ||
*/ | ||
public class SampleDatePrefUtil { | ||
public static DatePrefs getSamplePreferences() { | ||
Age age = new Age("20"); | ||
Height height = new Height("180"); | ||
Income income = new Income("10000"); | ||
Gender gender = new Gender("F"); | ||
return new DatePrefs(age, gender, height, income); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/seedu/lovebook/storage/DatePrefsStorage.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,43 @@ | ||
package seedu.lovebook.storage; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
|
||
import seedu.lovebook.commons.exceptions.DataLoadingException; | ||
import seedu.lovebook.model.ReadOnlyDatePrefs; | ||
|
||
/** | ||
* Represents a storage for {@link seedu.lovebook.model.DatePrefs}. | ||
*/ | ||
public interface DatePrefsStorage { | ||
/** | ||
* Returns the file path of the data file. | ||
*/ | ||
Path getDatePrefsFilePath(); | ||
|
||
/** | ||
* Returns LoveBook data as a {@link ReadOnlyDatePrefs}. | ||
* Returns {@code Optional.empty()} if storage file is not found. | ||
* | ||
* @throws DataLoadingException if loading the data from storage failed. | ||
*/ | ||
Optional<ReadOnlyDatePrefs> readDatePrefs() throws DataLoadingException; | ||
|
||
/** | ||
* @see #getDatePrefsFilePath() | ||
*/ | ||
Optional<ReadOnlyDatePrefs> readDatePrefs(Path filePath) throws DataLoadingException; | ||
|
||
/** | ||
* Saves the given {@link ReadOnlyDatePrefs} to the storage. | ||
* @param prefs cannot be null. | ||
* @throws IOException if there was any problem writing to the file. | ||
*/ | ||
void saveDatePrefs(ReadOnlyDatePrefs prefs) throws IOException; | ||
|
||
/** | ||
* @see #saveDatePrefs(ReadOnlyDatePrefs) | ||
*/ | ||
void saveDatePrefs(ReadOnlyDatePrefs prefs, Path filePath) throws IOException; | ||
} |
Oops, something went wrong.