]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffices.java
Updated copyright year
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / model / branchoffice / BranchOffices.java
1
2 /*
3  * Copyright (C) 2017, 2020 Free Software Foundation
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.mxchange.jcontactsbusiness.model.branchoffice;
19
20 import java.io.Serializable;
21 import java.util.Objects;
22
23 /**
24  * An utilities class for branch offices
25  *
26  * @author Roland Häder<roland@mxchange.org>
27  */
28 public class BranchOffices implements Serializable {
29
30         /**
31          * Serial number
32          */
33         private static final long serialVersionUID = 69_537_867_224_651L;
34
35         /**
36          * Compares both branch office instances. This method returns -1 if second
37          * instance is null.
38          * <p>
39          * @param branchOffice1 Branch office instance 1
40          * @param branchOffice2 Branch office instance 2
41          * <p>
42          * @return Comparison value
43          */
44         public static int compare (final BranchOffice branchOffice1, final BranchOffice branchOffice2) {
45                 // Check euqality, then at least first must be given
46                 if (Objects.equals(branchOffice1, branchOffice2)) {
47                         // Both are same
48                         return 0;
49                 } else if (null == branchOffice1) {
50                         // First is null
51                         return -1;
52                 } else if (null == branchOffice2) {
53                         // Second is null
54                         return 1;
55                 }
56
57                 // Invoke compareTo() method
58                 return branchOffice1.compareTo(branchOffice2);
59         }
60
61         /**
62          * Checks if both branch offices have same address. This method will throw
63          * an {@code NullPointerException} if one of the instances is null.
64          * <p>
65          * @param branchOffice1 Branch office 1
66          * @param branchOffice2 Branch office 2
67          * <p>
68          * @return Whether both branch office addresses are the same
69          * <p>
70          * @throws NullPointerException If one of the instances is null
71          */
72         public static boolean isSameAddress (final BranchOffice branchOffice1, final BranchOffice branchOffice2) {
73                 // Check that both parameters are not null
74                 if (null == branchOffice1) {
75                         // Throw NPE
76                         throw new NullPointerException("branchOffice1 is null"); //NOI18N
77                 } else if (null == branchOffice2) {
78                         // Throw NPE
79                         throw new NullPointerException("branchOffice2 is null"); //NOI18N
80                 }
81
82                 // Default is the same
83                 boolean isSameAddress = true;
84
85                 // Compare both addresses
86                 if (!Objects.equals(branchOffice1.getBranchCompany(), branchOffice2.getBranchCompany())) {
87                         // Not the same
88                         isSameAddress = false;
89                 } else if (!Objects.equals(branchOffice1.getBranchCountry(), branchOffice2.getBranchCountry())) {
90                         // Not the same
91                         isSameAddress = false;
92                 } else if (!Objects.equals(branchOffice1.getBranchCity(), branchOffice2.getBranchCity())) {
93                         // Not the same
94                         isSameAddress = false;
95                 } else if (!Objects.equals(branchOffice1.getBranchZipCode(), branchOffice2.getBranchZipCode())) {
96                         // Not the same
97                         isSameAddress = false;
98                 } else if (!Objects.equals(branchOffice1.getBranchStreet(), branchOffice2.getBranchStreet())) {
99                         // Not the same
100                         isSameAddress = false;
101                 } else if (!Objects.equals(branchOffice1.getBranchHouseNumber(), branchOffice2.getBranchHouseNumber())) {
102                         // Not the same
103                         isSameAddress = false;
104                 } else if (!Objects.equals(branchOffice1.getBranchHouseNumberExtension(), branchOffice2.getBranchHouseNumberExtension())) {
105                         // Not the same
106                         isSameAddress = false;
107                 } else if (!Objects.equals(branchOffice1.getBranchStore(), branchOffice2.getBranchStore())) {
108                         // Not the same
109                         isSameAddress = false;
110                 } else if (!Objects.equals(branchOffice1.getBranchSuiteNumber(), branchOffice2.getBranchSuiteNumber())) {
111                         // Not the same
112                         isSameAddress = false;
113                 }
114
115                 // Return flag
116                 return isSameAddress;
117         }
118
119         /**
120          * Private default constructor
121          */
122         private BranchOffices () {
123                 // Utilities don't have instances
124         }
125
126 }