diff --git a/src/main/java/seedu/address/model/order/Order.java b/src/main/java/seedu/address/model/order/Order.java index 2011078e075..de5b8034098 100644 --- a/src/main/java/seedu/address/model/order/Order.java +++ b/src/main/java/seedu/address/model/order/Order.java @@ -1,4 +1,82 @@ package seedu.address.model.order; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + public class Order { + private int id; + private Map productMap; + + public Order() { + productMap = new HashMap<>(); + } + + public Order(int id) { + this.id = id; + productMap = new HashMap<>(); + } + + public void setID(int id) { + this.id = id; + } + + public int getId(){ + return this.id; + } + + public Map getProductMap() { + return this.productMap; + } + + public void addProduct(Product newProduct, Quantity newQuantity) { + productMap.put(newProduct, newQuantity); + } + + public Quantity getQuantity(Product product) { + Quantity currQuantity = productMap.get(product); + return currQuantity; + } + + public int getQuantityValue(Product product) { + int value = productMap.get(product).getValue(); + return value; + } + + public void changeQuantity(Product currProduct, int newQuantity) { + Quantity currQuantity = productMap.get(currProduct); + currQuantity.setQuantity(newQuantity); + } + + public void deleteProduct(Product product) { + productMap.remove(product); + } + + public void clearProductMap() { + this.productMap.clear(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof Order)) { + return false; + } + + Order otherOrder = (Order) other; + return (this.id == otherOrder.id) + && this.productMap.equals(otherOrder.productMap); + } + + @Override + public int hashCode() { + return Objects.hash(id, productMap); + } + + @Override + public String toString() { + return productMap.toString(); + } } diff --git a/src/main/java/seedu/address/model/order/Product.java b/src/main/java/seedu/address/model/order/Product.java index 8b0dd8d88a1..1c042de13cc 100644 --- a/src/main/java/seedu/address/model/order/Product.java +++ b/src/main/java/seedu/address/model/order/Product.java @@ -1,4 +1,50 @@ package seedu.address.model.order; public class Product { + + public static final String MESSAGE_CONSTRAINTS = + "Product names should only contain alphanumeric characters and spaces, and it should not be blank"; + + /* + * The first character of the product name must not be a whitespace, + * otherwise " " (a blank string) becomes a valid input. + */ + public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*"; + private String name; + + public Product(String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + if (!(other instanceof Product)){ + return false; + } + + Product otherProduct = (Product) other; + return this.name.equals(otherProduct.name); + } + + @Override + public int hashCode() { + return this.name.hashCode(); + } + + public String getName() { + return this.name; + } + + public void rename(String newName) { + this.name = newName; + } } diff --git a/src/main/java/seedu/address/model/order/Quantity.java b/src/main/java/seedu/address/model/order/Quantity.java new file mode 100644 index 00000000000..5143514627f --- /dev/null +++ b/src/main/java/seedu/address/model/order/Quantity.java @@ -0,0 +1,45 @@ +package seedu.address.model.order; + +public class Quantity { + public static final String MESSAGE_CONSTRAINTS = + "Product quantity should only be a number."; + public static final String VALIDATION_REGEX = "\\d"; + public int value; + + public Quantity(int value) { + this.value = value; + } + + @Override + public String toString() { + return Integer.toString(this.value); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof Quantity)) { + return false; + } + + Quantity otherQuantity = (Quantity) other; + return this.value == otherQuantity.value; + } + + @Override + public int hashCode() { + return Integer.hashCode(this.value); + } + + public int getValue() { + return this.value; + } + + public void setQuantity(int newQuantity) { + this.value = newQuantity; + } +}