]> git.mxchange.org Git - jcustomer-core.git/commitdiff
Cleanup:
authorRoland Haeder <roland@mxchange.org>
Sat, 12 Mar 2016 11:45:32 +0000 (12:45 +0100)
committerRoland Haeder <roland@mxchange.org>
Sat, 12 Mar 2016 11:45:32 +0000 (12:45 +0100)
- compareTo()/Comparable<T> was used back in the TDGP times and is no longer needed
- value first, then variable on comparison to avoid accidently assignments
- updated jar(s)

lib/jcontacts-core.jar
lib/jcore.jar
lib/jcoreee.jar
src/org/mxchange/jshopcore/model/basket/AddableBasketItem.java
src/org/mxchange/jshopcore/model/basket/items/BaseItem.java
src/org/mxchange/jshopcore/model/basket/items/BasketItem.java
src/org/mxchange/jshopcore/model/category/ProductCategory.java
src/org/mxchange/jshopcore/model/customer/ShopCustomer.java
src/org/mxchange/jshopcore/model/order/ShopOrder.java
src/org/mxchange/jshopcore/model/order/items/OrderItem.java
src/org/mxchange/jshopcore/model/product/GenericProduct.java

index e905316a232cc3f743e47c1d041b3c782fa666f1..c06f26338a644f05dc23d0100e3b2efc31d0f98f 100644 (file)
Binary files a/lib/jcontacts-core.jar and b/lib/jcontacts-core.jar differ
index 23ef19d3e26ecc03e092895707158a0296bb95bf..097890ccbac9f229dc08c9aa1dd3e6ca12696ce6 100644 (file)
Binary files a/lib/jcore.jar and b/lib/jcore.jar differ
index f2ad1c85d97e64c5a60b7580b4a440554a198134..3f35cb503dc349a077aa978ba857bb1175b5c861 100644 (file)
Binary files a/lib/jcoreee.jar and b/lib/jcoreee.jar differ
index 366783ee3dff8e489d5749e08e5d5600a254a37b..512ca7b1b6017d1a5e16fc22c538961d232d1f30 100644 (file)
@@ -26,14 +26,6 @@ import org.mxchange.jshopcore.model.product.Product;
  */
 public interface AddableBasketItem extends Serializable {
 
-       /**
-        * Check equality on item instance
-        * <p>
-        * @param object Other object to check
-        */
-       @Override
-       boolean equals (final Object object);
-
        /**
         * Getter for item amount
         * <p>
@@ -84,22 +76,22 @@ public interface AddableBasketItem extends Serializable {
        Product getItemProduct ();
 
        /**
-        * Setter fo product instance
+        * Setter for product instance
         * <p>
         * @param product the product to set
         */
        void setItemProduct (final Product product);
 
-       /**
-        * Hash-code calculation
-        */
-       @Override
-       int hashCode ();
-
        /**
         * Determines whether the item has a Product instance set
         * <p>
         * @return Whether a Product instance is set
         */
        boolean isProductType ();
+
+       @Override
+       boolean equals (final Object object);
+
+       @Override
+       int hashCode ();
 }
index d5f015c736d8b41668a372fb5d168671a4f07d3c..198afadf52363dff3bcbb2474edb919346022944 100644 (file)
@@ -26,33 +26,13 @@ import org.mxchange.jshopcore.model.product.Product;
  * <p>
  * @author Roland Haeder<roland@mxchange.org>
  */
-public abstract class BaseItem implements AddableBasketItem, Comparable<AddableBasketItem> {
+public abstract class BaseItem implements AddableBasketItem {
 
        /**
         * Serial number
         */
        private static final long serialVersionUID = 24_348_671_457_829_156L;
 
-       @Override
-       public int compareTo (final AddableBasketItem item) {
-               // item should not be null
-               if (null == item) {
-                       throw new NullPointerException("item is null"); //NOI18N
-               }
-
-               // Is the id the same?
-               if (Objects.equals(this.getItemProduct(), item.getItemProduct())) {
-                       // Same id, means same item
-                       return 0;
-               } else if (this.getItemProduct().getProductId() > item.getItemProduct().getProductId()) {
-                       // This id is larger than compared to
-                       return -1;
-               }
-
-               // The other id is larger
-               return 1;
-       }
-
        @Override
        public boolean equals (final Object object) {
                // Is it same type?
@@ -85,4 +65,5 @@ public abstract class BaseItem implements AddableBasketItem, Comparable<AddableB
                // Is the instance set?
                return (this.getItemProduct() instanceof Product);
        }
+
 }
index 78fb2084fc5376f768345a6dbd20a013f65ed76f..6acdca73d0e39e62cfc62ad8b168151ae1b0bcfe 100644 (file)
@@ -37,7 +37,7 @@ import org.mxchange.jshopcore.model.product.Product;
  */
 @Entity (name = "basket_items")
 @Table (name = "basket_items")
-public class BasketItem extends BaseItem implements AddableBasketItem, Comparable<AddableBasketItem> {
+public class BasketItem extends BaseItem implements AddableBasketItem {
 
        /**
         * Serial number
index 0e9442760b86d061a7bbf82fff269de0c2fab17d..cc632786b728f9ffafcf5224f88bd59015e5a076 100644 (file)
@@ -16,7 +16,6 @@
  */
 package org.mxchange.jshopcore.model.category;
 
-import java.util.Objects;
 import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
@@ -35,7 +34,7 @@ import javax.persistence.Table;
  */
 @Entity (name = "category")
 @Table (name = "category")
-public class ProductCategory implements Category, Comparable<Category> {
+public class ProductCategory implements Category {
 
        /**
         * Serial number
@@ -84,26 +83,6 @@ public class ProductCategory implements Category, Comparable<Category> {
        public ProductCategory () {
        }
 
-       @Override
-       public int compareTo (final Category category) {
-               // category should not be null
-               if (null == category) {
-                       throw new NullPointerException("category is null"); //NOI18N
-               }
-
-               // Is the categoryId the same?
-               if (Objects.equals(this.getCategoryId(), category.getCategoryId())) {
-                       // Same categoryId, means same category
-                       return 0;
-               } else if (this.getCategoryId() > category.getCategoryId()) {
-                       // This categoryId is larger than compared to
-                       return -1;
-               }
-
-               // The other categoryId is larger
-               return 1;
-       }
-
        @Override
        public void copyAll (final Category category) {
                // Copy all data
index 4fe55ce2a3f89cb9745d815eef1f9f4782d38ec8..0165309e13d622fb146536c5faca7263cf12e80b 100644 (file)
@@ -43,7 +43,7 @@ import org.mxchange.jshopcore.model.customer.status.CustomerAccountStatus;
  */
 @Entity (name = "customer")
 @Table (name = "customer")
-public class ShopCustomer implements Customer, Comparable<Customer> {
+public class ShopCustomer implements Customer {
 
        /**
         * Serial number
@@ -112,11 +112,6 @@ public class ShopCustomer implements Customer, Comparable<Customer> {
        public ShopCustomer () {
        }
 
-       @Override
-       public int compareTo (final Customer customer) {
-               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-       }
-
        @Override
        public void copyAll (final Customer customer) {
                // Copy also contact data
@@ -132,16 +127,16 @@ public class ShopCustomer implements Customer, Comparable<Customer> {
        }
 
        @Override
-       public boolean equals (final Object obj) {
-               if (this == obj) {
+       public boolean equals (final Object object) {
+               if (this == object) {
                        return true;
-               } else if (obj == null) {
+               } else if (null == object) {
                        return false;
-               } else if (this.getClass() != obj.getClass()) {
+               } else if (this.getClass() != object.getClass()) {
                        return false;
                }
 
-               final Customer other = (Customer) obj;
+               final Customer other = (Customer) object;
 
                if (!Objects.equals(this.getCustomerNumber(), other.getCustomerNumber())) {
                        return false;
index 51acec5ba3664d93389f0e0f3d6fad6c42fefdd6..54a087c14009fb5d44ae8f72111d165f1fbb5c36 100644 (file)
@@ -42,7 +42,7 @@ import org.mxchange.jshopcore.model.customer.ShopCustomer;
  */
 @Entity (name = "orders")
 @Table (name = "orders")
-public class ShopOrder implements Orderable, Comparable<Orderable> {
+public class ShopOrder implements Orderable {
 
        /**
         * Serial number
@@ -85,11 +85,6 @@ public class ShopOrder implements Orderable, Comparable<Orderable> {
        @Transient
        private List<AddableBasketItem> orderedItems;
 
-       @Override
-       public int compareTo (final Orderable order) {
-               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
-       }
-
        @Override
        public String getAccessKey () {
                return this.accessKey;
index 23f2ab18876021ff634593e44ce062c9ca1e84ac..95b2d15fa96edf3319efa40c35488c36ed56c303 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.jshopcore.model.order.items;
 
+import java.util.Objects;
 import javax.persistence.Basic;
 import javax.persistence.CascadeType;
 import javax.persistence.Column;
@@ -23,6 +24,7 @@ import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
+import javax.persistence.Index;
 import javax.persistence.JoinColumn;
 import javax.persistence.OneToOne;
 import javax.persistence.Table;
@@ -37,21 +39,19 @@ import org.mxchange.jshopcore.model.product.Product;
  * @author Roland Haeder<roland@mxchange.org>
  */
 @Entity (name = "ordered_item")
-@Table (name = "ordered_items")
-public class OrderItem extends BaseItem implements AddableBasketItem, Comparable<AddableBasketItem> {
+@Table (
+               name = "ordered_items",
+               indexes = {
+                       @Index (name = "product", columnList = "order_product_id")
+               }
+)
+public class OrderItem extends BaseItem implements AddableBasketItem {
 
        /**
         * Serial number
         */
        private static final long serialVersionUID = 44_189_562_738_723_581L;
 
-       /**
-        * Item amount
-        */
-       @Basic (optional = false)
-       @Column (name = "order_amount", length = 20, nullable = false)
-       private Long orderedAmount;
-
        /**
         * Entry id (from database backend)
         */
@@ -67,6 +67,13 @@ public class OrderItem extends BaseItem implements AddableBasketItem, Comparable
        @Column (name = "order_item_type", length = 20)
        private String itemType;
 
+       /**
+        * Item amount
+        */
+       @Basic (optional = false)
+       @Column (name = "order_amount", length = 20, nullable = false)
+       private Long orderedAmount;
+
        /**
         * Product instance
         */
@@ -80,6 +87,36 @@ public class OrderItem extends BaseItem implements AddableBasketItem, Comparable
        public OrderItem () {
        }
 
+       @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 AddableBasketItem item = (AddableBasketItem) object;
+
+               if (!Objects.equals(this.itemType, item.getItemType())) {
+                       return false;
+               } else if (!Objects.equals(this.orderedAmount, item.getOrderedAmount())) {
+                       return false;
+               }
+
+               return Objects.equals(this.product, item.getItemProduct());
+       }
+
+       @Override
+       public int hashCode () {
+               int hash = 3;
+               hash = 53 * hash + Objects.hashCode(this.getItemType());
+               hash = 53 * hash + Objects.hashCode(this.getOrderedAmount());
+               hash = 53 * hash + Objects.hashCode(this.getItemProduct());
+               return hash;
+       }
+
        @Override
        public Long getItemId () {
                return this.itemId;
@@ -119,4 +156,5 @@ public class OrderItem extends BaseItem implements AddableBasketItem, Comparable
        public void setOrderedAmount (final Long orderedAmount) {
                this.orderedAmount = orderedAmount;
        }
+
 }
index 05fba515ce397f5135973c3c3bb1ad8ced3d0f36..d1e952f066ee9893fb297804cbbd22bcc08449f6 100644 (file)
@@ -38,7 +38,7 @@ import org.mxchange.jshopcore.model.category.ProductCategory;
  */
 @Entity (name = "products")
 @Table (name = "products")
-public class GenericProduct implements Product, Comparable<Product> {
+public class GenericProduct implements Product {
 
        /**
         * Serial number
@@ -89,10 +89,10 @@ public class GenericProduct implements Product, Comparable<Product> {
        /**
         * Constructor will all required data
         * <p>
-        * @param productId Id number of product
-        * @param productTitle Name of product
-        * @param productPrice Price
-        * @param productCategory Category instance
+        * @param productId           Id number of product
+        * @param productTitle        Name of product
+        * @param productPrice        Price
+        * @param productCategory     Category instance
         * @param productAvailability Availability (selectable by customer)
         */
        public GenericProduct (final Long productId, final String productTitle, final Float productPrice, final Category productCategory, final Boolean productAvailability) {
@@ -104,26 +104,6 @@ public class GenericProduct implements Product, Comparable<Product> {
                this.productAvailability = productAvailability;
        }
 
-       @Override
-       public int compareTo (final Product product) {
-               // productCategory should not be null
-               if (null == product) {
-                       throw new NullPointerException("product is null"); //NOI18N
-               }
-
-               // Is the productId the same?
-               if (Objects.equals(this.getProductId(), product.getProductId())) {
-                       // Same productId, means same productCategory
-                       return 0;
-               } else if (this.getProductId() > product.getProductId()) {
-                       // This productId is larger than compared to
-                       return 1;
-               }
-
-               // The other productId is larger
-               return -1;
-       }
-
        @Override
        public void copyAll (final Product product) {
                // Copy all
@@ -134,16 +114,16 @@ public class GenericProduct implements Product, Comparable<Product> {
        }
 
        @Override
-       public boolean equals (final Object obj) {
-               if (this == obj) {
+       public boolean equals (final Object object) {
+               if (this == object) {
                        return true;
-               } else if (obj == null) {
+               } else if (null == object) {
                        return false;
-               } else if (this.getClass() != obj.getClass()) {
+               } else if (this.getClass() != object.getClass()) {
                        return false;
                }
 
-               final Product other = (Product) obj;
+               final Product other = (Product) object;
 
                if (!Objects.equals(this.getProductTitle(), other.getProductTitle())) {
                        return false;