+++ /dev/null
-/*
- * 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
- }
-
-}
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
// 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
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)
// ... 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
+++ /dev/null
-/*
- * 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
- }
-
-}
--- /dev/null
+/*
+ * 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
+ }
+
+}
--- /dev/null
+/*
+ * 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
+ }
+
+}