]> git.mxchange.org Git - jshop-core.git/commitdiff
added missing equals() hashCode() methods as this is needed for JPA to work correctly
authorRoland Haeder <roland@mxchange.org>
Sun, 10 Apr 2016 12:58:42 +0000 (14:58 +0200)
committerRoland Haeder <roland@mxchange.org>
Sun, 10 Apr 2016 12:58:42 +0000 (14:58 +0200)
src/org/mxchange/jshopcore/model/basket/BaseBasket.java
src/org/mxchange/jshopcore/model/basket/Basket.java
src/org/mxchange/jshopcore/model/basket/items/BaseItem.java
src/org/mxchange/jshopcore/model/category/Category.java
src/org/mxchange/jshopcore/model/category/ProductCategory.java
src/org/mxchange/jshopcore/model/order/Orderable.java
src/org/mxchange/jshopcore/model/order/ShopOrder.java
src/org/mxchange/jshopcore/model/product/GenericProduct.java
src/org/mxchange/jshopcore/model/product/Product.java

index 8f1a80b8dba095af4488852153b89c21da3dc488..476c52926234ff48f2634a0521dc997fca757a26 100644 (file)
@@ -137,4 +137,5 @@ public abstract class BaseBasket<T extends AddableBasketItem> implements Basket<
                // Deligate call to frontend
                return this.deque.isEmpty();
        }
+
 }
index f5750767f4d66c58a6e06f4756e50ea93a7cfec4..c963ba23cfdfc90b1edf96c3287bc8d244e32ae9 100644 (file)
@@ -34,7 +34,14 @@ public interface Basket<T extends AddableBasketItem> extends Serializable {
         * @param item Item instance to add
         * <p>
         * @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<T extends AddableBasketItem> extends Serializable {
         * @return Whether the basket is empty
         */
        boolean isEmpty ();
+
+       @Override
+       boolean equals (final Object object);
+
+       @Override
+       int hashCode ();
+
 }
index 198afadf52363dff3bcbb2474edb919346022944..fb080ae7284f6e2a2eaf0fdbff5c631981e3906b 100644 (file)
@@ -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.
  * <p>
  * @author Roland Haeder<roland@mxchange.org>
  */
index 64900bfdb98d356aba71c4a89a6fc9967e466df4..15bb232316f591385b82772a033d21412d09df11 100644 (file)
@@ -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 ();
+
 }
index 37e544480ffdf671235c98945e64dca21223539c..dd7bd44d5106162170c48e025a09fceaeecc072f 100644 (file)
@@ -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
         * <p>
-        * @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;
        }
+
 }
index 78a00e835548a7c008a7ea034533ec7b31ef0f6f..d505f82c17af53552a9c7b9ea96b899301c4b3ca 100644 (file)
@@ -98,4 +98,11 @@ public interface Orderable extends Serializable {
         * @param orderedItems List of ordered items
         */
        void setOrderedItems (final List<AddableBasketItem> orderedItems);
+
+       @Override
+       boolean equals (final Object object);
+
+       @Override
+       int hashCode ();
+
 }
index e74ed0900eda1c432338323bb238d43ab44ab478..904cd971026c23b5593f7a9c1b42c4bd4f9b0906 100644 (file)
@@ -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<AddableBasketItem> 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<AddableBasketItem> orderedItems) {
                this.orderedItems = orderedItems;
        }
+
 }
index 3f34e792fdd7f88d402573eff2a589915ad84817..b1b18e9d3ce13a79d32e54a58d16cc4e87da5133 100644 (file)
@@ -189,4 +189,5 @@ public class GenericProduct implements Product {
        public void setProductTitle (final String productTitle) {
                this.productTitle = productTitle;
        }
+
 }
index 88d2261fd0c90abc3528f6e73e223f199f00db25..21f42c65b98d40beada23b1b0ae95f9a452804fe 100644 (file)
@@ -108,4 +108,5 @@ public interface Product extends Serializable {
 
        @Override
        int hashCode ();
+
 }