2 * Copyright (C) 2018 Free Software Foundation
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jproduct.model.product;
19 import java.io.Serializable;
20 import java.util.Objects;
23 * An utilities class for generic products
25 * @author Roland Häder<roland@mxchange.org>
27 public class Products implements Serializable {
32 private static final long serialVersionUID = 157_687_661_634_902L;
35 * Compares both Product instances. This method returns -1 if second
38 * @param product1 Product instance 1
39 * @param product2 Product instance 2
41 * @return Comparison value
43 public static int compare (final Product product1, final Product product2) {
44 // Check euqality, then at least first must be given
45 if (Objects.equals(product1, product2)) {
48 } else if (null == product1) {
51 } else if (null == product2) {
56 // Invoke compareTo() method
57 return product1.compareTo(product2);
61 * Copies all properties from source product to target product
63 * @param sourceProduct Source product instance
64 * @param targetProduct Target product instance
66 * @throws NullPointerException If one instance is null
68 public static void copyAll (final Product sourceProduct, final Product targetProduct) {
69 // Product should be valid
70 if (null == sourceProduct) {
72 throw new NullPointerException("sourceProduct is null"); //NOI18N
73 } else if (null == targetProduct) {
75 throw new NullPointerException("targetProduct is null"); //NOI18N
79 targetProduct.setProductAgeGroup(sourceProduct.getProductAgeGroup());
80 targetProduct.setProductAvailability(sourceProduct.getProductAvailability());
81 targetProduct.setProductCategory(sourceProduct.getProductCategory());
82 targetProduct.setProductCreated(sourceProduct.getProductCreated());
83 targetProduct.setProductCurrencyCode(sourceProduct.getProductCurrencyCode());
84 targetProduct.setProductGrossPrice(sourceProduct.getProductGrossPrice());
85 targetProduct.setProductI18nKey(sourceProduct.getProductI18nKey());
86 targetProduct.setProductManufacturer(sourceProduct.getProductManufacturer());
87 targetProduct.setProductNetPrice(sourceProduct.getProductNetPrice());
88 targetProduct.setProductNumber(sourceProduct.getProductNumber());
89 targetProduct.setProductSize(sourceProduct.getProductSize());
90 targetProduct.setProductTaxRate(sourceProduct.getProductTaxRate());
91 targetProduct.setProductUnitAmount(sourceProduct.getProductUnitAmount());
92 targetProduct.setProductUnitI18nKey(sourceProduct.getProductUnitI18nKey());
96 * Utility classes should have no instances
99 // Private constructor