From: Roland Haeder Date: Sat, 12 Mar 2016 11:45:32 +0000 (+0100) Subject: Cleanup: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d331b9a861326deb6c5503487ff106efb67ee59b;p=jproduct-core.git Cleanup: - compareTo()/Comparable 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) --- diff --git a/lib/jcontacts-core.jar b/lib/jcontacts-core.jar index e905316..c06f263 100644 Binary files a/lib/jcontacts-core.jar and b/lib/jcontacts-core.jar differ diff --git a/lib/jcore.jar b/lib/jcore.jar index 23ef19d..097890c 100644 Binary files a/lib/jcore.jar and b/lib/jcore.jar differ diff --git a/lib/jcoreee.jar b/lib/jcoreee.jar index f2ad1c8..3f35cb5 100644 Binary files a/lib/jcoreee.jar and b/lib/jcoreee.jar differ diff --git a/src/org/mxchange/jshopcore/model/basket/AddableBasketItem.java b/src/org/mxchange/jshopcore/model/basket/AddableBasketItem.java index 366783e..512ca7b 100644 --- a/src/org/mxchange/jshopcore/model/basket/AddableBasketItem.java +++ b/src/org/mxchange/jshopcore/model/basket/AddableBasketItem.java @@ -26,14 +26,6 @@ import org.mxchange.jshopcore.model.product.Product; */ public interface AddableBasketItem extends Serializable { - /** - * Check equality on item instance - *

- * @param object Other object to check - */ - @Override - boolean equals (final Object object); - /** * Getter for item amount *

@@ -84,22 +76,22 @@ public interface AddableBasketItem extends Serializable { Product getItemProduct (); /** - * Setter fo product instance + * Setter for product instance *

* @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 *

* @return Whether a Product instance is set */ boolean isProductType (); + + @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 d5f015c..198afad 100644 --- a/src/org/mxchange/jshopcore/model/basket/items/BaseItem.java +++ b/src/org/mxchange/jshopcore/model/basket/items/BaseItem.java @@ -26,33 +26,13 @@ import org.mxchange.jshopcore.model.product.Product; *

* @author Roland Haeder */ -public abstract class BaseItem implements AddableBasketItem, Comparable { +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 { +public class BasketItem extends BaseItem implements AddableBasketItem { /** * Serial number diff --git a/src/org/mxchange/jshopcore/model/category/ProductCategory.java b/src/org/mxchange/jshopcore/model/category/ProductCategory.java index 0e94427..cc63278 100644 --- a/src/org/mxchange/jshopcore/model/category/ProductCategory.java +++ b/src/org/mxchange/jshopcore/model/category/ProductCategory.java @@ -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 { +public class ProductCategory implements Category { /** * Serial number @@ -84,26 +83,6 @@ public class ProductCategory implements Category, Comparable { 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 diff --git a/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java b/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java index 4fe55ce..0165309 100644 --- a/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java +++ b/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java @@ -43,7 +43,7 @@ import org.mxchange.jshopcore.model.customer.status.CustomerAccountStatus; */ @Entity (name = "customer") @Table (name = "customer") -public class ShopCustomer implements Customer, Comparable { +public class ShopCustomer implements Customer { /** * Serial number @@ -112,11 +112,6 @@ public class ShopCustomer implements Customer, Comparable { 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 { } @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; diff --git a/src/org/mxchange/jshopcore/model/order/ShopOrder.java b/src/org/mxchange/jshopcore/model/order/ShopOrder.java index 51acec5..54a087c 100644 --- a/src/org/mxchange/jshopcore/model/order/ShopOrder.java +++ b/src/org/mxchange/jshopcore/model/order/ShopOrder.java @@ -42,7 +42,7 @@ import org.mxchange.jshopcore.model.customer.ShopCustomer; */ @Entity (name = "orders") @Table (name = "orders") -public class ShopOrder implements Orderable, Comparable { +public class ShopOrder implements Orderable { /** * Serial number @@ -85,11 +85,6 @@ public class ShopOrder implements Orderable, Comparable { @Transient private List 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; diff --git a/src/org/mxchange/jshopcore/model/order/items/OrderItem.java b/src/org/mxchange/jshopcore/model/order/items/OrderItem.java index 23f2ab1..95b2d15 100644 --- a/src/org/mxchange/jshopcore/model/order/items/OrderItem.java +++ b/src/org/mxchange/jshopcore/model/order/items/OrderItem.java @@ -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 */ @Entity (name = "ordered_item") -@Table (name = "ordered_items") -public class OrderItem extends BaseItem implements AddableBasketItem, Comparable { +@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; } + } diff --git a/src/org/mxchange/jshopcore/model/product/GenericProduct.java b/src/org/mxchange/jshopcore/model/product/GenericProduct.java index 05fba51..d1e952f 100644 --- a/src/org/mxchange/jshopcore/model/product/GenericProduct.java +++ b/src/org/mxchange/jshopcore/model/product/GenericProduct.java @@ -38,7 +38,7 @@ import org.mxchange.jshopcore.model.category.ProductCategory; */ @Entity (name = "products") @Table (name = "products") -public class GenericProduct implements Product, Comparable { +public class GenericProduct implements Product { /** * Serial number @@ -89,10 +89,10 @@ public class GenericProduct implements Product, Comparable { /** * Constructor will all required data *

- * @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 { 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 { } @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;