Skip to content

Commit

Permalink
Convert ItemDate to abstract. Implement hashcode in both dates.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tan Yi Xian committed Nov 2, 2022
1 parent 16d0d73 commit de3de19
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/foodrem/model/item/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Item(ItemName name,
Set<Tag> tagSet) {
requireAllNonNull(name, quantity, unit, boughtDate, expiryDate, price, remarks, tagSet);

// Same date is accepted
// Same Bought date and Expiry date is accepted
if (!boughtDate.isNotSet() && !expiryDate.isNotSet() && boughtDate.isAfterDate(expiryDate)) {
throw new IllegalArgumentException("The item bought date should not be after the item expiry date.");
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/seedu/foodrem/model/item/ItemBoughtDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ public boolean equals(Object other) {
&& getDate().equals(((ItemBoughtDate) other).getDate()));
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return super.hashCode();
}

/**
* {@inheritDoc}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/foodrem/model/item/ItemDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Represents an item date in an {@link Item}.
* Guarantees: details are present and not null, immutable.
*/
public class ItemDate {
public abstract class ItemDate {
// Remember to change relevant messages displayed to users when changing the regex.
public static final String DATE_PATTERN_REGEX = "dd-MM-uuuu";
public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/seedu/foodrem/model/item/ItemExpiryDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public boolean isNotSet() {
return this == NOT_SET_EXPIRY_DATE;
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return super.hashCode();
}

/**
* Returns {@code true} if both {@link ItemExpiryDate} have the same date by
* {@link LocalDate#equals(Object)}.
Expand Down

0 comments on commit de3de19

Please sign in to comment.