]> git.mxchange.org Git - jproduct-core.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 6 Oct 2022 13:34:37 +0000 (15:34 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 6 Oct 2022 13:34:37 +0000 (15:34 +0200)
- renamed utility classes *s to *Utils
- moved them to their own package

src/org/mxchange/jproduct/model/category/Categories.java [deleted file]
src/org/mxchange/jproduct/model/category/ProductCategory.java
src/org/mxchange/jproduct/model/product/GenericProduct.java
src/org/mxchange/jproduct/model/product/Products.java [deleted file]
src/org/mxchange/jproduct/model/utils/CategoryUtils.java [new file with mode: 0644]
src/org/mxchange/jproduct/model/utils/ProductUtils.java [new file with mode: 0644]

diff --git a/src/org/mxchange/jproduct/model/category/Categories.java b/src/org/mxchange/jproduct/model/category/Categories.java
deleted file mode 100644 (file)
index 72efca7..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright (C) 2022 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jproduct.model.category;
-
-import java.io.Serializable;
-import java.util.Objects;
-
-/**
- * An utilities class for product categories
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public class Categories implements Serializable {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 157_687_661_634_901L;
-
-       /**
-        * Compares both Category instances. This method returns -1 if second
-        * instance is null.
-        * <p>
-        * @param category1 Category instance 1
-        * @param category2 Category instance 2
-        * <p>
-        * @return Comparison value
-        */
-       public static int compare (final Category category1, final Category category2) {
-               // Check equality, then at least first must be given
-               if (Objects.equals(category1, category2)) {
-                       // Both are same
-                       return 0;
-               } else if (null == category1) {
-                       // First is null
-                       return -1;
-               } else if (null == category2) {
-                       // Second is null
-                       return 1;
-               }
-
-               // Invoke compareTo() method
-               return category1.compareTo(category2);
-       }
-
-       /**
-        * Copies all data from source category to target category
-        * <p>
-        * @param sourceCategory Source category instance
-        * @param targetCategory Target category instance
-        */
-       public static void copyCategoryData (final Category sourceCategory, final Category targetCategory) {
-               // Category should be valid
-               if (null == sourceCategory) {
-                       // Throw NPE
-                       throw new NullPointerException("sourceCategory is null"); //NOI18N
-               } else if (null == targetCategory) {
-                       // Throw NPE
-                       throw new NullPointerException("targetCategory is null"); //NOI18N
-               } else if (Objects.equals(sourceCategory, targetCategory)) {
-                       // Is exactly the same!
-                       throw new IllegalArgumentException("sourcerCategory and targetCategory are the same."); //NOI18N
-               }
-
-               // Copy all fields
-               targetCategory.setCategoryI18nKey(sourceCategory.getCategoryI18nKey());
-               targetCategory.setCategoryId(sourceCategory.getCategoryId());
-               targetCategory.setCategoryShownInStatistics(sourceCategory.getCategoryShownInStatistics());
-               targetCategory.setParentCategory(sourceCategory.getParentCategory());
-       }
-
-       /**
-        * Utility classes should have no instances
-        */
-       private Categories () {
-               // Private constructor
-       }
-
-}
index ef537fd10e45241bc1e4a5dc44e28be746e23123..4c1a7abc2223ec86fb44f0f42fbffc46cc4ae0ca 100644 (file)
@@ -33,7 +33,9 @@ import javax.persistence.Table;
 import javax.persistence.Temporal;
 import javax.persistence.TemporalType;
 import javax.persistence.Transient;
+import org.apache.commons.lang3.StringUtils;
 import org.mxchange.jcoreutils.Comparables;
+import org.mxchange.jproduct.model.utils.CategoryUtils;
 
 /**
  * A product category
@@ -148,9 +150,9 @@ public class ProductCategory implements Category {
                // Init comparators
                final int comparators[] = {
                        // First check parent category
-                       Categories.compare(this.getParentCategory(), category.getParentCategory()),
+                       CategoryUtils.compare(this.getParentCategory(), category.getParentCategory()),
                        // ... last is i18n key as it is unique
-                       this.getCategoryI18nKey().compareTo(category.getCategoryI18nKey())
+                       StringUtils.compare(this.getCategoryI18nKey(), category.getCategoryI18nKey())
                };
 
                // Check all values
index 2454b8419ef13342a645abb6bb928fc61fcceb96..04457e33a27a85e990e4d4c4036285dbb21b6374 100644 (file)
@@ -40,14 +40,14 @@ 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.jcontactsbusiness.model.utils.BasicDataUtils;
 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;
+import org.mxchange.jproduct.model.utils.CategoryUtils;
 
 /**
  * Generic product POJO (entity)
@@ -301,21 +301,21 @@ public class GenericProduct implements Product {
                        // ... size
                        StringUtils.compare(this.getProductSize(), product.getProductSize()),
                        // ... then i18n key
-                       this.getProductI18nKey().compareTo(product.getProductI18nKey()),
+                       StringUtils.compare(this.getProductI18nKey(), product.getProductI18nKey()),
                        // ... gross price
-                       this.getProductGrossPrice().compareTo(product.getProductGrossPrice()),
+                       SafeNumberUtils.compare(this.getProductGrossPrice(), 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()),
+                       SafeNumberUtils.compare(this.getProductUnitAmount(), product.getProductUnitAmount()),
                        // ... currency code
-                       this.getProductCurrencyCode().compareTo(product.getProductCurrencyCode()),
+                       StringUtils.compare(this.getProductCurrencyCode(), product.getProductCurrencyCode()),
                        // ... manufacturer
                        BasicDataUtils.compare(this.getProductManufacturer(), product.getProductManufacturer()),
                        // ... category
-                       Categories.compare(this.getProductCategory(), product.getProductCategory())
+                       CategoryUtils.compare(this.getProductCategory(), product.getProductCategory())
                };
 
                // Check all values
diff --git a/src/org/mxchange/jproduct/model/product/Products.java b/src/org/mxchange/jproduct/model/product/Products.java
deleted file mode 100644 (file)
index fc73b10..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (C) 2022 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jproduct.model.product;
-
-import java.io.Serializable;
-import java.util.Objects;
-
-/**
- * An utilities class for generic products
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public class Products implements Serializable {
-
-       /**
-        * Serial number
-        */
-       private static final long serialVersionUID = 157_687_661_634_902L;
-
-       /**
-        * Compares both Product instances. This method returns -1 if second
-        * instance is null.
-        * <p>
-        * @param product1 Product instance 1
-        * @param product2 Product instance 2
-        * <p>
-        * @return Comparison value
-        */
-       public static int compare (final Product product1, final Product product2) {
-               // Check equality, then at least first must be given
-               if (Objects.equals(product1, product2)) {
-                       // Both are same
-                       return 0;
-               } else if (null == product1) {
-                       // First is null
-                       return -1;
-               } else if (null == product2) {
-                       // Second is null
-                       return 1;
-               }
-
-               // Invoke compareTo() method
-               return product1.compareTo(product2);
-       }
-
-       /**
-        * Copies all properties from source product to target product
-        * <p>
-        * @param sourceProduct Source product instance
-        * @param targetProduct Target product instance
-        * <p>
-        * @throws NullPointerException If one instance is null
-        */
-       public static void copyProductData (final Product sourceProduct, final Product targetProduct) {
-               // Product should be valid
-               if (null == sourceProduct) {
-                       // Throw NPE
-                       throw new NullPointerException("sourceProduct is null"); //NOI18N
-               } else if (null == targetProduct) {
-                       // Throw NPE
-                       throw new NullPointerException("targetProduct is null"); //NOI18N
-               } else if (Objects.equals(sourceProduct, targetProduct)) {
-                       // Is exactly the same!
-                       throw new IllegalArgumentException("sourcerProduct and targetProduct are the same."); //NOI18N
-               }
-
-               // Copy all:
-               targetProduct.setProductAgeGroup(sourceProduct.getProductAgeGroup());
-               targetProduct.setProductAvailability(sourceProduct.getProductAvailability());
-               targetProduct.setProductBarCodeNumber(sourceProduct.getProductBarCodeNumber());
-               targetProduct.setProductCategory(sourceProduct.getProductCategory());
-               targetProduct.setProductCurrencyCode(sourceProduct.getProductCurrencyCode());
-               targetProduct.setProductFscNumber(sourceProduct.getProductFscNumber());
-               targetProduct.setProductGrossPrice(sourceProduct.getProductGrossPrice());
-               targetProduct.setProductI18nKey(sourceProduct.getProductI18nKey());
-               targetProduct.setProductManufacturer(sourceProduct.getProductManufacturer());
-               targetProduct.setProductNetPrice(sourceProduct.getProductNetPrice());
-               targetProduct.setProductNumber(sourceProduct.getProductNumber());
-               targetProduct.setProductSize(sourceProduct.getProductSize());
-               targetProduct.setProductTaxRate(sourceProduct.getProductTaxRate());
-               targetProduct.setProductUnitAmount(sourceProduct.getProductUnitAmount());
-               targetProduct.setProductUnitI18nKey(sourceProduct.getProductUnitI18nKey());
-       }
-
-       /**
-        * Utility classes should have no instances
-        */
-       private Products () {
-               // Private constructor
-       }
-
-}
diff --git a/src/org/mxchange/jproduct/model/utils/CategoryUtils.java b/src/org/mxchange/jproduct/model/utils/CategoryUtils.java
new file mode 100644 (file)
index 0000000..891f1d8
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2022 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jproduct.model.utils;
+
+import java.io.Serializable;
+import java.util.Objects;
+import org.mxchange.jproduct.model.category.Category;
+
+/**
+ * An utilities class for product categories
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class CategoryUtils implements Serializable {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 157_687_661_634_901L;
+
+       /**
+        * Compares both Category instances. This method returns -1 if second
+        * instance is null.
+        * <p>
+        * @param category1 Category instance 1
+        * @param category2 Category instance 2
+        * <p>
+        * @return Comparison value
+        */
+       public static int compare (final Category category1, final Category category2) {
+               // Check equality, then at least first must be given
+               if (Objects.equals(category1, category2)) {
+                       // Both are same
+                       return 0;
+               } else if (null == category1) {
+                       // First is null
+                       return -1;
+               } else if (null == category2) {
+                       // Second is null
+                       return 1;
+               }
+
+               // Invoke compareTo() method
+               return category1.compareTo(category2);
+       }
+
+       /**
+        * Copies all data from source category to target category
+        * <p>
+        * @param sourceCategory Source category instance
+        * @param targetCategory Target category instance
+        */
+       public static void copyCategoryData (final Category sourceCategory, final Category targetCategory) {
+               // Category should be valid
+               if (null == sourceCategory) {
+                       // Throw NPE
+                       throw new NullPointerException("sourceCategory is null"); //NOI18N
+               } else if (null == targetCategory) {
+                       // Throw NPE
+                       throw new NullPointerException("targetCategory is null"); //NOI18N
+               } else if (Objects.equals(sourceCategory, targetCategory)) {
+                       // Is exactly the same!
+                       throw new IllegalArgumentException("sourcerCategory and targetCategory are the same."); //NOI18N
+               }
+
+               // Copy all fields
+               targetCategory.setCategoryI18nKey(sourceCategory.getCategoryI18nKey());
+               targetCategory.setCategoryId(sourceCategory.getCategoryId());
+               targetCategory.setCategoryShownInStatistics(sourceCategory.getCategoryShownInStatistics());
+               targetCategory.setParentCategory(sourceCategory.getParentCategory());
+       }
+
+       /**
+        * Utility classes should have no instances
+        */
+       private CategoryUtils () {
+               // Private constructor
+       }
+
+}
diff --git a/src/org/mxchange/jproduct/model/utils/ProductUtils.java b/src/org/mxchange/jproduct/model/utils/ProductUtils.java
new file mode 100644 (file)
index 0000000..7c8f383
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * Copyright (C) 2022 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jproduct.model.utils;
+
+import java.io.Serializable;
+import java.util.Objects;
+import org.mxchange.jproduct.model.product.Product;
+
+/**
+ * An utilities class for generic products
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public class ProductUtils implements Serializable {
+
+       /**
+        * Serial number
+        */
+       private static final long serialVersionUID = 157_687_661_634_902L;
+
+       /**
+        * Compares both Product instances. This method returns -1 if second
+        * instance is null.
+        * <p>
+        * @param product1 Product instance 1
+        * @param product2 Product instance 2
+        * <p>
+        * @return Comparison value
+        */
+       public static int compare (final Product product1, final Product product2) {
+               // Check equality, then at least first must be given
+               if (Objects.equals(product1, product2)) {
+                       // Both are same
+                       return 0;
+               } else if (null == product1) {
+                       // First is null
+                       return -1;
+               } else if (null == product2) {
+                       // Second is null
+                       return 1;
+               }
+
+               // Invoke compareTo() method
+               return product1.compareTo(product2);
+       }
+
+       /**
+        * Copies all properties from source product to target product
+        * <p>
+        * @param sourceProduct Source product instance
+        * @param targetProduct Target product instance
+        * <p>
+        * @throws NullPointerException If one instance is null
+        */
+       public static void copyProductData (final Product sourceProduct, final Product targetProduct) {
+               // Product should be valid
+               if (null == sourceProduct) {
+                       // Throw NPE
+                       throw new NullPointerException("sourceProduct is null"); //NOI18N
+               } else if (null == targetProduct) {
+                       // Throw NPE
+                       throw new NullPointerException("targetProduct is null"); //NOI18N
+               } else if (Objects.equals(sourceProduct, targetProduct)) {
+                       // Is exactly the same!
+                       throw new IllegalArgumentException("sourcerProduct and targetProduct are the same."); //NOI18N
+               }
+
+               // Copy all:
+               targetProduct.setProductAgeGroup(sourceProduct.getProductAgeGroup());
+               targetProduct.setProductAvailability(sourceProduct.getProductAvailability());
+               targetProduct.setProductBarCodeNumber(sourceProduct.getProductBarCodeNumber());
+               targetProduct.setProductCategory(sourceProduct.getProductCategory());
+               targetProduct.setProductCurrencyCode(sourceProduct.getProductCurrencyCode());
+               targetProduct.setProductFscNumber(sourceProduct.getProductFscNumber());
+               targetProduct.setProductGrossPrice(sourceProduct.getProductGrossPrice());
+               targetProduct.setProductI18nKey(sourceProduct.getProductI18nKey());
+               targetProduct.setProductManufacturer(sourceProduct.getProductManufacturer());
+               targetProduct.setProductNetPrice(sourceProduct.getProductNetPrice());
+               targetProduct.setProductNumber(sourceProduct.getProductNumber());
+               targetProduct.setProductSize(sourceProduct.getProductSize());
+               targetProduct.setProductTaxRate(sourceProduct.getProductTaxRate());
+               targetProduct.setProductUnitAmount(sourceProduct.getProductUnitAmount());
+               targetProduct.setProductUnitI18nKey(sourceProduct.getProductUnitI18nKey());
+       }
+
+       /**
+        * Utility classes should have no instances
+        */
+       private ProductUtils () {
+               // Private constructor
+       }
+
+}