]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarters.java
Updated jar(s)
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / model / headquarter / Headquarters.java
1 /*
2  * Copyright (C) 2017, 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.jcontactsbusiness.model.headquarter;
18
19 import java.io.Serializable;
20 import java.util.Objects;
21
22 /**
23  * An utilities class for headquarter
24  *
25  * @author Roland Häder<roland@mxchange.org>
26  */
27 public class Headquarters implements Serializable {
28
29         /**
30          * Serial number
31          */
32         private static final long serialVersionUID = 69_537_867_224_651L;
33
34         /**
35          * Compare null-reference-safe 2 headquarter instances with each other.
36          * <p>
37          * @param headquarter1 Headquarter 1
38          * @param headquarter2 Headquarter 2
39          * <p>
40          * @return Comparison value from invoking Comparable.compareTo()
41          */
42         public static int compare (final Headquarter headquarter1, final Headquarter headquarter2) {
43                 // Compare both
44                 if (Objects.equals(headquarter1, headquarter2)) {
45                         // Same headquarters
46                         return 0;
47                 } else if (null == headquarter1) {
48                         // First is null
49                         return -1;
50                 } else if (null == headquarter2) {
51                         // Second headquarter is null
52                         return 1;
53                 }
54
55                 // Now that both are not NULL, compare them
56                 return headquarter1.compareTo(headquarter2);
57         }
58
59         /**
60          * Checks if both headquarter have same address. This method will throw an
61          * {@code NullPointerException} if one of the instances is null.
62          * <p>
63          * @param headquarter1 Headquarter 1
64          * @param headquarter2 Headquarter 2
65          * <p>
66          * @return Whether both branch office addresses are the same
67          * <p>
68          * @throws NullPointerException If one of the instances is null
69          */
70         public static boolean isSameAddress (final Headquarter headquarter1, final Headquarter headquarter2) {
71                 // Check that both parameters are not null
72                 if (null == headquarter1) {
73                         // Throw NPE
74                         throw new NullPointerException("headquarter1 is null"); //NOI18N
75                 } else if (null == headquarter2) {
76                         // Throw NPE
77                         throw new NullPointerException("headquarter2 is null"); //NOI18N
78                 }
79
80                 // Default is the same
81                 boolean isSameAddress = true;
82
83                 // Compare both addresses
84                 if (!Objects.equals(headquarter1.getHeadquarterCompanyName(), headquarter2.getHeadquarterCompanyName())) {
85                         // Not the same
86                         isSameAddress = false;
87                 } else if (!Objects.equals(headquarter1.getHeadquarterCountry(), headquarter2.getHeadquarterCountry())) {
88                         // Not the same
89                         isSameAddress = false;
90                 } else if (!Objects.equals(headquarter1.getHeadquarterCity(), headquarter2.getHeadquarterCity())) {
91                         // Not the same
92                         isSameAddress = false;
93                 } else if (!Objects.equals(headquarter1.getHeadquarterZipCode(), headquarter2.getHeadquarterZipCode())) {
94                         // Not the same
95                         isSameAddress = false;
96                 } else if (!Objects.equals(headquarter1.getHeadquarterStreet(), headquarter2.getHeadquarterStreet())) {
97                         // Not the same
98                         isSameAddress = false;
99                 } else if (!Objects.equals(headquarter1.getHeadquarterHouseNumber(), headquarter2.getHeadquarterHouseNumber())) {
100                         // Not the same
101                         isSameAddress = false;
102                 } else if (!Objects.equals(headquarter1.getHeadquarterHouseNumberExtension(), headquarter2.getHeadquarterHouseNumberExtension())) {
103                         // Not the same
104                         isSameAddress = false;
105                 } else if (!Objects.equals(headquarter1.getHeadquarterStore(), headquarter2.getHeadquarterStore())) {
106                         // Not the same
107                         isSameAddress = false;
108                 } else if (!Objects.equals(headquarter1.getHeadquarterSuiteNumber(), headquarter2.getHeadquarterSuiteNumber())) {
109                         // Not the same
110                         isSameAddress = false;
111                 }
112
113                 // Return flag
114                 return isSameAddress;
115         }
116
117         /**
118          * Private default constructor
119          */
120         private Headquarters () {
121                 // Utilities don't have instances
122         }
123
124 }