From: Roland Häder Date: Sun, 18 Mar 2018 22:09:43 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4164210d987fadd48dffd0f80e5ee807e51ea290;p=jcontacts-business-core.git Continued: - ops, need to compare basic data and contact employee of branch office before comparing the whole address - branch office number being compared before contact employee is okay Signed-off-by: Roland Häder --- diff --git a/src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffices.java b/src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffices.java index 1227526..e2be31f 100644 --- a/src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffices.java +++ b/src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffices.java @@ -1,3 +1,4 @@ + /* * Copyright (C) 2017, 2018 Free Software Foundation * @@ -39,8 +40,6 @@ public class BranchOffices implements Serializable { * @param branchOffice2 Branch office instance 2 *

* @return Comparison value - *

- * @throws NullPointerException If first instance is null */ public static int compare (final BranchOffice branchOffice1, final BranchOffice branchOffice2) { // Check euqality, then at least first must be given @@ -48,8 +47,8 @@ public class BranchOffices implements Serializable { // Both are same return 0; } else if (null == branchOffice1) { - // First cannot be null - throw new NullPointerException("branchOffice1 is null"); //NOI18N + // First is null + return -1; } else if (null == branchOffice2) { // Second is null return 1; diff --git a/src/org/mxchange/jcontactsbusiness/model/branchoffice/BusinessBranchOffice.java b/src/org/mxchange/jcontactsbusiness/model/branchoffice/BusinessBranchOffice.java index 7f3c91a..12815f0 100644 --- a/src/org/mxchange/jcontactsbusiness/model/branchoffice/BusinessBranchOffice.java +++ b/src/org/mxchange/jcontactsbusiness/model/branchoffice/BusinessBranchOffice.java @@ -41,6 +41,7 @@ import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData; import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee; import org.mxchange.jcontactsbusiness.model.employee.Employable; +import org.mxchange.jcontactsbusiness.model.employee.Employees; import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime; import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; import org.mxchange.jcoreee.utils.Comparables; @@ -302,10 +303,12 @@ public class BusinessBranchOffice implements BranchOffice { // Init comparisons final int[] comparators = { - // A different branch number is a clear indication ... + // First compare basic data + this.getBranchCompany().compareTo(branchOffice.getBranchCompany()), + // ... branch office number NumberUtils.compare(this.getBranchNumber(), branchOffice.getBranchNumber()), - // ... same with id ... - NumberUtils.compare(this.getBranchId(), branchOffice.getBranchId()), + // ... contact person + Employees.compare(this.getBranchContactEmployee(), branchOffice.getBranchContactEmployee()), // ... then country this.getBranchCountry().compareTo(branchOffice.getBranchCountry()), // ... next city diff --git a/src/org/mxchange/jcontactsbusiness/model/department/Departments.java b/src/org/mxchange/jcontactsbusiness/model/department/Departments.java index 7aa9a86..e78550c 100644 --- a/src/org/mxchange/jcontactsbusiness/model/department/Departments.java +++ b/src/org/mxchange/jcontactsbusiness/model/department/Departments.java @@ -42,8 +42,6 @@ public class Departments implements Serializable { * @param department2 Department instance 2 *

* @return Comparison value - *

- * @throws NullPointerException If first instance is null */ public static int compare (final Department department1, final Department department2) { // Check euqality, then at least first must be given @@ -51,8 +49,8 @@ public class Departments implements Serializable { // Both are same return 0; } else if (null == department1) { - // First cannot be null - throw new NullPointerException("department1 is null"); //NOI18N + // First is null + return -1; } else if (null == department2) { // Second is null return 1; diff --git a/src/org/mxchange/jcontactsbusiness/model/employee/Employees.java b/src/org/mxchange/jcontactsbusiness/model/employee/Employees.java index 9c642b6..177da4f 100644 --- a/src/org/mxchange/jcontactsbusiness/model/employee/Employees.java +++ b/src/org/mxchange/jcontactsbusiness/model/employee/Employees.java @@ -32,6 +32,32 @@ public class Employees implements Serializable { */ 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 euqality, 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 *

@@ -75,7 +101,7 @@ public class Employees implements Serializable { } 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.getEmployeeNumber()== null)) { + } else if ((employee1.getEmployeePersonalData() == null) && (employee1.getEmployeeNumber() == null)) { // Both are null throw new NullPointerException("employee1.employeePersonalData and employee1.employeeNumber are null"); //NOI18N } else if ((employee1.getEmployeePersonalData() != null) && (employee1.getEmployeePersonalData().getContactId() == null)) { @@ -120,7 +146,7 @@ public class Employees implements Serializable { } 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.getEmployeeNumber()== null)) { + } else if ((employee2.getEmployeePersonalData() == null) && (employee2.getEmployeeNumber() == null)) { // Both are null throw new NullPointerException("employee2.employeePersonalData and employee2.employeeNumber are null"); //NOI18N } else if ((employee2.getEmployeePersonalData() != null) && (employee2.getEmployeePersonalData().getContactId() == null)) { diff --git a/src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarters.java b/src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarters.java index 598290f..c680004 100644 --- a/src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarters.java +++ b/src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarters.java @@ -38,8 +38,6 @@ public class Headquarters implements Serializable { * @param headquarter2 Headquarter 2 *

* @return Comparison value from invoking Comparable.compareTo() - *

- * @throws NullPointerException If first instance is null */ public static int compare (final Headquarter headquarter1, final Headquarter headquarter2) { // Compare both @@ -47,8 +45,8 @@ public class Headquarters implements Serializable { // Same headquarters return 0; } else if (null == headquarter1) { - // First headquarter is null - throw new NullPointerException("headquarter1 is null"); //NOI18N + // First is null + return -1; } else if (null == headquarter2) { // Second headquarter is null return 1; diff --git a/src/org/mxchange/jcontactsbusiness/model/jobposition/JobPositions.java b/src/org/mxchange/jcontactsbusiness/model/jobposition/JobPositions.java index 1b523a9..a23be98 100644 --- a/src/org/mxchange/jcontactsbusiness/model/jobposition/JobPositions.java +++ b/src/org/mxchange/jcontactsbusiness/model/jobposition/JobPositions.java @@ -39,8 +39,6 @@ public class JobPositions implements Serializable { * @param jobPosition2 Job position instance 2 *

* @return Comparison value - *

- * @throws NullPointerException If first instance is null */ public static int compare (final JobPosition jobPosition1, final JobPosition jobPosition2) { // Check euqality, then at least first must be given @@ -48,8 +46,8 @@ public class JobPositions implements Serializable { // Both are same return 0; } else if (null == jobPosition1) { - // First cannot be null - throw new NullPointerException("jobPosition1 is null"); //NOI18N + // First is null + return -1; } else if (null == jobPosition2) { // Second is null return 1;