From: Roland Häder Date: Sun, 26 Apr 2020 19:06:13 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=cac2dda1c2eb26d9e8730bcd56a7c6003089570e;p=jproduct-core.git Continued: - "validate" all parameter of public, package and protected methods - check on all (except created/updated) entity properties in equals()/hashCode() methods Signed-off-by: Roland Häder --- diff --git a/src/org/mxchange/jproduct/model/category/ProductCategory.java b/src/org/mxchange/jproduct/model/category/ProductCategory.java index e21f3f8..3518667 100644 --- a/src/org/mxchange/jproduct/model/category/ProductCategory.java +++ b/src/org/mxchange/jproduct/model/category/ProductCategory.java @@ -100,6 +100,12 @@ public class ProductCategory implements Category { @OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH) private Category parentCategory; + /** + * Default constructor + */ + public ProductCategory () { + } + /** * Constructor with all required fields *

@@ -111,17 +117,23 @@ public class ProductCategory implements Category { // Call other constructor this(); + // Validate parameter + if (null == categoryI18nKey) { + // Throw NPE + throw new NullPointerException("categoryI18nKey is null"); //NOI18N + } else if (categoryI18nKey.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("categoryI18nKey is empty"); //NOI18N + } else if (null == categoryShownInStatistics) { + // Throw NPE + throw new NullPointerException("categoryShownInStatistics is null"); //NOI18N + } + // Set all here this.categoryI18nKey = categoryI18nKey; this.categoryShownInStatistics = categoryShownInStatistics; } - /** - * Default constructor - */ - public ProductCategory () { - } - @Override public int compareTo (final Category category) { // Check parameter on null-reference and equality to this @@ -162,6 +174,10 @@ public class ProductCategory implements Category { if (!Objects.equals(this.getCategoryI18nKey(), category.getCategoryI18nKey())) { return false; + } else if (!Objects.equals(this.getCategoryShownInStatistics(), category.getCategoryShownInStatistics())) { + return false; + } else if (!Objects.equals(this.getParentCategory(), category.getParentCategory())) { + return false; } else if (!Objects.equals(this.getCategoryId(), category.getCategoryId())) { return false; } @@ -237,8 +253,10 @@ public class ProductCategory implements Category { public int hashCode () { int hash = 7; - hash = 13 * hash + Objects.hashCode(this.getCategoryId()); hash = 13 * hash + Objects.hashCode(this.getCategoryI18nKey()); + hash = 13 * hash + Objects.hashCode(this.getCategoryId()); + hash = 13 * hash + Objects.hashCode(this.getCategoryShownInStatistics()); + hash = 13 * hash + Objects.hashCode(this.getParentCategory()); return hash; } diff --git a/src/org/mxchange/jproduct/model/product/GenericProduct.java b/src/org/mxchange/jproduct/model/product/GenericProduct.java index ce9e83d..4bdab1d 100644 --- a/src/org/mxchange/jproduct/model/product/GenericProduct.java +++ b/src/org/mxchange/jproduct/model/product/GenericProduct.java @@ -337,17 +337,37 @@ public class GenericProduct implements Product { final Product product = (Product) object; - if (!Objects.equals(this.getProductGrossPrice(), product.getProductGrossPrice())) { + if (!Objects.equals(this.getProductAgeGroup(), product.getProductAgeGroup())) { return false; - } else if (!Objects.equals(this.getProductId(), product.getProductId())) { + } else if (!Objects.equals(this.getProductAvailability(), product.getProductAvailability())) { + return false; + } else if (!Objects.equals(this.getProductBarCodeNumber(), product.getProductBarCodeNumber())) { + return false; + } else if (!Objects.equals(this.getProductCategory(), product.getProductCategory())) { + return false; + } else if (!Objects.equals(this.getProductCurrencyCode(), product.getProductCurrencyCode())) { + return false; + } else if (!Objects.equals(this.getProductFscNumber(), product.getProductFscNumber())) { + return false; + } else if (!Objects.equals(this.getProductGrossPrice(), product.getProductGrossPrice())) { return false; } else if (!Objects.equals(this.getProductI18nKey(), product.getProductI18nKey())) { return false; - } else if (!Objects.equals(this.getProductAgeGroup(), product.getProductAgeGroup())) { + } else if (!Objects.equals(this.getProductId(), product.getProductId())) { + return false; + } else if (!Objects.equals(this.getProductManufacturer(), product.getProductManufacturer())) { + return false; + } else if (!Objects.equals(this.getProductNetPrice(), product.getProductNetPrice())) { + return false; + } else if (!Objects.equals(this.getProductNumber(), product.getProductNumber())) { return false; } else if (!Objects.equals(this.getProductSize(), product.getProductSize())) { return false; - } else if (!Objects.equals(this.getProductBarCodeNumber(), product.getProductBarCodeNumber())) { + } else if (!Objects.equals(this.getProductTaxRate(), product.getProductTaxRate())) { + return false; + } else if (!Objects.equals(this.getProductUnitAmount(), product.getProductUnitAmount())) { + return false; + } else if (!Objects.equals(this.getProductUnitI18nKey(), product.getProductUnitI18nKey())) { return false; } @@ -542,12 +562,21 @@ public class GenericProduct implements Product { public int hashCode () { int hash = 7; + hash = 23 * hash + Objects.hashCode(this.getProductAgeGroup()); + hash = 23 * hash + Objects.hashCode(this.getProductBarCodeNumber()); + hash = 23 * hash + Objects.hashCode(this.getProductCategory()); + hash = 23 * hash + Objects.hashCode(this.getProductCurrencyCode()); + hash = 23 * hash + Objects.hashCode(this.getProductFscNumber()); hash = 23 * hash + Objects.hashCode(this.getProductGrossPrice()); - hash = 23 * hash + Objects.hashCode(this.getProductId()); hash = 23 * hash + Objects.hashCode(this.getProductI18nKey()); - hash = 23 * hash + Objects.hashCode(this.getProductAgeGroup()); + hash = 23 * hash + Objects.hashCode(this.getProductId()); + hash = 23 * hash + Objects.hashCode(this.getProductManufacturer()); + hash = 23 * hash + Objects.hashCode(this.getProductNetPrice()); + hash = 23 * hash + Objects.hashCode(this.getProductNumber()); hash = 23 * hash + Objects.hashCode(this.getProductSize()); - hash = 23 * hash + Objects.hashCode(this.getProductBarCodeNumber()); + hash = 23 * hash + Objects.hashCode(this.getProductTaxRate()); + hash = 23 * hash + Objects.hashCode(this.getProductUnitAmount()); + hash = 23 * hash + Objects.hashCode(this.getProductUnitI18nKey()); return hash; }