]> 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          * Utility classes should have no instances
62          */
63         private Products () {
64                 // Private constructor
65         }
66
67 }