From: Roland Häder Date: Thu, 15 Mar 2018 23:36:19 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4314b6468e0529bc51c4c6c746dd9ae2e65eae5a;p=jcontacts-business-core.git Continued: - added new dependency to jcoreee.jar - implemented Comparable interface in all entities - rewrote to use Comparables.checkAll() - check for null-pointer reference - documented thrown NPE - added utils class for job positions Signed-off-by: Roland Häder --- diff --git a/nbproject/project.properties b/nbproject/project.properties index f3f37e1..f07f0a8 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -31,6 +31,7 @@ dist.javadoc.dir=${dist.dir}/javadoc endorsed.classpath= excludes= file.reference.jcontacts-core.jar=lib/jcontacts-core.jar +file.reference.jcoreee.jar=lib/jcoreee.jar file.reference.jcountry-core.jar=lib/jcountry-core.jar file.reference.jphone-core.jar=lib/jphone-core.jar file.reference.juser-core.jar=lib/juser-core.jar @@ -43,6 +44,7 @@ javac.classpath=\ ${file.reference.jcountry-core.jar}:\ ${file.reference.jphone-core.jar}:\ ${file.reference.juser-core.jar}:\ + ${file.reference.jcoreee.jar}:\ ${libs.jpa20-persistence.classpath} # Space-separated list of extra javac options javac.compilerargs=-Xlint:unchecked -Xlint:deprecation @@ -97,7 +99,8 @@ run.test.classpath=\ ${build.test.classes.dir} source.encoding=UTF-8 source.reference.jcontacts-core.jar=../jcontacts-core/src/ -source.reference.jcountry-core.jar=../jcountry-code/src/ +source.reference.jcoreee.jar=../jcoreee/src/ +source.reference.jcountry-core.jar=../jcountry-core/src/ source.reference.jphone-core.jar=../jphone-core/src/ source.reference.juser-core.jar=../juser-core/src/ src.dir=src diff --git a/src/org/mxchange/jcontactsbusiness/model/basicdata/BasicData.java b/src/org/mxchange/jcontactsbusiness/model/basicdata/BasicData.java index 554cb84..834aad7 100644 --- a/src/org/mxchange/jcontactsbusiness/model/basicdata/BasicData.java +++ b/src/org/mxchange/jcontactsbusiness/model/basicdata/BasicData.java @@ -32,7 +32,7 @@ import org.mxchange.jusercore.model.user.User; *

* @author Roland Häder */ -public interface BasicData extends Serializable { +public interface BasicData extends Comparable, Serializable { /** * Getter for branches list diff --git a/src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java b/src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java index dd3ab39..1efd780 100644 --- a/src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java +++ b/src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java @@ -40,8 +40,11 @@ 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.jcoreee.utils.Comparables; +import org.mxchange.jcoreee.utils.StringUtils; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber; import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; @@ -198,6 +201,36 @@ public class BusinessBasicData implements BasicData { this.companyName = companyName; } + @Override + public int compareTo (final BasicData basicData) { + // For performance reasons + if (null == basicData) { + // Should not happen + throw new NullPointerException("basicData is null"); //NOI18N + } else if (Objects.equals(this, basicData)) { + // Same object + return 0; + } + + // Init comparators + final int comparators[] = { + // First compare company name + this.getCompanyName().compareToIgnoreCase(basicData.getCompanyName()), + // ... next tax number + StringUtils.compareToIgnoreCase(this.getCompanyTaxNumber(), basicData.getCompanyTaxNumber()), + // ... and email address + StringUtils.compareToIgnoreCase(this.getCompanyEmailAddress(), basicData.getCompanyEmailAddress()), + // ... head quarter data + Headquarters.compare(this.getCompanyHeadquarterData(), basicData.getCompanyHeadquarterData()) + }; + + // Check all values + final int comparison = Comparables.checkAll(comparators); + + // Return value + return comparison; + } + @Override public boolean equals (final Object object) { if (null == object) { diff --git a/src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffices.java b/src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffices.java index 284d097..7054e4b 100644 --- a/src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffices.java +++ b/src/org/mxchange/jcontactsbusiness/model/branchoffice/BranchOffices.java @@ -31,6 +31,34 @@ public class BranchOffices implements Serializable { */ 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 + *

+ * @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 + if (Objects.equals(branchOffice1, branchOffice2)) { + // Both are same + return 0; + } else if (null == branchOffice1) { + // First cannot be null + throw new NullPointerException("branchOffice1 is null"); //NOI18N + } else if (null == branchOffice2) { + // Second is null + return -1; + } + + // Invoke compareTo() method + return branchOffice1.compareTo(branchOffice2); + } + /** * Checks if both branch offices have same address. This method will throw * an {@code NullPointerException} if one of the instances is null. diff --git a/src/org/mxchange/jcontactsbusiness/model/branchoffice/BusinessBranchOffice.java b/src/org/mxchange/jcontactsbusiness/model/branchoffice/BusinessBranchOffice.java index 1c32787..9619c54 100644 --- a/src/org/mxchange/jcontactsbusiness/model/branchoffice/BusinessBranchOffice.java +++ b/src/org/mxchange/jcontactsbusiness/model/branchoffice/BusinessBranchOffice.java @@ -43,6 +43,7 @@ import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee; import org.mxchange.jcontactsbusiness.model.employee.Employable; import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime; import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; +import org.mxchange.jcoreee.utils.Comparables; import org.mxchange.jcoreee.utils.StringUtils; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jcountry.model.data.CountryData; @@ -290,16 +291,16 @@ public class BusinessBranchOffice implements BranchOffice { @Override public int compareTo (final BranchOffice branchOffice) { // For performance reasons - if (Objects.equals(this, branchOffice)) { + if (null == branchOffice) { + // Should not happen + throw new NullPointerException("branchOffice is null"); //NOI18N + } else if (Objects.equals(this, branchOffice)) { // Same object return 0; } - // Init check array (I could repeat myself here, but no) + // Init comparisons final int[] comparators = { - // A different branch number is a clear indication ... - // A different branch number is a clear indication ... - // A different branch number is a clear indication ... // A different branch number is a clear indication ... Long.compare(this.getBranchNumber(), branchOffice.getBranchNumber()), // ... same with id ... @@ -314,31 +315,21 @@ public class BusinessBranchOffice implements BranchOffice { this.getBranchStreet().compareToIgnoreCase(branchOffice.getBranchStreet()), // ... and house number this.getBranchHouseNumber().compareTo(branchOffice.getBranchHouseNumber()), - // ... and last house number + // ... and house number Short.compare(this.getBranchLastHouseNumber(), branchOffice.getBranchLastHouseNumber()), - StringUtils.comareToIgnoreCase(this.getBranchHouseNumberExtension(), branchOffice.getBranchHouseNumberExtension()), + // ... and extension + StringUtils.compareToIgnoreCase(this.getBranchHouseNumberExtension(), branchOffice.getBranchHouseNumberExtension()), // ... store ... Short.compare(this.getBranchStore(), branchOffice.getBranchStore()), // ... suite number ... Short.compare(this.getBranchSuiteNumber(), branchOffice.getBranchSuiteNumber()) }; - // Loop through all - for (int i = 0; i < comparators.length; i++) { - - // Is it smaller or bigger? - if (comparators[i] < 0) { - return -1; - } else if (comparators[i] > 0) { - return 1; - } - } - - // Verify that compareTo() is constistent with equals() - assert Objects.equals(this, branchOffice) : "compareTo inconsistent with equals()"; //NOI18N + // Check all values + final int comparison = Comparables.checkAll(comparators); - // Assume euqality - return 0; + // Return value + return comparison; } @Override diff --git a/src/org/mxchange/jcontactsbusiness/model/department/BusinessDepartment.java b/src/org/mxchange/jcontactsbusiness/model/department/BusinessDepartment.java index 611e0e4..edde1cc 100644 --- a/src/org/mxchange/jcontactsbusiness/model/department/BusinessDepartment.java +++ b/src/org/mxchange/jcontactsbusiness/model/department/BusinessDepartment.java @@ -37,11 +37,14 @@ import javax.persistence.Transient; 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.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.jcoreee.utils.Comparables; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; @@ -157,6 +160,36 @@ public class BusinessDepartment implements Department { this.departmentI18nKey = departmentName; } + @Override + public int compareTo (final Department department) { + // For performance reasons + if (null == department) { + // Should not happen + throw new NullPointerException("department is null"); //NOI18N + } else if (Objects.equals(this, department)) { + // Same object + return 0; + } + + // Init comparisons + final int[] comparators = { + // First department's company (BasicData) ... + this.getDepartmentCompany().compareTo(department.getDepartmentCompany()), + // ... then headquarters + Headquarters.compare(this.getDepartmentHeadquarter(), department.getDepartmentHeadquarter()), + // ... branch office + BranchOffices.compare(this.getDepartmentBranchOffice(), department.getDepartmentBranchOffice()), + // ... finally department's i18n key + this.getDepartmentI18nKey().compareTo(department.getDepartmentI18nKey()) + }; + + // Check all values + final int comparison = Comparables.checkAll(comparators); + + // Return value + return comparison; + } + @Override public boolean equals (final Object object) { if (null == object) { diff --git a/src/org/mxchange/jcontactsbusiness/model/department/Department.java b/src/org/mxchange/jcontactsbusiness/model/department/Department.java index eeb9226..2cb0771 100644 --- a/src/org/mxchange/jcontactsbusiness/model/department/Department.java +++ b/src/org/mxchange/jcontactsbusiness/model/department/Department.java @@ -18,18 +18,18 @@ package org.mxchange.jcontactsbusiness.model.department; import java.io.Serializable; import java.util.Date; +import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; -import org.mxchange.jusercore.model.user.User; import org.mxchange.jcontactsbusiness.model.employee.Employable; -import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; +import org.mxchange.jusercore.model.user.User; /** * A POJI for company departments *

* @author Roland Häder */ -public interface Department extends Serializable { +public interface Department extends Comparable, Serializable { /** * Getter for connection to business contact diff --git a/src/org/mxchange/jcontactsbusiness/model/department/Departments.java b/src/org/mxchange/jcontactsbusiness/model/department/Departments.java index b1664a8..7786af3 100644 --- a/src/org/mxchange/jcontactsbusiness/model/department/Departments.java +++ b/src/org/mxchange/jcontactsbusiness/model/department/Departments.java @@ -34,6 +34,34 @@ public class Departments implements Serializable { */ 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 + *

+ * @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 + if (Objects.equals(department1, department2)) { + // Both are same + return 0; + } else if (null == department1) { + // First cannot be null + throw new NullPointerException("department1 is null"); //NOI18N + } else if (null == department2) { + // Second is null + return -1; + } + + // Invoke compareTo() method + return department1.compareTo(department2); + } + /** * Checks if both departments are the same (entity) or if at least basic * company data and department name are matching. diff --git a/src/org/mxchange/jcontactsbusiness/model/employee/BusinessEmployee.java b/src/org/mxchange/jcontactsbusiness/model/employee/BusinessEmployee.java index 8e349f6..cf87e93 100644 --- a/src/org/mxchange/jcontactsbusiness/model/employee/BusinessEmployee.java +++ b/src/org/mxchange/jcontactsbusiness/model/employee/BusinessEmployee.java @@ -34,17 +34,24 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jcontacts.model.contact.Contacts; import org.mxchange.jcontacts.model.contact.UserContact; 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.JobPosition; +import org.mxchange.jcontactsbusiness.model.jobposition.JobPositions; +import org.mxchange.jcoreee.utils.Comparables; +import org.mxchange.jcoreee.utils.StringUtils; import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber; import org.mxchange.jusercore.model.user.LoginUser; @@ -70,6 +77,13 @@ public class BusinessEmployee implements Employable { @Transient private static final long serialVersionUID = 48_959_819_859_812_076L; + /** + * Company the employee is working at + */ + @JoinColumn (name = "employee_company_id", nullable = false, updatable = false) + @OneToOne (targetEntity = BusinessBasicData.class, cascade = CascadeType.REFRESH, optional = false) + private BasicData employeeBasicData; + /** * Branch office (if the employee works there) */ @@ -77,13 +91,6 @@ public class BusinessEmployee implements Employable { @OneToOne (targetEntity = BusinessBranchOffice.class, cascade = CascadeType.REFRESH) private BranchOffice employeeBranchOffice; - /** - * Company the employee is working at - */ - @JoinColumn (name = "employee_company_id", nullable = false, updatable = false) - @OneToOne (targetEntity = BusinessBasicData.class, cascade = CascadeType.REFRESH, optional = false) - private BasicData employeeCompany; - /** * Timestamp when this entry has been created */ @@ -100,7 +107,7 @@ public class BusinessEmployee implements Employable { private Department employeeDepartment; /** - * Employable's email address + * Employee's email address */ @Column (name = "employee_email_address", length = 30) private String employeeEmailAddress; @@ -121,38 +128,38 @@ public class BusinessEmployee implements Employable { private Long employeeId; /** - * Employable's business mobile number + * Employee's position (example: CEO) + */ + @JoinColumn (name = "employee_position_id") + @OneToOne (targetEntity = EmployeePosition.class, cascade = CascadeType.REFRESH) + private JobPosition employeeJobPosition; + + /** + * Employee's business mobile number */ @JoinColumn (name = "employee_mobile_number_id") @OneToOne (targetEntity = MobileNumber.class, cascade = CascadeType.REFRESH) private DialableMobileNumber employeeMobileNumber; /** - * Employable's staff number + * Employee's staff number */ @Column (name = "employee_staff_number", length = 20) private String employeeNumber; /** - * Employable's personal data + * Employee's personal data */ @JoinColumn (name = "employee_personal_data_id") @OneToOne (targetEntity = UserContact.class, cascade = CascadeType.REFRESH) private Contact employeePersonalData; /** - * Employable's phone extension (or number if different) + * Employee's phone extension (or number if different) */ @Column (name = "employee_phone_extension", length = 10) private Integer employeePhoneExtension; - /** - * Employable's position (example: CEO) - */ - @JoinColumn (name = "employee_position_id") - @OneToOne (targetEntity = EmployeePosition.class, cascade = CascadeType.REFRESH) - private JobPosition employeePosition; - /** * User owner instance */ @@ -188,11 +195,49 @@ public class BusinessEmployee implements Employable { } // Set all fields - this.employeeCompany = employeeCompany; + this.employeeBasicData = employeeCompany; this.employeeNumber = employeeNumber; this.employeePersonalData = employeePersonalData; } + @Override + public int compareTo (final Employable employable) { + // For performance reasons + if (null == employable) { + // Should not happen + throw new NullPointerException("employable is null"); //NOI18N + } else if (Objects.equals(this, employable)) { + // Same object + return 0; + } + + // Init comparisons + final int[] comparators = { + // First check company data (BasicData) + this.getEmployeeBasicData().compareTo(employable.getEmployeeBasicData()), + // ... next headquarters + Headquarters.compare(this.getEmployeeHeadquarter(), employable.getEmployeeHeadquarter()), + // ... branch office + BranchOffices.compare(this.getEmployeeBranchOffice(), employable.getEmployeeBranchOffice()), + // ... department + Departments.compare(this.getEmployeeDepartment(), employable.getEmployeeDepartment()), + // ... job position + JobPositions.compare(this.getEmployeeJobPosition(), employable.getEmployeeJobPosition()), + // ... employee's number + StringUtils.compareToIgnoreCase(this.getEmployeeNumber(), employable.getEmployeeNumber()), + // ... employee's email address + StringUtils.compareToIgnoreCase(this.getEmployeeEmailAddress(), employable.getEmployeeEmailAddress()), + // ... finally contact data + Contacts.compare(this.getEmployeePersonalData(), employable.getEmployeePersonalData()) + }; + + // Check all values + final int comparison = Comparables.checkAll(comparators); + + // Return value + return comparison; + } + @Override public boolean equals (final Object object) { if (null == object) { @@ -205,7 +250,7 @@ public class BusinessEmployee implements Employable { if (!Objects.equals(this.getEmployeeId(), employee.getEmployeeId())) { return false; - } else if (!Objects.equals(this.getEmployeeCompany(), employee.getEmployeeCompany())) { + } else if (!Objects.equals(this.getEmployeeBasicData(), employee.getEmployeeBasicData())) { return false; } else if (!Objects.equals(this.getEmployeeNumber(), employee.getEmployeeNumber())) { return false; @@ -217,23 +262,23 @@ public class BusinessEmployee implements Employable { } @Override - public BranchOffice getEmployeeBranchOffice () { - return this.employeeBranchOffice; + public BasicData getEmployeeBasicData () { + return this.employeeBasicData; } @Override - public void setEmployeeBranchOffice (final BranchOffice employeeBranchOffice) { - this.employeeBranchOffice = employeeBranchOffice; + public void setEmployeeBasicData (final BasicData employeeBasicData) { + this.employeeBasicData = employeeBasicData; } @Override - public BasicData getEmployeeCompany () { - return this.employeeCompany; + public BranchOffice getEmployeeBranchOffice () { + return this.employeeBranchOffice; } @Override - public void setEmployeeCompany (final BasicData employeeCompany) { - this.employeeCompany = employeeCompany; + public void setEmployeeBranchOffice (final BranchOffice employeeBranchOffice) { + this.employeeBranchOffice = employeeBranchOffice; } @Override @@ -288,6 +333,16 @@ public class BusinessEmployee implements Employable { this.employeeId = employeeId; } + @Override + public JobPosition getEmployeeJobPosition () { + return this.employeeJobPosition; + } + + @Override + public void setEmployeeJobPosition (final JobPosition employeeJobPosition) { + this.employeeJobPosition = employeeJobPosition; + } + @Override public DialableMobileNumber getEmployeeMobileNumber () { return this.employeeMobileNumber; @@ -328,16 +383,6 @@ public class BusinessEmployee implements Employable { this.employeePhoneExtension = employeePhoneExtension; } - @Override - public JobPosition getEmployeePosition () { - return this.employeePosition; - } - - @Override - public void setEmployeePosition (final JobPosition employeePosition) { - this.employeePosition = employeePosition; - } - @Override public User getEmployeeUserOwner () { return this.employeeUserOwner; @@ -353,7 +398,7 @@ public class BusinessEmployee implements Employable { int hash = 3; hash = 97 * hash + Objects.hashCode(this.getEmployeeId()); - hash = 97 * hash + Objects.hashCode(this.getEmployeeCompany()); + hash = 97 * hash + Objects.hashCode(this.getEmployeeBasicData()); hash = 97 * hash + Objects.hashCode(this.getEmployeeNumber()); hash = 97 * hash + Objects.hashCode(this.getEmployeePersonalData()); diff --git a/src/org/mxchange/jcontactsbusiness/model/employee/Employable.java b/src/org/mxchange/jcontactsbusiness/model/employee/Employable.java index faac464..1eec65b 100644 --- a/src/org/mxchange/jcontactsbusiness/model/employee/Employable.java +++ b/src/org/mxchange/jcontactsbusiness/model/employee/Employable.java @@ -32,7 +32,7 @@ import org.mxchange.jusercore.model.user.User; *

* @author Roland Häder */ -public interface Employable extends Serializable { +public interface Employable extends Comparable, Serializable { /** * Getter for employee's branch office @@ -53,14 +53,14 @@ public interface Employable extends Serializable { *

* @return Company instance */ - BasicData getEmployeeCompany (); + BasicData getEmployeeBasicData (); /** * Setter for employee's company *

* @param employeeCompany Company instance */ - void setEmployeeCompany (final BasicData employeeCompany); + void setEmployeeBasicData (final BasicData employeeCompany); /** * Getter for employee's department @@ -179,14 +179,14 @@ public interface Employable extends Serializable { *

* @return Employable's position */ - JobPosition getEmployeePosition (); + JobPosition getEmployeeJobPosition (); /** * Setter for employee's position *

* @param employeePosition Employable's position */ - void setEmployeePosition (final JobPosition employeePosition); + void setEmployeeJobPosition (final JobPosition employeePosition); /** * Getter for user owner instance diff --git a/src/org/mxchange/jcontactsbusiness/model/employee/Employees.java b/src/org/mxchange/jcontactsbusiness/model/employee/Employees.java index 50fec03..9c642b6 100644 --- a/src/org/mxchange/jcontactsbusiness/model/employee/Employees.java +++ b/src/org/mxchange/jcontactsbusiness/model/employee/Employees.java @@ -45,15 +45,15 @@ public class Employees implements Serializable { if (null == employee1) { // Throw NPE throw new NullPointerException("employee1 is null"); //NOI18N - } else if (employee1.getEmployeeCompany() == null) { + } else if (employee1.getEmployeeBasicData() == null) { // Throw it again throw new NullPointerException("employee1.employeeCompany is null"); //NOI18N - } else if (employee1.getEmployeeCompany().getBasicDataId() == null) { + } else if (employee1.getEmployeeBasicData().getBasicDataId() == null) { // Throw it again throw new NullPointerException("employee1.employeeCompany.basicDataId is null"); //NOI18N - } else if (employee1.getEmployeeCompany().getBasicDataId() < 1) { + } else if (employee1.getEmployeeBasicData().getBasicDataId() < 1) { // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("employee1.employeeCompany.basicDataId={0} is invalid.", employee1.getEmployeeCompany().getBasicDataId())); //NOI18N + 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 @@ -90,15 +90,15 @@ public class Employees implements Serializable { } else if (null == employee2) { // Throw NPE throw new NullPointerException("employee2 is null"); //NOI18N - } else if (employee2.getEmployeeCompany() == null) { + } else if (employee2.getEmployeeBasicData() == null) { // Throw it again throw new NullPointerException("employee2.employeeCompany is null"); //NOI18N - } else if (employee2.getEmployeeCompany().getBasicDataId() == null) { + } else if (employee2.getEmployeeBasicData().getBasicDataId() == null) { // Throw it again throw new NullPointerException("employee2.employeeCompany.basicDataId is null"); //NOI18N - } else if (employee2.getEmployeeCompany().getBasicDataId() < 1) { + } else if (employee2.getEmployeeBasicData().getBasicDataId() < 1) { // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("employee2.employeeCompany.basicDataId={0} is invalid.", employee2.getEmployeeCompany().getBasicDataId())); //NOI18N + 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 @@ -138,7 +138,7 @@ public class Employees implements Serializable { } // Same data found? - if (!Objects.equals(employee1.getEmployeeCompany(), employee2.getEmployeeCompany())) { + if (!Objects.equals(employee1.getEmployeeBasicData(), employee2.getEmployeeBasicData())) { // Not the same companies return false; } else if (!Objects.equals(employee1.getEmployeeNumber(), employee2.getEmployeeNumber())) { diff --git a/src/org/mxchange/jcontactsbusiness/model/headquarter/BusinessHeadquarter.java b/src/org/mxchange/jcontactsbusiness/model/headquarter/BusinessHeadquarter.java index f6a35e1..6391d47 100644 --- a/src/org/mxchange/jcontactsbusiness/model/headquarter/BusinessHeadquarter.java +++ b/src/org/mxchange/jcontactsbusiness/model/headquarter/BusinessHeadquarter.java @@ -41,6 +41,8 @@ import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee; import org.mxchange.jcontactsbusiness.model.employee.Employable; import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime; import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; +import org.mxchange.jcoreee.utils.Comparables; +import org.mxchange.jcoreee.utils.StringUtils; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jcountry.model.data.CountryData; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; @@ -267,6 +269,50 @@ public class BusinessHeadquarter implements Headquarter { this.headquarterZipCode = headquarterZipCode; } + @Override + public int compareTo (final Headquarter headquarter) { + // For performance reasons + if (null == headquarter) { + // Should not happen + throw new NullPointerException("headquarter is null"); //NOI18N + } else if (Objects.equals(this, headquarter)) { + // Same object + return 0; + } + + // Init comparators + final int comparators[] = { + // First check company name + this.getHeadquarterCompanyName().compareTo(headquarter.getHeadquarterCompanyName()), + // ... next country + this.getHeadquarterCountry().compareTo(headquarter.getHeadquarterCountry()), + // ... then ZIP code + Integer.compare(this.getHeadquarterZipCode(), headquarter.getHeadquarterZipCode()), + // ... and city + this.getHeadquarterCity().compareTo(headquarter.getHeadquarterCity()), + // ... street name + StringUtils.compareToIgnoreCase(this.getHeadquarterStreet(), headquarter.getHeadquarterStreet()), + // ... house number + Integer.compare(this.getHeadquarterHouseNumber(), headquarter.getHeadquarterHouseNumber()), + // ... last house number + Integer.compare(this.getHeadquarterLastHouseNumber(), headquarter.getHeadquarterLastHouseNumber()), + // ... extension + StringUtils.compareToIgnoreCase(this.getHeadquarterHouseNumberExtension(), headquarter.getHeadquarterHouseNumberExtension()), + // ... store number + Integer.compare(this.getHeadquarterStore(), headquarter.getHeadquarterStore()), + // ... suite number + Integer.compare(this.getHeadquarterSuiteNumber(), headquarter.getHeadquarterSuiteNumber()), + // ... last email address + StringUtils.compareToIgnoreCase(this.getHeadquarterEmailAddress(), headquarter.getHeadquarterEmailAddress()) + }; + + // Check all values + final int comparison = Comparables.checkAll(comparators); + + // Return value + return comparison; + } + @Override public boolean equals (final Object object) { if (null == object) { diff --git a/src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarter.java b/src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarter.java index 92c7535..6e62e75 100644 --- a/src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarter.java +++ b/src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarter.java @@ -31,7 +31,7 @@ import org.mxchange.jusercore.model.user.User; *

* @author Roland Häder */ -public interface Headquarter extends Serializable { +public interface Headquarter extends Comparable, Serializable { /** * Getter for headquarter's city name diff --git a/src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarters.java b/src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarters.java index d43189a..2d847b9 100644 --- a/src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarters.java +++ b/src/org/mxchange/jcontactsbusiness/model/headquarter/Headquarters.java @@ -32,8 +32,35 @@ public class Headquarters implements Serializable { private static final long serialVersionUID = 69_537_867_224_651L; /** - * Checks if both headquarter have same address. This method will throw - * an {@code NullPointerException} if one of the instances is null. + * 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() + *

+ * @throws NullPointerException If first instance is null + */ + 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 headquarter is null + throw new NullPointerException("headquarter1 is null"); //NOI18N + } 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 diff --git a/src/org/mxchange/jcontactsbusiness/model/jobposition/EmployeePosition.java b/src/org/mxchange/jcontactsbusiness/model/jobposition/EmployeePosition.java index 592d078..c77c72a 100644 --- a/src/org/mxchange/jcontactsbusiness/model/jobposition/EmployeePosition.java +++ b/src/org/mxchange/jcontactsbusiness/model/jobposition/EmployeePosition.java @@ -28,6 +28,7 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; +import org.mxchange.jcoreee.utils.Comparables; /** * A POJO for job positions @@ -77,6 +78,30 @@ public class EmployeePosition implements JobPosition { @Column (name = "job_position_updated", insertable = false) private Date jobPositionUpdated; + @Override + public int compareTo (final JobPosition jobPosition) { + // For performance reasons + if (null == jobPosition) { + // Should not happen + throw new NullPointerException("jobPosition is null"); //NOI18N + } else if (Objects.equals(this, jobPosition)) { + // Same object + return 0; + } + + // Init comparisons + final int[] comparators = { + // First position name ... + this.getJobPositionName().compareToIgnoreCase(jobPosition.getJobPositionName()) + }; + + // Check all values + final int comparison = Comparables.checkAll(comparators); + + // Return value + return comparison; + } + @Override public boolean equals (final Object object) { if (this == object) { diff --git a/src/org/mxchange/jcontactsbusiness/model/jobposition/JobPosition.java b/src/org/mxchange/jcontactsbusiness/model/jobposition/JobPosition.java index e9ee417..01e2335 100644 --- a/src/org/mxchange/jcontactsbusiness/model/jobposition/JobPosition.java +++ b/src/org/mxchange/jcontactsbusiness/model/jobposition/JobPosition.java @@ -24,7 +24,7 @@ import java.util.Date; *

* @author Roland Häder */ -public interface JobPosition extends Serializable { +public interface JobPosition extends Comparable, Serializable { /** * Getter for id number diff --git a/src/org/mxchange/jcontactsbusiness/model/jobposition/JobPositions.java b/src/org/mxchange/jcontactsbusiness/model/jobposition/JobPositions.java new file mode 100644 index 0000000..b94b6f2 --- /dev/null +++ b/src/org/mxchange/jcontactsbusiness/model/jobposition/JobPositions.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2018 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 + *

+ * @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 + if (Objects.equals(jobPosition1, jobPosition2)) { + // Both are same + return 0; + } else if (null == jobPosition1) { + // First cannot be null + throw new NullPointerException("jobPosition1 is null"); //NOI18N + } 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 07604b1..26c5642 100644 --- a/src/org/mxchange/jcontactsbusiness/model/logo/BusinessLogo.java +++ b/src/org/mxchange/jcontactsbusiness/model/logo/BusinessLogo.java @@ -31,6 +31,7 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; +import org.mxchange.jcoreee.utils.Comparables; import org.mxchange.jusercore.model.user.LoginUser; import org.mxchange.jusercore.model.user.User; @@ -80,6 +81,32 @@ public class BusinessLogo implements Logo { @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false) private User logoUploader; + @Override + public int compareTo (final Logo logo) { + // For performance reasons + if (null == logo) { + // Should not happen + throw new NullPointerException("logo is null"); //NOI18N + } else if (Objects.equals(this, logo)) { + // Same object + return 0; + } + + // Init comparisons + final int[] comparators = { + // First file name ... + this.getLogoFileName().compareToIgnoreCase(logo.getLogoFileName()), + // ... then uploader instance + this.getLogoUploader().compareTo(logo.getLogoUploader()) + }; + + // Check all values + final int comparison = Comparables.checkAll(comparators); + + // Return value + return comparison; + } + @Override public boolean equals (final Object object) { if (null == object) { diff --git a/src/org/mxchange/jcontactsbusiness/model/logo/Logo.java b/src/org/mxchange/jcontactsbusiness/model/logo/Logo.java index dda0532..37940fc 100644 --- a/src/org/mxchange/jcontactsbusiness/model/logo/Logo.java +++ b/src/org/mxchange/jcontactsbusiness/model/logo/Logo.java @@ -25,7 +25,7 @@ import org.mxchange.jusercore.model.user.User; *

* @author Roland Häder */ -public interface Logo extends Serializable { +public interface Logo extends Comparable, Serializable { /** * Getter for logo's local file name diff --git a/src/org/mxchange/jcontactsbusiness/model/opening_time/BusinessOpeningTime.java b/src/org/mxchange/jcontactsbusiness/model/opening_time/BusinessOpeningTime.java index c9397f5..c84f8b4 100644 --- a/src/org/mxchange/jcontactsbusiness/model/opening_time/BusinessOpeningTime.java +++ b/src/org/mxchange/jcontactsbusiness/model/opening_time/BusinessOpeningTime.java @@ -33,6 +33,7 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; import org.mxchange.jcontactsbusiness.model.opening_time.dayofweek.DayOfTheWeek; +import org.mxchange.jcoreee.utils.Comparables; /** * A POJO for business opening hours @@ -43,7 +44,7 @@ import org.mxchange.jcontactsbusiness.model.opening_time.dayofweek.DayOfTheWeek; @Table (name = "company_opening_times") @NamedQueries ( { - @NamedQuery (name = "AllOpeningTimes", query = "SELECT ot FROM company_opening_times AS ot ORDER BY ot.openingId ASC"), + @NamedQuery (name = "AllOpeningTimes", query = "SELECT ot FROM company_opening_times AS ot ORDER BY ot.openingId ASC") } ) @SuppressWarnings ("PersistenceUnitPresent") @@ -58,8 +59,8 @@ public class BusinessOpeningTime implements OpeningTime { /** * When this opening time was created */ - @Basic(optional = false) - @Column(name = "opening_times_created", nullable = false, updatable = false) + @Basic (optional = false) + @Column (name = "opening_times_created", nullable = false, updatable = false) @Temporal (TemporalType.TIMESTAMP) private Date openingCreated; @@ -125,6 +126,33 @@ public class BusinessOpeningTime implements OpeningTime { this.openingStartTime = openingStartTime; } + @Override + public int compareTo (final OpeningTime openingTime) { + // For performance reasons + if (null == openingTime) { + // Should not happen + throw new NullPointerException("openingTime is null"); //NOI18N + } else if (Objects.equals(this, openingTime)) { + // Same object + return 0; + } + + // Init comparisons + // @TODO Also compare start and end timestamps (java.util.Date) + final int[] comparators = { + // First starting day of the week + this.getOpeningStartDay().compareTo(openingTime.getOpeningStartDay()), + // ... and end day of the week + this.getOpeningEndDay().compareTo(openingTime.getOpeningEndDay()) + }; + + // Check all values + final int comparison = Comparables.checkAll(comparators); + + // Return value + return comparison; + } + @Override public boolean equals (final Object obj) { if (this == obj) { diff --git a/src/org/mxchange/jcontactsbusiness/model/opening_time/OpeningTime.java b/src/org/mxchange/jcontactsbusiness/model/opening_time/OpeningTime.java index 130add0..a52d76b 100644 --- a/src/org/mxchange/jcontactsbusiness/model/opening_time/OpeningTime.java +++ b/src/org/mxchange/jcontactsbusiness/model/opening_time/OpeningTime.java @@ -25,7 +25,7 @@ import org.mxchange.jcontactsbusiness.model.opening_time.dayofweek.DayOfTheWeek; * * @author Roland Häder */ -public interface OpeningTime extends Serializable { +public interface OpeningTime extends Comparable, Serializable { /** * Getter for opening time created timestamp