From cac2dda1c2eb26d9e8730bcd56a7c6003089570e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 26 Apr 2020 21:06:13 +0200 Subject: [PATCH] Continued: - "validate" all parameter of public, package and protected methods - check on all (except created/updated) entity properties in equals()/hashCode() methods MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../model/category/ProductCategory.java | 32 +++++++++++--- .../model/product/GenericProduct.java | 43 ++++++++++++++++--- 2 files changed, 61 insertions(+), 14 deletions(-) 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; } -- 2.39.5