From de3de1959d44116cfcdb5e200c58f930a27076e6 Mon Sep 17 00:00:00 2001 From: Tan Yi Xian <> Date: Wed, 2 Nov 2022 17:04:58 +0800 Subject: [PATCH] Convert ItemDate to abstract. Implement hashcode in both dates. --- src/main/java/seedu/foodrem/model/item/Item.java | 2 +- .../java/seedu/foodrem/model/item/ItemBoughtDate.java | 8 ++++++++ src/main/java/seedu/foodrem/model/item/ItemDate.java | 2 +- .../java/seedu/foodrem/model/item/ItemExpiryDate.java | 8 ++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/seedu/foodrem/model/item/Item.java b/src/main/java/seedu/foodrem/model/item/Item.java index 3b02a0530bc..c7a36766124 100644 --- a/src/main/java/seedu/foodrem/model/item/Item.java +++ b/src/main/java/seedu/foodrem/model/item/Item.java @@ -52,7 +52,7 @@ public Item(ItemName name, Set 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."); } diff --git a/src/main/java/seedu/foodrem/model/item/ItemBoughtDate.java b/src/main/java/seedu/foodrem/model/item/ItemBoughtDate.java index 386ffe365c5..15f9ebe70e8 100644 --- a/src/main/java/seedu/foodrem/model/item/ItemBoughtDate.java +++ b/src/main/java/seedu/foodrem/model/item/ItemBoughtDate.java @@ -58,6 +58,14 @@ public boolean equals(Object other) { && getDate().equals(((ItemBoughtDate) other).getDate())); } + /** + * {@inheritDoc} + */ + @Override + public int hashCode() { + return super.hashCode(); + } + /** * {@inheritDoc} */ diff --git a/src/main/java/seedu/foodrem/model/item/ItemDate.java b/src/main/java/seedu/foodrem/model/item/ItemDate.java index 9c876460d19..10fdfc82bf4 100644 --- a/src/main/java/seedu/foodrem/model/item/ItemDate.java +++ b/src/main/java/seedu/foodrem/model/item/ItemDate.java @@ -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 diff --git a/src/main/java/seedu/foodrem/model/item/ItemExpiryDate.java b/src/main/java/seedu/foodrem/model/item/ItemExpiryDate.java index 09829479c14..8394be5f947 100644 --- a/src/main/java/seedu/foodrem/model/item/ItemExpiryDate.java +++ b/src/main/java/seedu/foodrem/model/item/ItemExpiryDate.java @@ -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)}.