]> git.mxchange.org Git - jcontacts-business-core.git/blob - src/org/mxchange/jcontactsbusiness/model/department/Departments.java
Continued:
[jcontacts-business-core.git] / src / org / mxchange / jcontactsbusiness / model / department / Departments.java
1 /*
2  * Copyright (C) 2017 Roland Häder
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.department;
18
19 import java.io.Serializable;
20 import java.util.Objects;
21
22 /**
23  * Utilities class for departments
24  * <p>
25  * @author Roland Häder<roland@mxchange.org>
26  */
27 public class Departments implements Serializable {
28
29         /**
30          * Serial number
31          */
32         private static final long serialVersionUID = 20_154_686_786_561L;
33
34         /**
35          * Checks if both departments are the same (entity) or if at least basic
36          * company data and department name are matching.
37          * <p>
38          * @param department1 Department 1
39          * @param department2 Department 2
40          * <p>
41          * @return Whether both are the same
42          */
43         public static boolean isSameDepartment (final Department department1, final Department department2) {
44                 // Now check it
45                 if (null == department1) {
46                         // Throw NPE
47                         throw new NullPointerException("department1 is null"); //NOI18N
48                 } else if (null == department2) {
49                         // Throw it again
50                         throw new NullPointerException("department2 is null"); //NOI18N
51                 } else if (Objects.equals(department1, department2)) {
52                         // Same department
53                         return true;
54                 } else if (department1.getDepartmentCompany() == null) {
55                         // Throw NPE again
56                         throw new NullPointerException("department1.departmentCompany is null"); //NOI18N
57                 } else if (department1.getDepartmentName() == null) {
58                         // Throw it again
59                         throw new NullPointerException("department1.departmentName is null"); //NOI18N
60                 } else if (department1.getDepartmentName().isEmpty()) {
61                         // Throw IAE
62                         throw new IllegalArgumentException("department1.departmentName is empty"); //NOI18N
63                 } else if (department2.getDepartmentCompany() == null) {
64                         // Throw NPE again
65                         throw new NullPointerException("department2.departmentCompany is null"); //NOI18N
66                 } else if (department2.getDepartmentName() == null) {
67                         // Throw it again
68                         throw new NullPointerException("department2.departmentName is null"); //NOI18N
69                 } else if (department2.getDepartmentName().isEmpty()) {
70                         // Throw IAE
71                         throw new IllegalArgumentException("department2.departmentName is empty"); //NOI18N
72                 }
73
74                 // Same company and same name?
75                 boolean isSame = ((Objects.equals(department1.getDepartmentCompany(), department2.getDepartmentCompany())) &&
76                                                   (Objects.equals(department1.getDepartmentName(), department2.getDepartmentName())));
77
78                 // Return it
79                 return isSame;
80         }
81
82         /**
83          * Private default constructor
84          */
85         private Departments () {
86                 // Prevent instances from utilities classes
87         }
88
89 }