- 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)
*/
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>
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 ();
}
* <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?
// Is the instance set?
return (this.getItemProduct() instanceof 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
*/
package org.mxchange.jshopcore.model.category;
-import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
*/
@Entity (name = "category")
@Table (name = "category")
-public class ProductCategory implements Category, Comparable<Category> {
+public class ProductCategory implements Category {
/**
* Serial number
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
*/
@Entity (name = "customer")
@Table (name = "customer")
-public class ShopCustomer implements Customer, Comparable<Customer> {
+public class ShopCustomer implements Customer {
/**
* Serial number
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
}
@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;
*/
@Entity (name = "orders")
@Table (name = "orders")
-public class ShopOrder implements Orderable, Comparable<Orderable> {
+public class ShopOrder implements Orderable {
/**
* Serial number
@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;
*/
package org.mxchange.jshopcore.model.order.items;
+import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
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;
* @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)
*/
@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
*/
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;
public void setOrderedAmount (final Long orderedAmount) {
this.orderedAmount = orderedAmount;
}
+
}
*/
@Entity (name = "products")
@Table (name = "products")
-public class GenericProduct implements Product, Comparable<Product> {
+public class GenericProduct implements Product {
/**
* Serial number
/**
* 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) {
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
}
@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;