]> git.mxchange.org Git - jproduct-core.git/blob - src/org/mxchange/jproduct/model/product/Products.java
Continued:
[jproduct-core.git] / src / org / mxchange / jproduct / model / product / Products.java
1 /*
2  * Copyright (C) 2018 Free Software Foundation
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jproduct.model.product;
18
19 import java.io.Serializable;
20 import java.util.Objects;
21
22 /**
23  * An utilities class for generic products
24  * <p>
25  * @author Roland Häder<roland@mxchange.org>
26  */
27 public class Products implements Serializable {
28
29         /**
30          * Serial number
31          */
32         private static final long serialVersionUID = 157_687_661_634_902L;
33
34         /**
35          * Compares both Product instances. This method returns -1 if second
36          * instance is null.
37          * <p>
38          * @param product1 Product instance 1
39          * @param product2 Product instance 2
40          * <p>
41          * @return Comparison value
42          */
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)) {
46                         // Both are same
47                         return 0;
48                 } else if (null == product1) {
49                         // First is null
50                         return -1;
51                 } else if (null == product2) {
52                         // Second is null
53                         return 1;
54                 }
55
56                 // Invoke compareTo() method
57                 return product1.compareTo(product2);
58         }
59
60         /**
61          * Copies all properties from source product to target product
62          * <p>
63          * @param sourceProduct Source product instance
64          * @param targetProduct Target product instance
65          * <p>
66          * @throws NullPointerException If one instance is null
67          */
68         public static void copyAll (final Product sourceProduct, final Product targetProduct) {
69                 // Product should be valid
70                 if (null == sourceProduct) {
71                         // Throw NPE
72                         throw new NullPointerException("sourceProduct is null"); //NOI18N
73                 } else if (null == targetProduct) {
74                         // Throw NPE
75                         throw new NullPointerException("targetProduct is null"); //NOI18N
76                 }
77
78                 // Copy all:
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());
93         }
94
95         /**
96          * Utility classes should have no instances
97          */
98         private Products () {
99                 // Private constructor
100         }
101
102 }