]> git.mxchange.org Git - jproduct-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sun, 26 Apr 2020 19:06:13 +0000 (21:06 +0200)
committerRoland Häder <roland@mxchange.org>
Sun, 26 Apr 2020 19:06:13 +0000 (21:06 +0200)
- "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 <roland@mxchange.org>
src/org/mxchange/jproduct/model/category/ProductCategory.java
src/org/mxchange/jproduct/model/product/GenericProduct.java

index e21f3f868f5bb3b4b77aaf4226652556628ff8fc..35186674e41e281175f502f0d8bb742f34148420 100644 (file)
@@ -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
         * <p>
@@ -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;
        }
index ce9e83d3d3369aea445cfea4d0a009719ddcdb6a..4bdab1d5f90b9ac9d35bf0495607483791798ebf 100644 (file)
@@ -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;
        }