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
${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
${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
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-public interface BasicData extends Serializable {
+public interface BasicData extends Comparable<BasicData>, Serializable {
/**
* Getter for branches list
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;
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) {
*/
private static final long serialVersionUID = 69_537_867_224_651L;
+ /**
+ * Compares both branch office instances. This method returns -1 if second
+ * instance is null.
+ * <p>
+ * @param branchOffice1 Branch office instance 1
+ * @param branchOffice2 Branch office instance 2
+ * <p>
+ * @return Comparison value
+ * <p>
+ * @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.
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;
@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 ...
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
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;
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) {
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
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-public interface Department extends Serializable {
+public interface Department extends Comparable<Department>, Serializable {
/**
* Getter for connection to business contact
*/
private static final long serialVersionUID = 20_154_686_786_561L;
+ /**
+ * Compares both department instances. This method returns -1 if second
+ * instance is null.
+ * <p>
+ * @param department1 Department instance 1
+ * @param department2 Department instance 2
+ * <p>
+ * @return Comparison value
+ * <p>
+ * @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.
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;
@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)
*/
@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
*/
private Department employeeDepartment;
/**
- * Employable's email address
+ * Employee's email address
*/
@Column (name = "employee_email_address", length = 30)
private String employeeEmailAddress;
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
*/
}
// 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) {
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;
}
@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
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;
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;
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());
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-public interface Employable extends Serializable {
+public interface Employable extends Comparable<Employable>, Serializable {
/**
* Getter for employee's branch office
* <p>
* @return Company instance
*/
- BasicData getEmployeeCompany ();
+ BasicData getEmployeeBasicData ();
/**
* Setter for employee's company
* <p>
* @param employeeCompany Company instance
*/
- void setEmployeeCompany (final BasicData employeeCompany);
+ void setEmployeeBasicData (final BasicData employeeCompany);
/**
* Getter for employee's department
* <p>
* @return Employable's position
*/
- JobPosition getEmployeePosition ();
+ JobPosition getEmployeeJobPosition ();
/**
* Setter for employee's position
* <p>
* @param employeePosition Employable's position
*/
- void setEmployeePosition (final JobPosition employeePosition);
+ void setEmployeeJobPosition (final JobPosition employeePosition);
/**
* Getter for user owner instance
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
} 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
}
// 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())) {
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;
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) {
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-public interface Headquarter extends Serializable {
+public interface Headquarter extends Comparable<Headquarter>, Serializable {
/**
* Getter for headquarter's city name
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.
+ * <p>
+ * @param headquarter1 Headquarter 1
+ * @param headquarter2 Headquarter 2
+ * <p>
+ * @return Comparison value from invoking Comparable.compareTo()
+ * <p>
+ * @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.
* <p>
* @param headquarter1 Headquarter 1
* @param headquarter2 Headquarter 2
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
+import org.mxchange.jcoreee.utils.Comparables;
/**
* A POJO for job positions
@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) {
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-public interface JobPosition extends Serializable {
+public interface JobPosition extends Comparable<JobPosition>, Serializable {
/**
* Getter for id number
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jcontactsbusiness.model.jobposition;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+/**
+ * Utilities class for job positions
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+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.
+ * <p>
+ * @param jobPosition1 Job position instance 1
+ * @param jobPosition2 Job position instance 2
+ * <p>
+ * @return Comparison value
+ * <p>
+ * @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
+ }
+
+}
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;
@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) {
* <p>
* @author Roland Häder<roland@mxchange.org>
*/
-public interface Logo extends Serializable {
+public interface Logo extends Comparable<Logo>, Serializable {
/**
* Getter for logo's local file name
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
@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")
/**
* 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;
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) {
*
* @author Roland Häder<roland@mxchange.org>
*/
-public interface OpeningTime extends Serializable {
+public interface OpeningTime extends Comparable<OpeningTime>, Serializable {
/**
* Getter for opening time created timestamp