From: Roland Häder Date: Thu, 6 Oct 2022 13:26:26 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=42d68ff56df219eeb5e22c4c5a8c2f878316a114;p=jcontacts-business-core.git Continued: - renamed all *s utility classes to *Utils - moved them to own package (for all the same package) --- diff --git a/src/org/mxchange/jcontactsbusiness/model/basicdata/BasicDataUtils.java b/src/org/mxchange/jcontactsbusiness/model/basicdata/BasicDataUtils.java deleted file mode 100644 index e7f5126..0000000 --- a/src/org/mxchange/jcontactsbusiness/model/basicdata/BasicDataUtils.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2022 Free Software Foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontactsbusiness.model.basicdata; - -import java.io.Serializable; -import java.util.Objects; - -/** - * An utilities class for basic company data - *

- * @author Roland Häder - */ -public class BasicDataUtils implements Serializable { - - /** - * Serial number - */ - private static final long serialVersionUID = 159_847_673_672_091L; - - /** - * Compares both basic company data instances. This method returns -1 if - * second instance is null. - *

- * @param basicData1 Basic company data instance 1 - * @param basicData2 Basic company data instance 2 - *

- * @return Comparison value - */ - public static int compare (final BasicData basicData1, final BasicData basicData2) { - // Check equality, then at least first must be given - if (Objects.equals(basicData1, basicData2)) { - // Both are same - return 0; - } else if (null == basicData1) { - // First is null - return -1; - } else if (null == basicData2) { - // Second is null - return 1; - } - - // Invoke compareTo() method - return basicData1.compareTo(basicData2); - } - - /** - * Utility classes should not have instances - */ - private BasicDataUtils () { - // Private constructor - } - -} diff --git a/src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java b/src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java index 80d60e5..dbd25c5 100644 --- a/src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java +++ b/src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java @@ -41,9 +41,9 @@ import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee; import org.mxchange.jcontactsbusiness.model.employee.Employable; import org.mxchange.jcontactsbusiness.model.headquarter.BusinessHeadquarter; import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; -import org.mxchange.jcontactsbusiness.model.headquarter.Headquarters; import org.mxchange.jcontactsbusiness.model.logo.BusinessLogo; import org.mxchange.jcontactsbusiness.model.logo.Logo; +import org.mxchange.jcontactsbusiness.model.utils.HeadquarterUtils; import org.mxchange.jcoreutils.Comparables; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber; @@ -233,7 +233,7 @@ public class BusinessBasicData implements BasicData { // Init comparators final int comparators[] = { // First compare company short name - this.getCompanyShortName().compareToIgnoreCase(basicData.getCompanyShortName()), + StringUtils.compareIgnoreCase(this.getCompanyShortName(), basicData.getCompanyShortName()), // ... 2nd compare company name StringUtils.compareIgnoreCase(this.getCompanyName(), basicData.getCompanyName()), // ... next tax number @@ -241,7 +241,7 @@ public class BusinessBasicData implements BasicData { // ... and email address StringUtils.compareIgnoreCase(this.getCompanyEmailAddress(), basicData.getCompanyEmailAddress()), // ... head quarter data - Headquarters.compare(this.getCompanyHeadquarterData(), basicData.getCompanyHeadquarterData()) + HeadquarterUtils.compare(this.getCompanyHeadquarterData(), basicData.getCompanyHeadquarterData()) }; // Check all values diff --git a/src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffices.java b/src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffices.java deleted file mode 100644 index 1f08653..0000000 --- a/src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffices.java +++ /dev/null @@ -1,167 +0,0 @@ - -/* - * Copyright (C) 2017 - 2022 Free Software Foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontactsbusiness.model.branchoffice; - -import java.io.Serializable; -import java.util.Objects; - -/** - * An utilities class for branch offices - * - * @author Roland Häder - */ -public class BranchOffices implements Serializable { - - /** - * Serial number - */ - private static final long serialVersionUID = 69_537_867_224_651L; - - /** - * Compares both branch office instances. This method returns -1 if second - * instance is null. - *

- * @param branchOffice1 Branch office instance 1 - * @param branchOffice2 Branch office instance 2 - *

- * @return Comparison value - */ - public static int compare (final BranchOffice branchOffice1, final BranchOffice branchOffice2) { - // Check equality, then at least first must be given - if (Objects.equals(branchOffice1, branchOffice2)) { - // Both are same - return 0; - } else if (null == branchOffice1) { - // First is null - return -1; - } else if (null == branchOffice2) { - // Second is null - return 1; - } - - // Invoke compareTo() method - return branchOffice1.compareTo(branchOffice2); - } - - /** - * Copies all fields from source to target branch office instance - *

- * @param sourceBranchOffice Source BranchOffice instance - * @param targetBranchOffice Target BranchOffice instance - */ - public static void copyBranchOfficeData (final BranchOffice sourceBranchOffice, final BranchOffice targetBranchOffice) { - // Check that both parameters are not null - if (null == sourceBranchOffice) { - // Throw NPE - throw new NullPointerException("sourceBranchOffice is null"); //NOI18N - } else if (null == targetBranchOffice) { - // Throw NPE - throw new NullPointerException("targetBranchOffice is null"); //NOI18N - } else if (Objects.equals(sourceBranchOffice, targetBranchOffice)) { - // Throw IAE - throw new IllegalArgumentException("sourceBranchOffice and targetBranchOffice are the same"); //NOI18N - } - - // Copy all fields - targetBranchOffice.setBranchCity(sourceBranchOffice.getBranchCity()); - targetBranchOffice.setBranchCompany(sourceBranchOffice.getBranchCompany()); - targetBranchOffice.setBranchContactEmployee(sourceBranchOffice.getBranchContactEmployee()); - targetBranchOffice.setBranchCountry(sourceBranchOffice.getBranchCountry()); - targetBranchOffice.setBranchEmailAddress(sourceBranchOffice.getBranchEmailAddress()); - targetBranchOffice.setBranchFaxNumber(sourceBranchOffice.getBranchFaxNumber()); - targetBranchOffice.setBranchHouseNumber(sourceBranchOffice.getBranchHouseNumber()); - targetBranchOffice.setBranchHouseNumberExtension(sourceBranchOffice.getBranchHouseNumberExtension()); - targetBranchOffice.setBranchId(sourceBranchOffice.getBranchId()); - targetBranchOffice.setBranchLandLineNumber(sourceBranchOffice.getBranchLandLineNumber()); - targetBranchOffice.setBranchLastHouseNumber(sourceBranchOffice.getBranchLastHouseNumber()); - targetBranchOffice.setBranchNumber(sourceBranchOffice.getBranchNumber()); - targetBranchOffice.setBranchOpeningTimes(sourceBranchOffice.getBranchOpeningTimes()); - targetBranchOffice.setBranchOwnerEmployee(sourceBranchOffice.getBranchOwnerEmployee()); - targetBranchOffice.setBranchStore(sourceBranchOffice.getBranchStore()); - targetBranchOffice.setBranchStreet(sourceBranchOffice.getBranchStreet()); - targetBranchOffice.setBranchSuiteNumber(sourceBranchOffice.getBranchSuiteNumber()); - targetBranchOffice.setBranchUserOwner(sourceBranchOffice.getBranchUserOwner()); - targetBranchOffice.setBranchZipCode(sourceBranchOffice.getBranchZipCode()); - } - - /** - * Checks if both branch offices have same address. This method will throw - * an {@code NullPointerException} if one of the instances is null. - *

- * @param branchOffice1 Branch office 1 - * @param branchOffice2 Branch office 2 - *

- * @return Whether both branch office addresses are the same - *

- * @throws NullPointerException If one of the instances is null - */ - public static boolean isSameAddress (final BranchOffice branchOffice1, final BranchOffice branchOffice2) { - // Check that both parameters are not null - if (null == branchOffice1) { - // Throw NPE - throw new NullPointerException("branchOffice1 is null"); //NOI18N - } else if (null == branchOffice2) { - // Throw NPE - throw new NullPointerException("branchOffice2 is null"); //NOI18N - } - - // Default is the same - boolean isSameAddress = true; - - // Compare both addresses - if (!Objects.equals(branchOffice1.getBranchCompany(), branchOffice2.getBranchCompany())) { - // Not the same - isSameAddress = false; - } else if (!Objects.equals(branchOffice1.getBranchCountry(), branchOffice2.getBranchCountry())) { - // Not the same - isSameAddress = false; - } else if (!Objects.equals(branchOffice1.getBranchCity(), branchOffice2.getBranchCity())) { - // Not the same - isSameAddress = false; - } else if (!Objects.equals(branchOffice1.getBranchZipCode(), branchOffice2.getBranchZipCode())) { - // Not the same - isSameAddress = false; - } else if (!Objects.equals(branchOffice1.getBranchStreet(), branchOffice2.getBranchStreet())) { - // Not the same - isSameAddress = false; - } else if (!Objects.equals(branchOffice1.getBranchHouseNumber(), branchOffice2.getBranchHouseNumber())) { - // Not the same - isSameAddress = false; - } else if (!Objects.equals(branchOffice1.getBranchHouseNumberExtension(), branchOffice2.getBranchHouseNumberExtension())) { - // Not the same - isSameAddress = false; - } else if (!Objects.equals(branchOffice1.getBranchStore(), branchOffice2.getBranchStore())) { - // Not the same - isSameAddress = false; - } else if (!Objects.equals(branchOffice1.getBranchSuiteNumber(), branchOffice2.getBranchSuiteNumber())) { - // Not the same - isSameAddress = false; - } - - // Return flag - return isSameAddress; - } - - /** - * Private default constructor - */ - private BranchOffices () { - // Utilities don't have instances - } - -} diff --git a/src/org/mxchange/jcontactsbusiness/model/branchoffice/BusinessBranchOffice.java b/src/org/mxchange/jcontactsbusiness/model/branchoffice/BusinessBranchOffice.java index ff41be2..66f9200 100644 --- a/src/org/mxchange/jcontactsbusiness/model/branchoffice/BusinessBranchOffice.java +++ b/src/org/mxchange/jcontactsbusiness/model/branchoffice/BusinessBranchOffice.java @@ -40,8 +40,8 @@ import javax.persistence.TemporalType; import javax.persistence.Transient; import org.apache.commons.lang3.StringUtils; import org.mxchange.jcontacts.model.contact.Contact; -import org.mxchange.jcontacts.model.contact.Contacts; import org.mxchange.jcontacts.model.contact.UserContact; +import org.mxchange.jcontacts.model.utils.ContactUtils; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime; @@ -324,14 +324,15 @@ public class BusinessBranchOffice implements BranchOffice { // Init comparisons final int[] comparators = { + // First compare basic data // First compare basic data this.getBranchCompany().compareTo(branchOffice.getBranchCompany()), // ... branch office number SafeNumberUtils.compare(this.getBranchNumber(), branchOffice.getBranchNumber()), // ... owner employee - Contacts.compare(this.getBranchOwnerEmployee(), branchOffice.getBranchOwnerEmployee()), + ContactUtils.compare(this.getBranchOwnerEmployee(), branchOffice.getBranchOwnerEmployee()), // ... contact person - Contacts.compare(this.getBranchContactEmployee(), branchOffice.getBranchContactEmployee()), + ContactUtils.compare(this.getBranchContactEmployee(), branchOffice.getBranchContactEmployee()), // ... then country this.getBranchCountry().compareTo(branchOffice.getBranchCountry()), // ... next city diff --git a/src/org/mxchange/jcontactsbusiness/model/department/BusinessDepartment.java b/src/org/mxchange/jcontactsbusiness/model/department/BusinessDepartment.java index 1bd6df7..757ed77 100644 --- a/src/org/mxchange/jcontactsbusiness/model/department/BusinessDepartment.java +++ b/src/org/mxchange/jcontactsbusiness/model/department/BusinessDepartment.java @@ -34,19 +34,23 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; +import org.apache.commons.lang3.StringUtils; import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcontacts.model.contact.UserContact; +import org.mxchange.jcontacts.model.utils.ContactUtils; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; -import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffices; import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice; import org.mxchange.jcontactsbusiness.model.headquarter.BusinessHeadquarter; import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; -import org.mxchange.jcontactsbusiness.model.headquarter.Headquarters; +import org.mxchange.jcontactsbusiness.model.utils.BasicDataUtils; +import org.mxchange.jcontactsbusiness.model.utils.BranchOfficeUtils; +import org.mxchange.jcontactsbusiness.model.utils.HeadquarterUtils; import org.mxchange.jcoreutils.Comparables; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; +import org.mxchange.jusercore.model.user.Users; /** * A POJO for company departments @@ -181,13 +185,17 @@ public class BusinessDepartment implements Department { // Init comparisons final int[] comparators = { // First department's company (BasicData) ... - this.getDepartmentCompany().compareTo(department.getDepartmentCompany()), + BasicDataUtils.compare(this.getDepartmentCompany(), department.getDepartmentCompany()), // ... then headquarters - Headquarters.compare(this.getDepartmentHeadquarter(), department.getDepartmentHeadquarter()), + HeadquarterUtils.compare(this.getDepartmentHeadquarter(), department.getDepartmentHeadquarter()), // ... branch office - BranchOffices.compare(this.getDepartmentBranchOffice(), department.getDepartmentBranchOffice()), - // ... finally department's i18n key - this.getDepartmentI18nKey().compareTo(department.getDepartmentI18nKey()) + BranchOfficeUtils.compare(this.getDepartmentBranchOffice(), department.getDepartmentBranchOffice()), + // ... department's i18n key + StringUtils.compare(this.getDepartmentI18nKey(), department.getDepartmentI18nKey()), + // ... lead contact + ContactUtils.compare(this.getDepartmentLead(), department.getDepartmentLead()), + // ... user owner + Users.compare(this.getDepartmentUserOwner(), department.getDepartmentUserOwner()) }; // Check all values diff --git a/src/org/mxchange/jcontactsbusiness/model/department/Departments.java b/src/org/mxchange/jcontactsbusiness/model/department/Departments.java deleted file mode 100644 index e4d0c32..0000000 --- a/src/org/mxchange/jcontactsbusiness/model/department/Departments.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (C) 2017 - 2022 Free Software Foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontactsbusiness.model.department; - -import java.io.Serializable; -import java.text.MessageFormat; -import java.util.Objects; -import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; -import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; - -/** - * Utilities class for departments - *

- * @author Roland Häder - */ -public class Departments implements Serializable { - - /** - * Serial number - */ - private static final long serialVersionUID = 20_154_686_786_561L; - - /** - * Compares both department instances. This method returns -1 if second - * instance is null. - *

- * @param department1 Department instance 1 - * @param department2 Department instance 2 - *

- * @return Comparison value - */ - public static int compare (final Department department1, final Department department2) { - // Check equality, then at least first must be given - if (Objects.equals(department1, department2)) { - // Both are same - return 0; - } else if (null == department1) { - // First is null - return -1; - } else if (null == department2) { - // Second is null - return 1; - } - - // Invoke compareTo() method - return department1.compareTo(department2); - } - - /** - * Copies all data from source department to target department. - *

- * @param sourceDepartment Source department - * @param targetDepartment Target department - */ - public static void copyDepartmentData (final Department sourceDepartment, final Department targetDepartment) { - // Check that both parameters are not null - if (null == sourceDepartment) { - // Throw NPE - throw new NullPointerException("sourceDepartment is null"); //NOI18N - } else if (null == targetDepartment) { - // Throw NPE - throw new NullPointerException("targetDepartment is null"); //NOI18N - } else if (Objects.equals(sourceDepartment, targetDepartment)) { - // Throw IAE - throw new IllegalArgumentException("sourceDepartment and targetDepartment are the same"); //NOI18N - } - - // Copy all fields - targetDepartment.setDepartmentBranchOffice(sourceDepartment.getDepartmentBranchOffice()); - targetDepartment.setDepartmentCompany(sourceDepartment.getDepartmentCompany()); - targetDepartment.setDepartmentHeadquarter(sourceDepartment.getDepartmentHeadquarter()); - targetDepartment.setDepartmentI18nKey(sourceDepartment.getDepartmentI18nKey()); - targetDepartment.setDepartmentId(sourceDepartment.getDepartmentId()); - targetDepartment.setDepartmentLead(sourceDepartment.getDepartmentLead()); - targetDepartment.setDepartmentUserOwner(sourceDepartment.getDepartmentUserOwner()); - } - - /** - * Checks if both departments are the same (entity) or if at least basic - * company data and department name are matching. - *

- * @param department1 Department 1 - * @param department2 Department 2 - *

- * @return Whether both are the same - */ - public static boolean isSameDepartment (final Department department1, final Department department2) { - // Now check it - if (null == department1) { - // Throw NPE - throw new NullPointerException("department1 is null"); //NOI18N - } else if (null == department2) { - // Throw it again - throw new NullPointerException("department2 is null"); //NOI18N - } else if (Objects.equals(department1, department2)) { - // Same department - return true; - } else if (department1.getDepartmentCompany() == null) { - // Throw NPE again - throw new NullPointerException("department1.departmentCompany is null"); //NOI18N - } else if (department1.getDepartmentCompany().getBasicDataId() == null) { - // Throw NPE again - throw new NullPointerException("department1.departmentCompany.basicDataId is null"); //NOI18N - } else if (department1.getDepartmentCompany().getBasicDataId() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("department1.departmentCompany.basicDataId={0} is valid.", department1.getDepartmentCompany().getBasicDataId())); //NOI18N - } else if (department1.getDepartmentI18nKey() == null) { - // Throw it again - throw new NullPointerException("department1.departmentName is null"); //NOI18N - } else if (department1.getDepartmentI18nKey().isEmpty()) { - // Throw IAE - throw new IllegalArgumentException("department1.departmentName is empty"); //NOI18N - } else if (department2.getDepartmentCompany() == null) { - // Throw NPE again - throw new NullPointerException("department2.departmentCompany is null"); //NOI18N - } else if (department2.getDepartmentCompany().getBasicDataId() == null) { - // Throw NPE again - throw new NullPointerException("department2.departmentCompany.basicDataId is null"); //NOI18N - } else if (department2.getDepartmentCompany().getBasicDataId() < 1) { - // Throw NPE again - throw new NullPointerException(MessageFormat.format("department2.departmentCompany.basicDataId={0} is valid.", department2.getDepartmentCompany().getBasicDataId())); //NOI18N - } else if (department2.getDepartmentI18nKey() == null) { - // Throw it again - throw new NullPointerException("department2.departmentName is null"); //NOI18N - } else if (department2.getDepartmentI18nKey().isEmpty()) { - // Throw IAE - throw new IllegalArgumentException("department2.departmentName is empty"); //NOI18N - } - - // Same company and same name? - boolean isSame = ((Objects.equals(department1.getDepartmentCompany(), department2.getDepartmentCompany())) && - (((department1.getDepartmentBranchOffice() instanceof BranchOffice) && - (Objects.equals(department1.getDepartmentBranchOffice(), department2.getDepartmentBranchOffice()))) || - ((department1.getDepartmentHeadquarter() instanceof Headquarter) && - (Objects.equals(department1.getDepartmentHeadquarter(), department2.getDepartmentHeadquarter())))) && - (Objects.equals(department1.getDepartmentI18nKey(), department2.getDepartmentI18nKey()))); - - // Return it - return isSame; - } - - /** - * Private default constructor - */ - private Departments () { - // Prevent instances from utilities classes - } - -} diff --git a/src/org/mxchange/jcontactsbusiness/model/employee/BusinessEmployee.java b/src/org/mxchange/jcontactsbusiness/model/employee/BusinessEmployee.java index 7e5a5e2..b2c8054 100644 --- a/src/org/mxchange/jcontactsbusiness/model/employee/BusinessEmployee.java +++ b/src/org/mxchange/jcontactsbusiness/model/employee/BusinessEmployee.java @@ -35,22 +35,23 @@ import javax.persistence.TemporalType; import javax.persistence.Transient; import org.apache.commons.lang3.StringUtils; import org.mxchange.jcontacts.model.contact.Contact; -import org.mxchange.jcontacts.model.contact.Contacts; import org.mxchange.jcontacts.model.contact.UserContact; +import org.mxchange.jcontacts.model.utils.ContactUtils; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; -import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffices; import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice; import org.mxchange.jcontactsbusiness.model.department.BusinessDepartment; import org.mxchange.jcontactsbusiness.model.department.Department; -import org.mxchange.jcontactsbusiness.model.department.Departments; import org.mxchange.jcontactsbusiness.model.headquarter.BusinessHeadquarter; import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; -import org.mxchange.jcontactsbusiness.model.headquarter.Headquarters; import org.mxchange.jcontactsbusiness.model.jobposition.EmployeePosition; import org.mxchange.jcontactsbusiness.model.jobposition.HireableJobPosition; -import org.mxchange.jcontactsbusiness.model.jobposition.JobPositions; +import org.mxchange.jcontactsbusiness.model.utils.JobPositionUtils; +import org.mxchange.jcontactsbusiness.model.utils.BasicDataUtils; +import org.mxchange.jcontactsbusiness.model.utils.BranchOfficeUtils; +import org.mxchange.jcontactsbusiness.model.utils.DepartmentUtils; +import org.mxchange.jcontactsbusiness.model.utils.HeadquarterUtils; import org.mxchange.jcoreutils.Comparables; import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber; @@ -220,21 +221,23 @@ public class BusinessEmployee implements Employable { // Init comparisons final int[] comparators = { + // First employee's number // First employee's number StringUtils.compareIgnoreCase(this.getEmployeeNumber(), employable.getEmployeeNumber()), // ... finally contact data - Contacts.compare(this.getEmployeePersonalData(), employable.getEmployeePersonalData()), + ContactUtils.compare(this.getEmployeePersonalData(), employable.getEmployeePersonalData()), // ... employee's email address StringUtils.compareIgnoreCase(this.getEmployeeEmailAddress(), employable.getEmployeeEmailAddress()), // ... company data (BasicData) - this.getEmployeeBasicData().compareTo(employable.getEmployeeBasicData()), - JobPositions.compare(this.getEmployeeJobPosition(), employable.getEmployeeJobPosition()), + BasicDataUtils.compare(this.getEmployeeBasicData(), employable.getEmployeeBasicData()), + // ... job position +JobPositionUtils.compare(this.getEmployeeJobPosition(), employable.getEmployeeJobPosition()), // ... department - Departments.compare(this.getEmployeeDepartment(), employable.getEmployeeDepartment()), + DepartmentUtils.compare(this.getEmployeeDepartment(), employable.getEmployeeDepartment()), // ... branch office - BranchOffices.compare(this.getEmployeeBranchOffice(), employable.getEmployeeBranchOffice()), + BranchOfficeUtils.compare(this.getEmployeeBranchOffice(), employable.getEmployeeBranchOffice()), // ... next headquarters - Headquarters.compare(this.getEmployeeHeadquarter(), employable.getEmployeeHeadquarter()),}; + HeadquarterUtils.compare(this.getEmployeeHeadquarter(), employable.getEmployeeHeadquarter()),}; // Check all values final int comparison = Comparables.checkAll(comparators); diff --git a/src/org/mxchange/jcontactsbusiness/model/employee/Employees.java b/src/org/mxchange/jcontactsbusiness/model/employee/Employees.java deleted file mode 100644 index a5f20f3..0000000 --- a/src/org/mxchange/jcontactsbusiness/model/employee/Employees.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (C) 2017 - 2022 Free Software Foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontactsbusiness.model.employee; - -import java.io.Serializable; -import java.text.MessageFormat; -import java.util.Objects; - -/** - * Utilities class for employees - *

- * @author Roland Häder - */ -public class Employees implements Serializable { - - /** - * Serial number - */ - private static final long serialVersionUID = 158_376_461_255_901L; - - /** - * Compares both employee instances. This method returns -1 if second - * instance is null. - *

- * @param employable1 Employee instance 1 - * @param employable2 Employee instance 2 - *

- * @return Comparison value - */ - public static int compare (final Employable employable1, final Employable employable2) { - // Check equality, then at least first must be given - if (Objects.equals(employable1, employable2)) { - // Both are same - return 0; - } else if (null == employable1) { - // First is null - return -1; - } else if (null == employable2) { - // Second is null - return 1; - } - - // Invoke compareTo() method - return employable1.compareTo(employable2); - } - - /** - * Checks whether both employees are the same - *

- * @param employee1 Employee 1 - * @param employee2 Employee 2 - *

- * @return Whether both are the same - */ - public static boolean isSameEmployeeFound (final Employable employee1, final Employable employee2) { - // Validate parameter - if (null == employee1) { - // Throw NPE - throw new NullPointerException("employee1 is null"); //NOI18N - } else if (employee1.getEmployeeBasicData() == null) { - // Throw it again - throw new NullPointerException("employee1.employeeCompany is null"); //NOI18N - } else if (employee1.getEmployeeBasicData().getBasicDataId() == null) { - // Throw it again - throw new NullPointerException("employee1.employeeCompany.basicDataId is null"); //NOI18N - } else if (employee1.getEmployeeBasicData().getBasicDataId() < 1) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("employee1.employeeCompany.basicDataId={0} is invalid.", employee1.getEmployeeBasicData().getBasicDataId())); //NOI18N - } else if (employee1.getEmployeeBranchOffice() == null && employee1.getEmployeeDepartment() == null && employee1.getEmployeeHeadquarter() == null) { - // At least one must be set - throw new NullPointerException("employee1.employeeBranchOffice, employee1.employeeDepartment and employee1.employeeHeadquarter is null"); //NOI18N - } else if (employee1.getEmployeeBranchOffice() != null && employee1.getEmployeeBranchOffice().getBranchId() == null) { - // Throw NPE - throw new NullPointerException("employee1.employeeBranchOffice.branchId is null"); //NOI18N - } else if (employee1.getEmployeeBranchOffice() != null && employee1.getEmployeeBranchOffice().getBranchId() < 1) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("employee1.employeeBranchOffice.branchId={0} is invalid.", employee1.getEmployeeBranchOffice().getBranchId())); //NOI18N - } else if (employee1.getEmployeeDepartment() != null && employee1.getEmployeeDepartment().getDepartmentId() == null) { - // Throw NPE - throw new NullPointerException("employee1.employeeDepartment.departmentId is null"); //NOI18N - } else if (employee1.getEmployeeDepartment() != null && employee1.getEmployeeDepartment().getDepartmentId() < 1) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("employee1.employeeDepartment.departmentId={0} is invalid.", employee1.getEmployeeDepartment().getDepartmentId())); //NOI18N - } else if (employee1.getEmployeeHeadquarter() != null && employee1.getEmployeeHeadquarter().getHeadquarterId() == null) { - // Throw NPE - throw new NullPointerException("employee1.employeeHeadquarter.headquarterId is null"); //NOI18N - } else if (employee1.getEmployeeHeadquarter() != null && employee1.getEmployeeHeadquarter().getHeadquarterId() < 1) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("employee1.employeeHeadquarter.headquarterId={0} is invalid.", employee1.getEmployeeHeadquarter().getHeadquarterId())); //NOI18N - } else if ((employee1.getEmployeePersonalData() == null) && (employee1.getEmployeeBranchOffice() == null) && (employee1.getEmployeeHeadquarter() == null) && (employee1.getEmployeeNumber() == null)) { - // All are null - throw new NullPointerException("employee1.employeePersonalData, employee1.employeeBranchOffice, employee1.employeeHeadquarter and employee1.employeeNumber are null"); //NOI18N - } else if ((employee1.getEmployeePersonalData() != null) && (employee1.getEmployeePersonalData().getContactId() == null)) { - // Throw NPE - throw new NullPointerException("employee1.employeePersonalData.contactId is null"); //NOI18N - } else if ((employee1.getEmployeePersonalData() != null) && (employee1.getEmployeePersonalData().getContactId() < 1)) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("employee1.employeePersonalData.contactId={0} is invalid.", employee1.getEmployeePersonalData().getContactId())); //NOI18N - } else if ((employee1.getEmployeeNumber() != null) && (employee1.getEmployeeNumber().isEmpty())) { - // Throw it again - throw new IllegalArgumentException("employee1.employeeNumber is empty"); //NOI18N - } else if (null == employee2) { - // Throw NPE - throw new NullPointerException("employee2 is null"); //NOI18N - } else if (employee2.getEmployeeBasicData() == null) { - // Throw it again - throw new NullPointerException("employee2.employeeCompany is null"); //NOI18N - } else if (employee2.getEmployeeBasicData().getBasicDataId() == null) { - // Throw it again - throw new NullPointerException("employee2.employeeCompany.basicDataId is null"); //NOI18N - } else if (employee2.getEmployeeBasicData().getBasicDataId() < 1) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("employee2.employeeCompany.basicDataId={0} is invalid.", employee2.getEmployeeBasicData().getBasicDataId())); //NOI18N - } else if (employee2.getEmployeeBranchOffice() == null && employee2.getEmployeeDepartment() == null && employee2.getEmployeeHeadquarter() == null) { - // At least one must be set - throw new NullPointerException("employee2.employeeBranchOffice, employee2.employeeDepartment and employee2.employeeHeadquarter is null"); //NOI18N - } else if (employee2.getEmployeeBranchOffice() != null && employee2.getEmployeeBranchOffice().getBranchId() == null) { - // Throw NPE - throw new NullPointerException("employee2.employeeBranchOffice.branchId is null"); //NOI18N - } else if (employee2.getEmployeeBranchOffice() != null && employee2.getEmployeeBranchOffice().getBranchId() < 1) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("employee2.employeeBranchOffice.branchId={0} is invalid.", employee2.getEmployeeBranchOffice().getBranchId())); //NOI18N - } else if (employee2.getEmployeeDepartment() != null && employee2.getEmployeeDepartment().getDepartmentId() == null) { - // Throw NPE - throw new NullPointerException("employee2.employeeDepartment.departmentId is null"); //NOI18N - } else if (employee2.getEmployeeDepartment() != null && employee2.getEmployeeDepartment().getDepartmentId() < 1) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("employee2.employeeDepartment.departmentId={0} is invalid.", employee2.getEmployeeDepartment().getDepartmentId())); //NOI18N - } else if (employee2.getEmployeeHeadquarter() != null && employee2.getEmployeeHeadquarter().getHeadquarterId() == null) { - // Throw NPE - throw new NullPointerException("employee2.employeeHeadquarter.headquarterId is null"); //NOI18N - } else if (employee2.getEmployeeHeadquarter() != null && employee2.getEmployeeHeadquarter().getHeadquarterId() < 1) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("employee2.employeeHeadquarter.headquarterId={0} is invalid.", employee2.getEmployeeHeadquarter().getHeadquarterId())); //NOI18N - } else if ((employee2.getEmployeePersonalData() == null) && (employee2.getEmployeeBranchOffice() == null) && (employee2.getEmployeeHeadquarter() == null) && (employee2.getEmployeeNumber() == null)) { - // All are null - throw new NullPointerException("employee2.employeePersonalData, employee2.employeeBranchOffice, employee2.employeeHeadquarter and employee2.employeeNumber are null"); //NOI18N - } else if ((employee2.getEmployeePersonalData() != null) && (employee2.getEmployeePersonalData().getContactId() == null)) { - // Throw NPE - throw new NullPointerException("employee2.employeePersonalData.contactId is null"); //NOI18N - } else if ((employee2.getEmployeePersonalData() != null) && (employee2.getEmployeePersonalData().getContactId() < 1)) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("employee2.employeePersonalData.contactId={0} is invalid.", employee2.getEmployeePersonalData().getContactId())); //NOI18N - } else if ((employee2.getEmployeeNumber() != null) && (employee2.getEmployeeNumber().isEmpty())) { - // Throw it again - throw new IllegalArgumentException("employee2.employeeNumber is empty"); //NOI18N - } else if (Objects.equals(employee1, employee2)) { - // Found equal entity - return true; - } - - // Same data found? - if (!Objects.equals(employee1.getEmployeeBasicData(), employee2.getEmployeeBasicData())) { - // Not the same companies - return false; - } else if (!Objects.equals(employee1.getEmployeeNumber(), employee2.getEmployeeNumber())) { - // Not same number - return false; - } else if (!Objects.equals(employee1.getEmployeePersonalData(), employee2.getEmployeePersonalData())) { - // Not same personal data - return false; - } - - // Is same employee - return true; - } - - /** - * Private constructor - */ - private Employees () { - // No instances from utilities - } - -} diff --git a/src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarters.java b/src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarters.java deleted file mode 100644 index dfd6020..0000000 --- a/src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarters.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2017 - 2022 Free Software Foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontactsbusiness.model.headquarter; - -import java.io.Serializable; -import java.util.Objects; - -/** - * An utilities class for headquarter - * - * @author Roland Häder - */ -public class Headquarters implements Serializable { - - /** - * Serial number - */ - private static final long serialVersionUID = 69_537_867_224_651L; - - /** - * Compare null-reference-safe 2 headquarter instances with each other. - *

- * @param headquarter1 Headquarter 1 - * @param headquarter2 Headquarter 2 - *

- * @return Comparison value from invoking Comparable.compareTo() - */ - public static int compare (final Headquarter headquarter1, final Headquarter headquarter2) { - // Compare both - if (Objects.equals(headquarter1, headquarter2)) { - // Same headquarters - return 0; - } else if (null == headquarter1) { - // First is null - return -1; - } else if (null == headquarter2) { - // Second headquarter is null - return 1; - } - - // Now that both are not NULL, compare them - return headquarter1.compareTo(headquarter2); - } - - /** - * Checks if both headquarter have same address. This method will throw an - * {@code NullPointerException} if one of the instances is null. - *

- * @param headquarter1 Headquarter 1 - * @param headquarter2 Headquarter 2 - *

- * @return Whether both branch office addresses are the same - *

- * @throws NullPointerException If one of the instances is null - */ - public static boolean isSameAddress (final Headquarter headquarter1, final Headquarter headquarter2) { - // Check that both parameters are not null - if (null == headquarter1) { - // Throw NPE - throw new NullPointerException("headquarter1 is null"); //NOI18N - } else if (null == headquarter2) { - // Throw NPE - throw new NullPointerException("headquarter2 is null"); //NOI18N - } - - // Default is the same - boolean isSameAddress = true; - - // Compare both addresses - if (!Objects.equals(headquarter1.getHeadquarterCompanyName(), headquarter2.getHeadquarterCompanyName())) { - // Not the same - isSameAddress = false; - } else if (!Objects.equals(headquarter1.getHeadquarterCountry(), headquarter2.getHeadquarterCountry())) { - // Not the same - isSameAddress = false; - } else if (!Objects.equals(headquarter1.getHeadquarterCity(), headquarter2.getHeadquarterCity())) { - // Not the same - isSameAddress = false; - } else if (!Objects.equals(headquarter1.getHeadquarterZipCode(), headquarter2.getHeadquarterZipCode())) { - // Not the same - isSameAddress = false; - } else if (!Objects.equals(headquarter1.getHeadquarterStreet(), headquarter2.getHeadquarterStreet())) { - // Not the same - isSameAddress = false; - } else if (!Objects.equals(headquarter1.getHeadquarterHouseNumber(), headquarter2.getHeadquarterHouseNumber())) { - // Not the same - isSameAddress = false; - } else if (!Objects.equals(headquarter1.getHeadquarterHouseNumberExtension(), headquarter2.getHeadquarterHouseNumberExtension())) { - // Not the same - isSameAddress = false; - } else if (!Objects.equals(headquarter1.getHeadquarterStore(), headquarter2.getHeadquarterStore())) { - // Not the same - isSameAddress = false; - } else if (!Objects.equals(headquarter1.getHeadquarterSuiteNumber(), headquarter2.getHeadquarterSuiteNumber())) { - // Not the same - isSameAddress = false; - } - - // Return flag - return isSameAddress; - } - - /** - * Private default constructor - */ - private Headquarters () { - // Utilities don't have instances - } - -} diff --git a/src/org/mxchange/jcontactsbusiness/model/jobposition/EmployeePosition.java b/src/org/mxchange/jcontactsbusiness/model/jobposition/EmployeePosition.java index c08b89d..ae2e5ae 100644 --- a/src/org/mxchange/jcontactsbusiness/model/jobposition/EmployeePosition.java +++ b/src/org/mxchange/jcontactsbusiness/model/jobposition/EmployeePosition.java @@ -33,10 +33,12 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; +import org.apache.commons.lang3.StringUtils; import org.mxchange.jcontactsbusiness.model.jobposition.status.JobPositionStatus; import org.mxchange.jcoreutils.Comparables; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; +import org.mxchange.jusercore.model.user.Users; /** * A POJO for job positions @@ -144,9 +146,9 @@ public class EmployeePosition implements HireableJobPosition { // Init comparisons final int[] comparators = { // First added by which user ... - this.getJobPositionAddedUser().compareTo(jobPosition.getJobPositionAddedUser()), + Users.compare(this.getJobPositionAddedUser(), jobPosition.getJobPositionAddedUser()), // ... next name - this.getJobPositionName().compareToIgnoreCase(jobPosition.getJobPositionName()) + StringUtils.compareIgnoreCase(this.getJobPositionName(), jobPosition.getJobPositionName()) }; // Check all values diff --git a/src/org/mxchange/jcontactsbusiness/model/jobposition/JobPositions.java b/src/org/mxchange/jcontactsbusiness/model/jobposition/JobPositions.java deleted file mode 100644 index 72d1b67..0000000 --- a/src/org/mxchange/jcontactsbusiness/model/jobposition/JobPositions.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2022 Free Software Foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcontactsbusiness.model.jobposition; - -import java.io.Serializable; -import java.util.Objects; - -/** - * Utilities class for job positions - *

- * @author Roland Häder - */ -public class JobPositions implements Serializable { - - /** - * Serial number - */ - private static final long serialVersionUID = 157_986_766_142_309L; - - /** - * Compares both job position instances. This method returns -1 if second - * instance is null. - *

- * @param jobPosition1 Job position instance 1 - * @param jobPosition2 Job position instance 2 - *

- * @return Comparison value - */ - public static int compare (final HireableJobPosition jobPosition1, final HireableJobPosition jobPosition2) { - // Check equality, then at least first must be given - if (Objects.equals(jobPosition1, jobPosition2)) { - // Both are same - return 0; - } else if (null == jobPosition1) { - // First is null - return -1; - } else if (null == jobPosition2) { - // Second is null - return 1; - } - - // Invoke compareTo() method - return jobPosition1.compareTo(jobPosition2); - } - - /** - * Private constructor - */ - private JobPositions () { - // No instance should be creatable - } - -} diff --git a/src/org/mxchange/jcontactsbusiness/model/logo/BusinessLogo.java b/src/org/mxchange/jcontactsbusiness/model/logo/BusinessLogo.java index 8e7f392..ae98fde 100644 --- a/src/org/mxchange/jcontactsbusiness/model/logo/BusinessLogo.java +++ b/src/org/mxchange/jcontactsbusiness/model/logo/BusinessLogo.java @@ -31,9 +31,11 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; +import org.apache.commons.lang3.StringUtils; import org.mxchange.jcoreutils.Comparables; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; +import org.mxchange.jusercore.model.user.Users; /** * A POJO for company logos @@ -102,9 +104,9 @@ public class BusinessLogo implements Logo { // Init comparisons final int[] comparators = { // First file name ... - this.getLogoFileName().compareToIgnoreCase(logo.getLogoFileName()), + StringUtils.compareIgnoreCase(this.getLogoFileName(), logo.getLogoFileName()), // ... then uploader instance - this.getLogoUploaderUser().compareTo(logo.getLogoUploaderUser()) + Users.compare(this.getLogoUploaderUser(), logo.getLogoUploaderUser()) }; // Check all values diff --git a/src/org/mxchange/jcontactsbusiness/model/utils/BasicDataUtils.java b/src/org/mxchange/jcontactsbusiness/model/utils/BasicDataUtils.java new file mode 100644 index 0000000..e4a4616 --- /dev/null +++ b/src/org/mxchange/jcontactsbusiness/model/utils/BasicDataUtils.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2022 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontactsbusiness.model.utils; + +import java.io.Serializable; +import java.util.Objects; +import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; + +/** + * An utilities class for basic company data + *

+ * @author Roland Häder + */ +public class BasicDataUtils implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 159_847_673_672_091L; + + /** + * Compares both basic company data instances. This method returns -1 if + * second instance is null. + *

+ * @param basicData1 Basic company data instance 1 + * @param basicData2 Basic company data instance 2 + *

+ * @return Comparison value + */ + public static int compare (final BasicData basicData1, final BasicData basicData2) { + // Check equality, then at least first must be given + if (Objects.equals(basicData1, basicData2)) { + // Both are same + return 0; + } else if (null == basicData1) { + // First is null + return -1; + } else if (null == basicData2) { + // Second is null + return 1; + } + + // Invoke compareTo() method + return basicData1.compareTo(basicData2); + } + + /** + * Utility classes should not have instances + */ + private BasicDataUtils () { + // Private constructor + } + +} diff --git a/src/org/mxchange/jcontactsbusiness/model/utils/BranchOfficeUtils.java b/src/org/mxchange/jcontactsbusiness/model/utils/BranchOfficeUtils.java new file mode 100644 index 0000000..801b17b --- /dev/null +++ b/src/org/mxchange/jcontactsbusiness/model/utils/BranchOfficeUtils.java @@ -0,0 +1,168 @@ + +/* + * Copyright (C) 2017 - 2022 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontactsbusiness.model.utils; + +import java.io.Serializable; +import java.util.Objects; +import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; + +/** + * An utilities class for branch offices + * + * @author Roland Häder + */ +public class BranchOfficeUtils implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 69_537_867_224_651L; + + /** + * Compares both branch office instances. This method returns -1 if second + * instance is null. + *

+ * @param branchOffice1 Branch office instance 1 + * @param branchOffice2 Branch office instance 2 + *

+ * @return Comparison value + */ + public static int compare (final BranchOffice branchOffice1, final BranchOffice branchOffice2) { + // Check equality, then at least first must be given + if (Objects.equals(branchOffice1, branchOffice2)) { + // Both are same + return 0; + } else if (null == branchOffice1) { + // First is null + return -1; + } else if (null == branchOffice2) { + // Second is null + return 1; + } + + // Invoke compareTo() method + return branchOffice1.compareTo(branchOffice2); + } + + /** + * Copies all fields from source to target branch office instance + *

+ * @param sourceBranchOffice Source BranchOffice instance + * @param targetBranchOffice Target BranchOffice instance + */ + public static void copyBranchOfficeData (final BranchOffice sourceBranchOffice, final BranchOffice targetBranchOffice) { + // Check that both parameters are not null + if (null == sourceBranchOffice) { + // Throw NPE + throw new NullPointerException("sourceBranchOffice is null"); //NOI18N + } else if (null == targetBranchOffice) { + // Throw NPE + throw new NullPointerException("targetBranchOffice is null"); //NOI18N + } else if (Objects.equals(sourceBranchOffice, targetBranchOffice)) { + // Throw IAE + throw new IllegalArgumentException("sourceBranchOffice and targetBranchOffice are the same"); //NOI18N + } + + // Copy all fields + targetBranchOffice.setBranchCity(sourceBranchOffice.getBranchCity()); + targetBranchOffice.setBranchCompany(sourceBranchOffice.getBranchCompany()); + targetBranchOffice.setBranchContactEmployee(sourceBranchOffice.getBranchContactEmployee()); + targetBranchOffice.setBranchCountry(sourceBranchOffice.getBranchCountry()); + targetBranchOffice.setBranchEmailAddress(sourceBranchOffice.getBranchEmailAddress()); + targetBranchOffice.setBranchFaxNumber(sourceBranchOffice.getBranchFaxNumber()); + targetBranchOffice.setBranchHouseNumber(sourceBranchOffice.getBranchHouseNumber()); + targetBranchOffice.setBranchHouseNumberExtension(sourceBranchOffice.getBranchHouseNumberExtension()); + targetBranchOffice.setBranchId(sourceBranchOffice.getBranchId()); + targetBranchOffice.setBranchLandLineNumber(sourceBranchOffice.getBranchLandLineNumber()); + targetBranchOffice.setBranchLastHouseNumber(sourceBranchOffice.getBranchLastHouseNumber()); + targetBranchOffice.setBranchNumber(sourceBranchOffice.getBranchNumber()); + targetBranchOffice.setBranchOpeningTimes(sourceBranchOffice.getBranchOpeningTimes()); + targetBranchOffice.setBranchOwnerEmployee(sourceBranchOffice.getBranchOwnerEmployee()); + targetBranchOffice.setBranchStore(sourceBranchOffice.getBranchStore()); + targetBranchOffice.setBranchStreet(sourceBranchOffice.getBranchStreet()); + targetBranchOffice.setBranchSuiteNumber(sourceBranchOffice.getBranchSuiteNumber()); + targetBranchOffice.setBranchUserOwner(sourceBranchOffice.getBranchUserOwner()); + targetBranchOffice.setBranchZipCode(sourceBranchOffice.getBranchZipCode()); + } + + /** + * Checks if both branch offices have same address. This method will throw + * an {@code NullPointerException} if one of the instances is null. + *

+ * @param branchOffice1 Branch office 1 + * @param branchOffice2 Branch office 2 + *

+ * @return Whether both branch office addresses are the same + *

+ * @throws NullPointerException If one of the instances is null + */ + public static boolean isSameAddress (final BranchOffice branchOffice1, final BranchOffice branchOffice2) { + // Check that both parameters are not null + if (null == branchOffice1) { + // Throw NPE + throw new NullPointerException("branchOffice1 is null"); //NOI18N + } else if (null == branchOffice2) { + // Throw NPE + throw new NullPointerException("branchOffice2 is null"); //NOI18N + } + + // Default is the same + boolean isSameAddress = true; + + // Compare both addresses + if (!Objects.equals(branchOffice1.getBranchCompany(), branchOffice2.getBranchCompany())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(branchOffice1.getBranchCountry(), branchOffice2.getBranchCountry())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(branchOffice1.getBranchCity(), branchOffice2.getBranchCity())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(branchOffice1.getBranchZipCode(), branchOffice2.getBranchZipCode())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(branchOffice1.getBranchStreet(), branchOffice2.getBranchStreet())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(branchOffice1.getBranchHouseNumber(), branchOffice2.getBranchHouseNumber())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(branchOffice1.getBranchHouseNumberExtension(), branchOffice2.getBranchHouseNumberExtension())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(branchOffice1.getBranchStore(), branchOffice2.getBranchStore())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(branchOffice1.getBranchSuiteNumber(), branchOffice2.getBranchSuiteNumber())) { + // Not the same + isSameAddress = false; + } + + // Return flag + return isSameAddress; + } + + /** + * Private default constructor + */ + private BranchOfficeUtils () { + // Utilities don't have instances + } + +} diff --git a/src/org/mxchange/jcontactsbusiness/model/utils/DepartmentUtils.java b/src/org/mxchange/jcontactsbusiness/model/utils/DepartmentUtils.java new file mode 100644 index 0000000..f1c657f --- /dev/null +++ b/src/org/mxchange/jcontactsbusiness/model/utils/DepartmentUtils.java @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2017 - 2022 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontactsbusiness.model.utils; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Objects; +import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; +import org.mxchange.jcontactsbusiness.model.department.Department; +import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; + +/** + * Utilities class for departments + *

+ * @author Roland Häder + */ +public class DepartmentUtils implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 20_154_686_786_561L; + + /** + * Compares both department instances. This method returns -1 if second + * instance is null. + *

+ * @param department1 Department instance 1 + * @param department2 Department instance 2 + *

+ * @return Comparison value + */ + public static int compare (final Department department1, final Department department2) { + // Check equality, then at least first must be given + if (Objects.equals(department1, department2)) { + // Both are same + return 0; + } else if (null == department1) { + // First is null + return -1; + } else if (null == department2) { + // Second is null + return 1; + } + + // Invoke compareTo() method + return department1.compareTo(department2); + } + + /** + * Copies all data from source department to target department. + *

+ * @param sourceDepartment Source department + * @param targetDepartment Target department + */ + public static void copyDepartmentData (final Department sourceDepartment, final Department targetDepartment) { + // Check that both parameters are not null + if (null == sourceDepartment) { + // Throw NPE + throw new NullPointerException("sourceDepartment is null"); //NOI18N + } else if (null == targetDepartment) { + // Throw NPE + throw new NullPointerException("targetDepartment is null"); //NOI18N + } else if (Objects.equals(sourceDepartment, targetDepartment)) { + // Throw IAE + throw new IllegalArgumentException("sourceDepartment and targetDepartment are the same"); //NOI18N + } + + // Copy all fields + targetDepartment.setDepartmentBranchOffice(sourceDepartment.getDepartmentBranchOffice()); + targetDepartment.setDepartmentCompany(sourceDepartment.getDepartmentCompany()); + targetDepartment.setDepartmentHeadquarter(sourceDepartment.getDepartmentHeadquarter()); + targetDepartment.setDepartmentI18nKey(sourceDepartment.getDepartmentI18nKey()); + targetDepartment.setDepartmentId(sourceDepartment.getDepartmentId()); + targetDepartment.setDepartmentLead(sourceDepartment.getDepartmentLead()); + targetDepartment.setDepartmentUserOwner(sourceDepartment.getDepartmentUserOwner()); + } + + /** + * Checks if both departments are the same (entity) or if at least basic + * company data and department name are matching. + *

+ * @param department1 Department 1 + * @param department2 Department 2 + *

+ * @return Whether both are the same + */ + public static boolean isSameDepartment (final Department department1, final Department department2) { + // Now check it + if (null == department1) { + // Throw NPE + throw new NullPointerException("department1 is null"); //NOI18N + } else if (null == department2) { + // Throw it again + throw new NullPointerException("department2 is null"); //NOI18N + } else if (Objects.equals(department1, department2)) { + // Same department + return true; + } else if (department1.getDepartmentCompany() == null) { + // Throw NPE again + throw new NullPointerException("department1.departmentCompany is null"); //NOI18N + } else if (department1.getDepartmentCompany().getBasicDataId() == null) { + // Throw NPE again + throw new NullPointerException("department1.departmentCompany.basicDataId is null"); //NOI18N + } else if (department1.getDepartmentCompany().getBasicDataId() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("department1.departmentCompany.basicDataId={0} is valid.", department1.getDepartmentCompany().getBasicDataId())); //NOI18N + } else if (department1.getDepartmentI18nKey() == null) { + // Throw it again + throw new NullPointerException("department1.departmentName is null"); //NOI18N + } else if (department1.getDepartmentI18nKey().isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("department1.departmentName is empty"); //NOI18N + } else if (department2.getDepartmentCompany() == null) { + // Throw NPE again + throw new NullPointerException("department2.departmentCompany is null"); //NOI18N + } else if (department2.getDepartmentCompany().getBasicDataId() == null) { + // Throw NPE again + throw new NullPointerException("department2.departmentCompany.basicDataId is null"); //NOI18N + } else if (department2.getDepartmentCompany().getBasicDataId() < 1) { + // Throw NPE again + throw new NullPointerException(MessageFormat.format("department2.departmentCompany.basicDataId={0} is valid.", department2.getDepartmentCompany().getBasicDataId())); //NOI18N + } else if (department2.getDepartmentI18nKey() == null) { + // Throw it again + throw new NullPointerException("department2.departmentName is null"); //NOI18N + } else if (department2.getDepartmentI18nKey().isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("department2.departmentName is empty"); //NOI18N + } + + // Same company and same name? + boolean isSame = ((Objects.equals(department1.getDepartmentCompany(), department2.getDepartmentCompany())) && + (((department1.getDepartmentBranchOffice() instanceof BranchOffice) && + (Objects.equals(department1.getDepartmentBranchOffice(), department2.getDepartmentBranchOffice()))) || + ((department1.getDepartmentHeadquarter() instanceof Headquarter) && + (Objects.equals(department1.getDepartmentHeadquarter(), department2.getDepartmentHeadquarter())))) && + (Objects.equals(department1.getDepartmentI18nKey(), department2.getDepartmentI18nKey()))); + + // Return it + return isSame; + } + + /** + * Private default constructor + */ + private DepartmentUtils () { + // Prevent instances from utilities classes + } + +} diff --git a/src/org/mxchange/jcontactsbusiness/model/utils/EmployeeUtils.java b/src/org/mxchange/jcontactsbusiness/model/utils/EmployeeUtils.java new file mode 100644 index 0000000..3e8bcb6 --- /dev/null +++ b/src/org/mxchange/jcontactsbusiness/model/utils/EmployeeUtils.java @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2017 - 2022 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontactsbusiness.model.utils; + +import java.io.Serializable; +import java.text.MessageFormat; +import java.util.Objects; +import org.mxchange.jcontactsbusiness.model.employee.Employable; + +/** + * Utilities class for employees + *

+ * @author Roland Häder + */ +public class EmployeeUtils implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 158_376_461_255_901L; + + /** + * Compares both employee instances. This method returns -1 if second + * instance is null. + *

+ * @param employable1 Employee instance 1 + * @param employable2 Employee instance 2 + *

+ * @return Comparison value + */ + public static int compare (final Employable employable1, final Employable employable2) { + // Check equality, then at least first must be given + if (Objects.equals(employable1, employable2)) { + // Both are same + return 0; + } else if (null == employable1) { + // First is null + return -1; + } else if (null == employable2) { + // Second is null + return 1; + } + + // Invoke compareTo() method + return employable1.compareTo(employable2); + } + + /** + * Checks whether both employees are the same + *

+ * @param employee1 Employee 1 + * @param employee2 Employee 2 + *

+ * @return Whether both are the same + */ + public static boolean isSameEmployeeFound (final Employable employee1, final Employable employee2) { + // Validate parameter + if (null == employee1) { + // Throw NPE + throw new NullPointerException("employee1 is null"); //NOI18N + } else if (employee1.getEmployeeBasicData() == null) { + // Throw it again + throw new NullPointerException("employee1.employeeCompany is null"); //NOI18N + } else if (employee1.getEmployeeBasicData().getBasicDataId() == null) { + // Throw it again + throw new NullPointerException("employee1.employeeCompany.basicDataId is null"); //NOI18N + } else if (employee1.getEmployeeBasicData().getBasicDataId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee1.employeeCompany.basicDataId={0} is invalid.", employee1.getEmployeeBasicData().getBasicDataId())); //NOI18N + } else if (employee1.getEmployeeBranchOffice() == null && employee1.getEmployeeDepartment() == null && employee1.getEmployeeHeadquarter() == null) { + // At least one must be set + throw new NullPointerException("employee1.employeeBranchOffice, employee1.employeeDepartment and employee1.employeeHeadquarter is null"); //NOI18N + } else if (employee1.getEmployeeBranchOffice() != null && employee1.getEmployeeBranchOffice().getBranchId() == null) { + // Throw NPE + throw new NullPointerException("employee1.employeeBranchOffice.branchId is null"); //NOI18N + } else if (employee1.getEmployeeBranchOffice() != null && employee1.getEmployeeBranchOffice().getBranchId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee1.employeeBranchOffice.branchId={0} is invalid.", employee1.getEmployeeBranchOffice().getBranchId())); //NOI18N + } else if (employee1.getEmployeeDepartment() != null && employee1.getEmployeeDepartment().getDepartmentId() == null) { + // Throw NPE + throw new NullPointerException("employee1.employeeDepartment.departmentId is null"); //NOI18N + } else if (employee1.getEmployeeDepartment() != null && employee1.getEmployeeDepartment().getDepartmentId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee1.employeeDepartment.departmentId={0} is invalid.", employee1.getEmployeeDepartment().getDepartmentId())); //NOI18N + } else if (employee1.getEmployeeHeadquarter() != null && employee1.getEmployeeHeadquarter().getHeadquarterId() == null) { + // Throw NPE + throw new NullPointerException("employee1.employeeHeadquarter.headquarterId is null"); //NOI18N + } else if (employee1.getEmployeeHeadquarter() != null && employee1.getEmployeeHeadquarter().getHeadquarterId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee1.employeeHeadquarter.headquarterId={0} is invalid.", employee1.getEmployeeHeadquarter().getHeadquarterId())); //NOI18N + } else if ((employee1.getEmployeePersonalData() == null) && (employee1.getEmployeeBranchOffice() == null) && (employee1.getEmployeeHeadquarter() == null) && (employee1.getEmployeeNumber() == null)) { + // All are null + throw new NullPointerException("employee1.employeePersonalData, employee1.employeeBranchOffice, employee1.employeeHeadquarter and employee1.employeeNumber are null"); //NOI18N + } else if ((employee1.getEmployeePersonalData() != null) && (employee1.getEmployeePersonalData().getContactId() == null)) { + // Throw NPE + throw new NullPointerException("employee1.employeePersonalData.contactId is null"); //NOI18N + } else if ((employee1.getEmployeePersonalData() != null) && (employee1.getEmployeePersonalData().getContactId() < 1)) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee1.employeePersonalData.contactId={0} is invalid.", employee1.getEmployeePersonalData().getContactId())); //NOI18N + } else if ((employee1.getEmployeeNumber() != null) && (employee1.getEmployeeNumber().isEmpty())) { + // Throw it again + throw new IllegalArgumentException("employee1.employeeNumber is empty"); //NOI18N + } else if (null == employee2) { + // Throw NPE + throw new NullPointerException("employee2 is null"); //NOI18N + } else if (employee2.getEmployeeBasicData() == null) { + // Throw it again + throw new NullPointerException("employee2.employeeCompany is null"); //NOI18N + } else if (employee2.getEmployeeBasicData().getBasicDataId() == null) { + // Throw it again + throw new NullPointerException("employee2.employeeCompany.basicDataId is null"); //NOI18N + } else if (employee2.getEmployeeBasicData().getBasicDataId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee2.employeeCompany.basicDataId={0} is invalid.", employee2.getEmployeeBasicData().getBasicDataId())); //NOI18N + } else if (employee2.getEmployeeBranchOffice() == null && employee2.getEmployeeDepartment() == null && employee2.getEmployeeHeadquarter() == null) { + // At least one must be set + throw new NullPointerException("employee2.employeeBranchOffice, employee2.employeeDepartment and employee2.employeeHeadquarter is null"); //NOI18N + } else if (employee2.getEmployeeBranchOffice() != null && employee2.getEmployeeBranchOffice().getBranchId() == null) { + // Throw NPE + throw new NullPointerException("employee2.employeeBranchOffice.branchId is null"); //NOI18N + } else if (employee2.getEmployeeBranchOffice() != null && employee2.getEmployeeBranchOffice().getBranchId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee2.employeeBranchOffice.branchId={0} is invalid.", employee2.getEmployeeBranchOffice().getBranchId())); //NOI18N + } else if (employee2.getEmployeeDepartment() != null && employee2.getEmployeeDepartment().getDepartmentId() == null) { + // Throw NPE + throw new NullPointerException("employee2.employeeDepartment.departmentId is null"); //NOI18N + } else if (employee2.getEmployeeDepartment() != null && employee2.getEmployeeDepartment().getDepartmentId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee2.employeeDepartment.departmentId={0} is invalid.", employee2.getEmployeeDepartment().getDepartmentId())); //NOI18N + } else if (employee2.getEmployeeHeadquarter() != null && employee2.getEmployeeHeadquarter().getHeadquarterId() == null) { + // Throw NPE + throw new NullPointerException("employee2.employeeHeadquarter.headquarterId is null"); //NOI18N + } else if (employee2.getEmployeeHeadquarter() != null && employee2.getEmployeeHeadquarter().getHeadquarterId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee2.employeeHeadquarter.headquarterId={0} is invalid.", employee2.getEmployeeHeadquarter().getHeadquarterId())); //NOI18N + } else if ((employee2.getEmployeePersonalData() == null) && (employee2.getEmployeeBranchOffice() == null) && (employee2.getEmployeeHeadquarter() == null) && (employee2.getEmployeeNumber() == null)) { + // All are null + throw new NullPointerException("employee2.employeePersonalData, employee2.employeeBranchOffice, employee2.employeeHeadquarter and employee2.employeeNumber are null"); //NOI18N + } else if ((employee2.getEmployeePersonalData() != null) && (employee2.getEmployeePersonalData().getContactId() == null)) { + // Throw NPE + throw new NullPointerException("employee2.employeePersonalData.contactId is null"); //NOI18N + } else if ((employee2.getEmployeePersonalData() != null) && (employee2.getEmployeePersonalData().getContactId() < 1)) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employee2.employeePersonalData.contactId={0} is invalid.", employee2.getEmployeePersonalData().getContactId())); //NOI18N + } else if ((employee2.getEmployeeNumber() != null) && (employee2.getEmployeeNumber().isEmpty())) { + // Throw it again + throw new IllegalArgumentException("employee2.employeeNumber is empty"); //NOI18N + } else if (Objects.equals(employee1, employee2)) { + // Found equal entity + return true; + } + + // Same data found? + if (!Objects.equals(employee1.getEmployeeBasicData(), employee2.getEmployeeBasicData())) { + // Not the same companies + return false; + } else if (!Objects.equals(employee1.getEmployeeNumber(), employee2.getEmployeeNumber())) { + // Not same number + return false; + } else if (!Objects.equals(employee1.getEmployeePersonalData(), employee2.getEmployeePersonalData())) { + // Not same personal data + return false; + } + + // Is same employee + return true; + } + + /** + * Private constructor + */ + private EmployeeUtils () { + // No instances from utilities + } + +} diff --git a/src/org/mxchange/jcontactsbusiness/model/utils/HeadquarterUtils.java b/src/org/mxchange/jcontactsbusiness/model/utils/HeadquarterUtils.java new file mode 100644 index 0000000..fbe2283 --- /dev/null +++ b/src/org/mxchange/jcontactsbusiness/model/utils/HeadquarterUtils.java @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2017 - 2022 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontactsbusiness.model.utils; + +import java.io.Serializable; +import java.util.Objects; +import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; + +/** + * An utilities class for headquarter + * + * @author Roland Häder + */ +public class HeadquarterUtils implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 69_537_867_224_651L; + + /** + * Compare null-reference-safe 2 headquarter instances with each other. + *

+ * @param headquarter1 Headquarter 1 + * @param headquarter2 Headquarter 2 + *

+ * @return Comparison value from invoking Comparable.compareTo() + */ + public static int compare (final Headquarter headquarter1, final Headquarter headquarter2) { + // Compare both + if (Objects.equals(headquarter1, headquarter2)) { + // Same headquarters + return 0; + } else if (null == headquarter1) { + // First is null + return -1; + } else if (null == headquarter2) { + // Second headquarter is null + return 1; + } + + // Now that both are not NULL, compare them + return headquarter1.compareTo(headquarter2); + } + + /** + * Checks if both headquarter have same address. This method will throw an + * {@code NullPointerException} if one of the instances is null. + *

+ * @param headquarter1 Headquarter 1 + * @param headquarter2 Headquarter 2 + *

+ * @return Whether both branch office addresses are the same + *

+ * @throws NullPointerException If one of the instances is null + */ + public static boolean isSameAddress (final Headquarter headquarter1, final Headquarter headquarter2) { + // Check that both parameters are not null + if (null == headquarter1) { + // Throw NPE + throw new NullPointerException("headquarter1 is null"); //NOI18N + } else if (null == headquarter2) { + // Throw NPE + throw new NullPointerException("headquarter2 is null"); //NOI18N + } + + // Default is the same + boolean isSameAddress = true; + + // Compare both addresses + if (!Objects.equals(headquarter1.getHeadquarterCompanyName(), headquarter2.getHeadquarterCompanyName())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(headquarter1.getHeadquarterCountry(), headquarter2.getHeadquarterCountry())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(headquarter1.getHeadquarterCity(), headquarter2.getHeadquarterCity())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(headquarter1.getHeadquarterZipCode(), headquarter2.getHeadquarterZipCode())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(headquarter1.getHeadquarterStreet(), headquarter2.getHeadquarterStreet())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(headquarter1.getHeadquarterHouseNumber(), headquarter2.getHeadquarterHouseNumber())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(headquarter1.getHeadquarterHouseNumberExtension(), headquarter2.getHeadquarterHouseNumberExtension())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(headquarter1.getHeadquarterStore(), headquarter2.getHeadquarterStore())) { + // Not the same + isSameAddress = false; + } else if (!Objects.equals(headquarter1.getHeadquarterSuiteNumber(), headquarter2.getHeadquarterSuiteNumber())) { + // Not the same + isSameAddress = false; + } + + // Return flag + return isSameAddress; + } + + /** + * Private default constructor + */ + private HeadquarterUtils () { + // Utilities don't have instances + } + +} diff --git a/src/org/mxchange/jcontactsbusiness/model/utils/JobPositionUtils.java b/src/org/mxchange/jcontactsbusiness/model/utils/JobPositionUtils.java new file mode 100644 index 0000000..36d6c95 --- /dev/null +++ b/src/org/mxchange/jcontactsbusiness/model/utils/JobPositionUtils.java @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2022 Free Software Foundation + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcontactsbusiness.model.utils; + +import java.io.Serializable; +import java.util.Objects; +import org.mxchange.jcontactsbusiness.model.jobposition.HireableJobPosition; + +/** + * Utilities class for job positions + *

+ * @author Roland Häder + */ +public class JobPositionUtils implements Serializable { + + /** + * Serial number + */ + private static final long serialVersionUID = 157_986_766_142_309L; + + /** + * Compares both job position instances. This method returns -1 if second + * instance is null. + *

+ * @param jobPosition1 Job position instance 1 + * @param jobPosition2 Job position instance 2 + *

+ * @return Comparison value + */ + public static int compare (final HireableJobPosition jobPosition1, final HireableJobPosition jobPosition2) { + // Check equality, then at least first must be given + if (Objects.equals(jobPosition1, jobPosition2)) { + // Both are same + return 0; + } else if (null == jobPosition1) { + // First is null + return -1; + } else if (null == jobPosition2) { + // Second is null + return 1; + } + + // Invoke compareTo() method + return jobPosition1.compareTo(jobPosition2); + } + + /** + * Private constructor + */ + private JobPositionUtils () { + // No instance should be creatable + } + +}