2 * Copyright (C) 2017, 2018 Free Software Foundation
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.
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.
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/>.
17 package org.mxchange.jcontactsbusiness.model.department;
19 import java.io.Serializable;
20 import java.text.MessageFormat;
21 import java.util.Objects;
22 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
23 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
26 * Utilities class for departments
28 * @author Roland Häder<roland@mxchange.org>
30 public class Departments implements Serializable {
35 private static final long serialVersionUID = 20_154_686_786_561L;
38 * Compares both department instances. This method returns -1 if second
41 * @param department1 Department instance 1
42 * @param department2 Department instance 2
44 * @return Comparison value
46 public static int compare (final Department department1, final Department department2) {
47 // Check euqality, then at least first must be given
48 if (Objects.equals(department1, department2)) {
51 } else if (null == department1) {
54 } else if (null == department2) {
59 // Invoke compareTo() method
60 return department1.compareTo(department2);
64 * Checks if both departments are the same (entity) or if at least basic
65 * company data and department name are matching.
67 * @param department1 Department 1
68 * @param department2 Department 2
70 * @return Whether both are the same
72 public static boolean isSameDepartment (final Department department1, final Department department2) {
74 if (null == department1) {
76 throw new NullPointerException("department1 is null"); //NOI18N
77 } else if (null == department2) {
79 throw new NullPointerException("department2 is null"); //NOI18N
80 } else if (Objects.equals(department1, department2)) {
83 } else if (department1.getDepartmentCompany() == null) {
85 throw new NullPointerException("department1.departmentCompany is null"); //NOI18N
86 } else if (department1.getDepartmentCompany().getBasicDataId() == null) {
88 throw new NullPointerException("department1.departmentCompany.basicDataId is null"); //NOI18N
89 } else if (department1.getDepartmentCompany().getBasicDataId() < 1) {
91 throw new NullPointerException(MessageFormat.format("department1.departmentCompany.basicDataId={0} is valid.", department1.getDepartmentCompany().getBasicDataId())); //NOI18N
92 } else if (department1.getDepartmentI18nKey() == null) {
94 throw new NullPointerException("department1.departmentName is null"); //NOI18N
95 } else if (department1.getDepartmentI18nKey().isEmpty()) {
97 throw new IllegalArgumentException("department1.departmentName is empty"); //NOI18N
98 } else if (department2.getDepartmentCompany() == null) {
100 throw new NullPointerException("department2.departmentCompany is null"); //NOI18N
101 } else if (department2.getDepartmentCompany().getBasicDataId() == null) {
103 throw new NullPointerException("department2.departmentCompany.basicDataId is null"); //NOI18N
104 } else if (department2.getDepartmentCompany().getBasicDataId() < 1) {
106 throw new NullPointerException(MessageFormat.format("department2.departmentCompany.basicDataId={0} is valid.", department2.getDepartmentCompany().getBasicDataId())); //NOI18N
107 } else if (department2.getDepartmentI18nKey() == null) {
109 throw new NullPointerException("department2.departmentName is null"); //NOI18N
110 } else if (department2.getDepartmentI18nKey().isEmpty()) {
112 throw new IllegalArgumentException("department2.departmentName is empty"); //NOI18N
115 // Same company and same name?
116 boolean isSame = ((Objects.equals(department1.getDepartmentCompany(), department2.getDepartmentCompany())) &&
117 (((department1.getDepartmentBranchOffice() instanceof BranchOffice) &&
118 (Objects.equals(department1.getDepartmentBranchOffice(), department2.getDepartmentBranchOffice()))) ||
119 ((department1.getDepartmentHeadquarter() instanceof Headquarter) &&
120 (Objects.equals(department1.getDepartmentHeadquarter(), department2.getDepartmentHeadquarter())))) &&
121 (Objects.equals(department1.getDepartmentI18nKey(), department2.getDepartmentI18nKey())));
128 * Private default constructor
130 private Departments () {
131 // Prevent instances from utilities classes