From: Roland Haeder Date: Sun, 10 Apr 2016 12:58:42 +0000 (+0200) Subject: added missing equals() hashCode() methods as this is needed for JPA to work correctly X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9d2beab133487f688b2966dd4baa413040d763f0;p=jproduct-core.git added missing equals() hashCode() methods as this is needed for JPA to work correctly --- diff --git a/src/org/mxchange/jshopcore/model/basket/BaseBasket.java b/src/org/mxchange/jshopcore/model/basket/BaseBasket.java index 8f1a80b..476c529 100644 --- a/src/org/mxchange/jshopcore/model/basket/BaseBasket.java +++ b/src/org/mxchange/jshopcore/model/basket/BaseBasket.java @@ -137,4 +137,5 @@ public abstract class BaseBasket implements Basket< // Deligate call to frontend return this.deque.isEmpty(); } + } diff --git a/src/org/mxchange/jshopcore/model/basket/Basket.java b/src/org/mxchange/jshopcore/model/basket/Basket.java index f575076..c963ba2 100644 --- a/src/org/mxchange/jshopcore/model/basket/Basket.java +++ b/src/org/mxchange/jshopcore/model/basket/Basket.java @@ -34,7 +34,14 @@ public interface Basket extends Serializable { * @param item Item instance to add *

* @throws org.mxchange.jshopcore.exceptions.BasketItemAlreadyAddedException - * If the item instance has already been added + * If + * the + * item + * instance + * has + * already + * been + * added */ void addItem (final T item) throws BasketItemAlreadyAddedException; @@ -80,4 +87,11 @@ public interface Basket extends Serializable { * @return Whether the basket is empty */ boolean isEmpty (); + + @Override + boolean equals (final Object object); + + @Override + int hashCode (); + } diff --git a/src/org/mxchange/jshopcore/model/basket/items/BaseItem.java b/src/org/mxchange/jshopcore/model/basket/items/BaseItem.java index 198afad..fb080ae 100644 --- a/src/org/mxchange/jshopcore/model/basket/items/BaseItem.java +++ b/src/org/mxchange/jshopcore/model/basket/items/BaseItem.java @@ -21,8 +21,8 @@ import org.mxchange.jshopcore.model.basket.AddableBasketItem; import org.mxchange.jshopcore.model.product.Product; /** - * An item (addedable to a basket) could respresent a product or a discount - * coupon. This depends on the type of the item. + * An item (addable to a basket) could represent a product or a discount coupon. + * This depends on the type of the item. *

* @author Roland Haeder */ diff --git a/src/org/mxchange/jshopcore/model/category/Category.java b/src/org/mxchange/jshopcore/model/category/Category.java index 64900bf..15bb232 100644 --- a/src/org/mxchange/jshopcore/model/category/Category.java +++ b/src/org/mxchange/jshopcore/model/category/Category.java @@ -73,4 +73,11 @@ public interface Category extends Serializable { * @param title the title to set */ void setCategoryTitle (final String title); + + @Override + boolean equals (final Object object); + + @Override + int hashCode (); + } diff --git a/src/org/mxchange/jshopcore/model/category/ProductCategory.java b/src/org/mxchange/jshopcore/model/category/ProductCategory.java index 37e5444..dd7bd44 100644 --- a/src/org/mxchange/jshopcore/model/category/ProductCategory.java +++ b/src/org/mxchange/jshopcore/model/category/ProductCategory.java @@ -16,6 +16,7 @@ */ package org.mxchange.jshopcore.model.category; +import java.util.Objects; import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -66,8 +67,8 @@ public class ProductCategory implements Category { /** * Constructor which accepts all database fields *

- * @param categoryId Id number of database record - * @param categoryTitle Category categoryTitle + * @param categoryId Id number of database record + * @param categoryTitle Category categoryTitle * @param parentCategory Parent category */ public ProductCategory (final Long categoryId, final String categoryTitle, final Category parentCategory) { @@ -90,6 +91,35 @@ public class ProductCategory implements Category { this.setCategoryTitle(category.getCategoryTitle()); } + @Override + public boolean equals (final Object object) { + if (this == object) { + return true; + } else if (null == object) { + return false; + } else if (this.getClass() != object.getClass()) { + return false; + } + + final Category other = (Category) object; + + if (!Objects.equals(this.getCategoryTitle(), other.getCategoryTitle())) { + return false; + } else if (!Objects.equals(this.getCategoryId(), other.getCategoryId())) { + return false; + } + + return true; + } + + @Override + public int hashCode () { + int hash = 7; + hash = 13 * hash + Objects.hashCode(this.getCategoryId()); + hash = 13 * hash + Objects.hashCode(this.getCategoryTitle()); + return hash; + } + @Override public Long getCategoryId () { return this.categoryId; @@ -119,4 +149,5 @@ public class ProductCategory implements Category { public void setParentCategory (final Category parentCategory) { this.parentCategory = parentCategory; } + } diff --git a/src/org/mxchange/jshopcore/model/order/Orderable.java b/src/org/mxchange/jshopcore/model/order/Orderable.java index 78a00e8..d505f82 100644 --- a/src/org/mxchange/jshopcore/model/order/Orderable.java +++ b/src/org/mxchange/jshopcore/model/order/Orderable.java @@ -98,4 +98,11 @@ public interface Orderable extends Serializable { * @param orderedItems List of ordered items */ void setOrderedItems (final List orderedItems); + + @Override + boolean equals (final Object object); + + @Override + int hashCode (); + } diff --git a/src/org/mxchange/jshopcore/model/order/ShopOrder.java b/src/org/mxchange/jshopcore/model/order/ShopOrder.java index e74ed09..904cd97 100644 --- a/src/org/mxchange/jshopcore/model/order/ShopOrder.java +++ b/src/org/mxchange/jshopcore/model/order/ShopOrder.java @@ -18,6 +18,7 @@ package org.mxchange.jshopcore.model.order; import java.util.Calendar; import java.util.List; +import java.util.Objects; import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -85,6 +86,41 @@ public class ShopOrder implements Orderable { @Transient private List orderedItems; + @Override + public boolean equals (final Object object) { + if (this == object) { + return true; + } else if (null == object) { + return false; + } else if (this.getClass() != object.getClass()) { + return false; + } + + final Orderable other = (Orderable) object; + + if (!Objects.equals(this.getAccessKey(), other.getAccessKey())) { + return false; + } else if (!Objects.equals(this.getCustomer(), other.getCustomer())) { + return false; + } else if (!Objects.equals(this.getOrderId(), other.getOrderId())) { + return false; + } else if (!Objects.equals(this.getOrderedItems(), other.getOrderedItems())) { + return false; + } + + return true; + } + + @Override + public int hashCode () { + int hash = 7; + hash = 61 * hash + Objects.hashCode(this.getAccessKey()); + hash = 61 * hash + Objects.hashCode(this.getCustomer()); + hash = 61 * hash + Objects.hashCode(this.getOrderId()); + hash = 61 * hash + Objects.hashCode(this.getOrderedItems()); + return hash; + } + @Override public String getAccessKey () { return this.accessKey; @@ -134,4 +170,5 @@ public class ShopOrder implements Orderable { public void setOrderedItems (final List orderedItems) { this.orderedItems = orderedItems; } + } diff --git a/src/org/mxchange/jshopcore/model/product/GenericProduct.java b/src/org/mxchange/jshopcore/model/product/GenericProduct.java index 3f34e79..b1b18e9 100644 --- a/src/org/mxchange/jshopcore/model/product/GenericProduct.java +++ b/src/org/mxchange/jshopcore/model/product/GenericProduct.java @@ -189,4 +189,5 @@ public class GenericProduct implements Product { public void setProductTitle (final String productTitle) { this.productTitle = productTitle; } + } diff --git a/src/org/mxchange/jshopcore/model/product/Product.java b/src/org/mxchange/jshopcore/model/product/Product.java index 88d2261..21f42c6 100644 --- a/src/org/mxchange/jshopcore/model/product/Product.java +++ b/src/org/mxchange/jshopcore/model/product/Product.java @@ -108,4 +108,5 @@ public interface Product extends Serializable { @Override int hashCode (); + }