/*
- * Copyright (C) 2016, 2017 Free Software Foundation
+ * Copyright (C) 2016 - 2018 Free Software Foundation
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
+import org.apache.commons.lang3.StringUtils;
import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicDataUtils;
import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
+import org.mxchange.jcoreutils.Comparables;
+import org.mxchange.jcoreutils.SafeNumberUtils;
+import org.mxchange.jproduct.model.category.Categories;
import org.mxchange.jproduct.model.category.Category;
import org.mxchange.jproduct.model.category.ProductCategory;
import org.mxchange.jproduct.model.product.agegroup.AgeGroup;
/**
- * Generic product class
+ * Generic product POJO (entity)
* <p>
* @author Roland Häder<roland@mxchange.org>
- * TODO: Find a better name
*/
@Entity (name = "generic_products")
@Table (
* @throws IllegalArgumentException If a parameter is empty (string) or out
* of bounds
*/
- public GenericProduct (final String productI18nKey, final BigDecimal productGrossPrice, final String productCurrencyCode, final Category productCategory, final Boolean productAvailability, final BigDecimal productUnitAmount , final String productUnitI18nKey) {
+ public GenericProduct (final String productI18nKey, final BigDecimal productGrossPrice, final String productCurrencyCode, final Category productCategory, final Boolean productAvailability, final BigDecimal productUnitAmount, final String productUnitI18nKey) {
// Call other constructor first
this();
this.productUnitI18nKey = productUnitI18nKey;
}
+ @Override
+ public int compareTo (final Product product) {
+ // Check parameter on null-reference and equality to this
+ if (null == product) {
+ // Should not happen
+ throw new NullPointerException("product is null"); //NOI18N
+ } else if (product.equals(this)) {
+ // Same object
+ return 0;
+ }
+
+ // Init comparators
+ final int comparators[] = {
+ // First check product number
+ SafeNumberUtils.compare(this.getProductNumber(), product.getProductNumber()),
+ // ... size
+ StringUtils.compare(this.getProductSize(), product.getProductSize()),
+ // ... then i18n key
+ this.getProductI18nKey().compareTo(product.getProductI18nKey()),
+ // ... gross price
+ this.getProductGrossPrice().compareTo(product.getProductGrossPrice()),
+ // ... net price
+ SafeNumberUtils.compare(this.getProductNetPrice(), product.getProductNetPrice()),
+ // ... tax rate
+ SafeNumberUtils.compare(this.getProductTaxRate(), product.getProductTaxRate()),
+ // ... unit amount
+ this.getProductUnitAmount().compareTo(product.getProductUnitAmount()),
+ // ... currency code
+ this.getProductCurrencyCode().compareTo(product.getProductCurrencyCode()),
+ // ... manufacturer
+ BasicDataUtils.compare(this.getProductManufacturer(), product.getProductManufacturer()),
+ // ... category
+ Categories.compare(this.getProductCategory(), product.getProductCategory())
+ };
+
+ // Check all values
+ final int comparison = Comparables.checkAll(comparators);
+
+ // Return value
+ return comparison;
+ }
+
@Override
public boolean equals (final Object object) {
if (this == object) {