From 5efa85cbfbd3c92654286245b6018f1810078556 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 23 Aug 2016 16:35:54 +0200 Subject: [PATCH] equals() is for object-comparison (entitiy included), so always include id number --- .../jcontactsbusiness/CompanyContact.java | 20 +++++++++- .../basicdata/BusinessBasicData.java | 6 +-- .../basicdata/CompanyBasicData.java | 38 +++++++++++------- .../branch/CompanyBranchOffice.java | 33 ++++++++------- .../department/CompanyDepartment.java | 23 ++++++----- .../employee/CompanyEmployee.java | 25 +++++++----- .../headquarters/CompanyHeadQuartersData.java | 33 ++++++++------- .../jobposition/EmployeePosition.java | 24 +++++------ .../jcontactsbusiness/logo/CompanyLogo.java | 26 ++++++++---- .../opening_times/BusinessOpeningTimes.java | 40 +++++++++---------- 10 files changed, 163 insertions(+), 105 deletions(-) diff --git a/src/org/mxchange/jcontactsbusiness/CompanyContact.java b/src/org/mxchange/jcontactsbusiness/CompanyContact.java index 99012d4..fa0a148 100644 --- a/src/org/mxchange/jcontactsbusiness/CompanyContact.java +++ b/src/org/mxchange/jcontactsbusiness/CompanyContact.java @@ -125,7 +125,19 @@ public class CompanyContact implements BusinessContact { final BusinessContact other = (BusinessContact) object; - return Objects.equals(this.getBasicBusinessData(), other.getBasicBusinessData()); + if (!Objects.equals(this.getCompanyContactId(), other.getCompanyContactId())) { + return false; + } else if (!Objects.equals(this.getCompanyContact(), other.getCompanyContact())) { + return false; + } else if (!Objects.equals(this.getCompanyFounder(), other.getCompanyFounder())) { + return false; + } else if (!Objects.equals(this.getBasicBusinessData(), other.getBasicBusinessData())) { + return false; + } else if (!Objects.equals(this.getHeadQuartersData(), other.getHeadQuartersData())) { + return false; + } + + return true; } @Override @@ -215,7 +227,13 @@ public class CompanyContact implements BusinessContact { @Override public int hashCode () { int hash = 3; + + hash = 37 * hash + Objects.hashCode(this.getCompanyContactId()); + hash = 37 * hash + Objects.hashCode(this.getCompanyContact()); + hash = 37 * hash + Objects.hashCode(this.getCompanyFounder()); hash = 37 * hash + Objects.hashCode(this.getBasicBusinessData()); + hash = 37 * hash + Objects.hashCode(this.getHeadQuartersData()); + return hash; } } diff --git a/src/org/mxchange/jcontactsbusiness/basicdata/BusinessBasicData.java b/src/org/mxchange/jcontactsbusiness/basicdata/BusinessBasicData.java index bc011d4..6e5e04e 100644 --- a/src/org/mxchange/jcontactsbusiness/basicdata/BusinessBasicData.java +++ b/src/org/mxchange/jcontactsbusiness/basicdata/BusinessBasicData.java @@ -175,14 +175,14 @@ public interface BusinessBasicData extends Serializable { *

* @return User owner instance */ - User getBasicUserOwner (); + User getCompanyBasicUserOwner (); /** * Setter for user owner instance *

- * @param basicUserOwner User owner instance + * @param companyBasicUserOwner User owner instance */ - void setBasicUserOwner (final User basicUserOwner); + void setCompanyBasicUserOwner (final User companyBasicUserOwner); /** * Getter for timestamp when this entry has been created diff --git a/src/org/mxchange/jcontactsbusiness/basicdata/CompanyBasicData.java b/src/org/mxchange/jcontactsbusiness/basicdata/CompanyBasicData.java index 4135815..ac26e7a 100644 --- a/src/org/mxchange/jcontactsbusiness/basicdata/CompanyBasicData.java +++ b/src/org/mxchange/jcontactsbusiness/basicdata/CompanyBasicData.java @@ -70,7 +70,7 @@ public class CompanyBasicData implements BusinessBasicData { */ @JoinColumn (name = "company_user_id", nullable = false, updatable = false) @OneToOne (targetEntity = LoginUser.class, cascade = CascadeType.REFRESH, optional = false) - private User basicUserOwner; + private User companyBasicUserOwner; /** * Id number @@ -150,26 +150,21 @@ public class CompanyBasicData implements BusinessBasicData { final BusinessBasicData other = (BusinessBasicData) object; - if (!Objects.equals(this.getCompanyLegalStatus(), other.getCompanyLegalStatus())) { + if (!Objects.equals(this.getCompanyBasicId(), other.getCompanyBasicId())) { + return false; + } else if (!Objects.equals(this.getCompanyLegalStatus(), other.getCompanyLegalStatus())) { return false; } else if (!Objects.equals(this.getCompanyName(), other.getCompanyName())) { return false; } else if (!Objects.equals(this.getCompanyTaxNumber(), other.getCompanyTaxNumber())) { return false; + } else if (!Objects.equals(this.getCompanyBasicUserOwner(), other.getCompanyBasicUserOwner())) { + return false; } return true; } - @Override - public int hashCode () { - int hash = 5; - hash = 53 * hash + Objects.hashCode(this.getCompanyLegalStatus()); - hash = 53 * hash + Objects.hashCode(this.getCompanyName()); - hash = 53 * hash + Objects.hashCode(this.getCompanyTaxNumber()); - return hash; - } - @Override @SuppressWarnings ("ReturnOfDateField") public Calendar getBasicCreated () { @@ -183,13 +178,13 @@ public class CompanyBasicData implements BusinessBasicData { } @Override - public User getBasicUserOwner () { - return this.basicUserOwner; + public User getCompanyBasicUserOwner () { + return this.companyBasicUserOwner; } @Override - public void setBasicUserOwner (final User basicUserOwner) { - this.basicUserOwner = basicUserOwner; + public void setCompanyBasicUserOwner (final User companyBasicUserOwner) { + this.companyBasicUserOwner = companyBasicUserOwner; } @Override @@ -292,4 +287,17 @@ public class CompanyBasicData implements BusinessBasicData { this.companyWebsiteUrl = companyWebsiteUrl; } + @Override + public int hashCode () { + int hash = 5; + + hash = 53 * hash + Objects.hashCode(this.getCompanyBasicId()); + hash = 53 * hash + Objects.hashCode(this.getCompanyLegalStatus()); + hash = 53 * hash + Objects.hashCode(this.getCompanyName()); + hash = 53 * hash + Objects.hashCode(this.getCompanyTaxNumber()); + hash = 53 * hash + Objects.hashCode(this.getCompanyBasicUserOwner()); + + return hash; + } + } diff --git a/src/org/mxchange/jcontactsbusiness/branch/CompanyBranchOffice.java b/src/org/mxchange/jcontactsbusiness/branch/CompanyBranchOffice.java index c352667..69e90e4 100644 --- a/src/org/mxchange/jcontactsbusiness/branch/CompanyBranchOffice.java +++ b/src/org/mxchange/jcontactsbusiness/branch/CompanyBranchOffice.java @@ -165,7 +165,9 @@ public class CompanyBranchOffice implements BranchOffice { final BranchOffice other = (BranchOffice) object; - if (!Objects.equals(this.getBranchCity(), other.getBranchCity())) { + if (!Objects.equals(this.getBranchId(), other.getBranchId())) { + return false; + } else if (!Objects.equals(this.getBranchCity(), other.getBranchCity())) { return false; } else if (!Objects.equals(this.getBranchCountry(), other.getBranchCountry())) { return false; @@ -184,19 +186,6 @@ public class CompanyBranchOffice implements BranchOffice { return true; } - @Override - public int hashCode () { - int hash = 7; - hash = 53 * hash + Objects.hashCode(this.getBranchCity()); - hash = 53 * hash + Objects.hashCode(this.getBranchCountry()); - hash = 53 * hash + Objects.hashCode(this.getBranchHouseNumber()); - hash = 53 * hash + Objects.hashCode(this.getBranchStore()); - hash = 53 * hash + Objects.hashCode(this.getBranchStreet()); - hash = 53 * hash + Objects.hashCode(this.getBranchSuiteNumber()); - hash = 53 * hash + Objects.hashCode(this.getBranchZipCode()); - return hash; - } - @Override public String getBranchCity () { return this.branchCity; @@ -339,4 +328,20 @@ public class CompanyBranchOffice implements BranchOffice { this.branchZipCode = branchZipCode; } + @Override + public int hashCode () { + int hash = 7; + + hash = 53 * hash + Objects.hashCode(this.getBranchId()); + hash = 53 * hash + Objects.hashCode(this.getBranchCity()); + hash = 53 * hash + Objects.hashCode(this.getBranchCountry()); + hash = 53 * hash + Objects.hashCode(this.getBranchHouseNumber()); + hash = 53 * hash + Objects.hashCode(this.getBranchStore()); + hash = 53 * hash + Objects.hashCode(this.getBranchStreet()); + hash = 53 * hash + Objects.hashCode(this.getBranchSuiteNumber()); + hash = 53 * hash + Objects.hashCode(this.getBranchZipCode()); + + return hash; + } + } diff --git a/src/org/mxchange/jcontactsbusiness/department/CompanyDepartment.java b/src/org/mxchange/jcontactsbusiness/department/CompanyDepartment.java index 3fb5a8c..5632166 100644 --- a/src/org/mxchange/jcontactsbusiness/department/CompanyDepartment.java +++ b/src/org/mxchange/jcontactsbusiness/department/CompanyDepartment.java @@ -127,7 +127,9 @@ public class CompanyDepartment implements Department { final Department other = (Department) object; - if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) { + if (!Objects.equals(this.getDepartmentId(), other.getDepartmentId())) { + return false; + } else if (!Objects.equals(this.getDepartmentCompany(), other.getDepartmentCompany())) { return false; } else if (!Objects.equals(this.getDepartmentName(), other.getDepartmentName())) { return false; @@ -136,14 +138,6 @@ public class CompanyDepartment implements Department { return true; } - @Override - public int hashCode () { - int hash = 5; - hash = 53 * hash + Objects.hashCode(this.getDepartmentCompany()); - hash = 53 * hash + Objects.hashCode(this.getDepartmentName()); - return hash; - } - @Override public HeadQuartersData getDepartentHeadquarters () { return this.departentHeadquarters; @@ -226,4 +220,15 @@ public class CompanyDepartment implements Department { this.departmentUserOwner = departmentUserOwner; } + @Override + public int hashCode () { + int hash = 5; + + hash = 53 * hash + Objects.hashCode(this.getDepartmentId()); + hash = 53 * hash + Objects.hashCode(this.getDepartmentCompany()); + hash = 53 * hash + Objects.hashCode(this.getDepartmentName()); + + return hash; + } + } diff --git a/src/org/mxchange/jcontactsbusiness/employee/CompanyEmployee.java b/src/org/mxchange/jcontactsbusiness/employee/CompanyEmployee.java index 5a73f08..dce162e 100644 --- a/src/org/mxchange/jcontactsbusiness/employee/CompanyEmployee.java +++ b/src/org/mxchange/jcontactsbusiness/employee/CompanyEmployee.java @@ -164,7 +164,9 @@ public class CompanyEmployee implements Employee { final Employee other = (Employee) object; - if (!Objects.equals(this.getEmployeeCompany(), other.getEmployeeCompany())) { + if (!Objects.equals(this.getEmployeeId(), other.getEmployeeId())) { + return false; + } else if (!Objects.equals(this.getEmployeeCompany(), other.getEmployeeCompany())) { return false; } else if (!Objects.equals(this.getEmployeeNumber(), other.getEmployeeNumber())) { return false; @@ -175,15 +177,6 @@ public class CompanyEmployee implements Employee { return true; } - @Override - public int hashCode () { - int hash = 3; - hash = 97 * hash + Objects.hashCode(this.getEmployeeCompany()); - hash = 97 * hash + Objects.hashCode(this.getEmployeeNumber()); - hash = 97 * hash + Objects.hashCode(this.getEmployeePersonalData()); - return hash; - } - @Override public BranchOffice getEmployeeBranchOffice () { return this.employeeBranchOffice; @@ -316,4 +309,16 @@ public class CompanyEmployee implements Employee { this.employeeUserOwner = employeeUserOwner; } + @Override + public int hashCode () { + int hash = 3; + + hash = 97 * hash + Objects.hashCode(this.getEmployeeId()); + hash = 97 * hash + Objects.hashCode(this.getEmployeeCompany()); + hash = 97 * hash + Objects.hashCode(this.getEmployeeNumber()); + hash = 97 * hash + Objects.hashCode(this.getEmployeePersonalData()); + + return hash; + } + } diff --git a/src/org/mxchange/jcontactsbusiness/headquarters/CompanyHeadQuartersData.java b/src/org/mxchange/jcontactsbusiness/headquarters/CompanyHeadQuartersData.java index 70b61f0..0e28493 100644 --- a/src/org/mxchange/jcontactsbusiness/headquarters/CompanyHeadQuartersData.java +++ b/src/org/mxchange/jcontactsbusiness/headquarters/CompanyHeadQuartersData.java @@ -150,7 +150,9 @@ public class CompanyHeadQuartersData implements HeadQuartersData { final HeadQuartersData other = (HeadQuartersData) object; - if (!Objects.equals(this.getHeadquartersCity(), other.getHeadquartersCity())) { + if (!Objects.equals(this.getHeadquartersId(), other.getHeadquartersId())) { + return false; + } else if (!Objects.equals(this.getHeadquartersCity(), other.getHeadquartersCity())) { return false; } else if (!Objects.equals(this.getHeadquartersCountry(), other.getHeadquartersCountry())) { return false; @@ -169,19 +171,6 @@ public class CompanyHeadQuartersData implements HeadQuartersData { return true; } - @Override - public int hashCode () { - int hash = 7; - hash = 47 * hash + Objects.hashCode(this.getHeadquartersCity()); - hash = 47 * hash + Objects.hashCode(this.getHeadquartersCountry()); - hash = 47 * hash + Objects.hashCode(this.getHeadquartersHouseNumber()); - hash = 47 * hash + Objects.hashCode(this.getHeadquartersStore()); - hash = 47 * hash + Objects.hashCode(this.getHeadquartersStreet()); - hash = 47 * hash + Objects.hashCode(this.getHeadquartersSuiteNumber()); - hash = 47 * hash + Objects.hashCode(this.getHeadquartersZipCode()); - return hash; - } - @Override public String getHeadquartersCity () { return this.headquartersCity; @@ -304,4 +293,20 @@ public class CompanyHeadQuartersData implements HeadQuartersData { this.headquartersZipCode = headquartersZipCode; } + @Override + public int hashCode () { + int hash = 7; + + hash = 47 * hash + Objects.hashCode(this.getHeadquartersId()); + hash = 47 * hash + Objects.hashCode(this.getHeadquartersCity()); + hash = 47 * hash + Objects.hashCode(this.getHeadquartersCountry()); + hash = 47 * hash + Objects.hashCode(this.getHeadquartersHouseNumber()); + hash = 47 * hash + Objects.hashCode(this.getHeadquartersStore()); + hash = 47 * hash + Objects.hashCode(this.getHeadquartersStreet()); + hash = 47 * hash + Objects.hashCode(this.getHeadquartersSuiteNumber()); + hash = 47 * hash + Objects.hashCode(this.getHeadquartersZipCode()); + + return hash; + } + } diff --git a/src/org/mxchange/jcontactsbusiness/jobposition/EmployeePosition.java b/src/org/mxchange/jcontactsbusiness/jobposition/EmployeePosition.java index 1ef9618..e9b08d9 100644 --- a/src/org/mxchange/jcontactsbusiness/jobposition/EmployeePosition.java +++ b/src/org/mxchange/jcontactsbusiness/jobposition/EmployeePosition.java @@ -97,25 +97,15 @@ public class EmployeePosition implements JobPosition { final JobPosition other = (JobPosition) object; - if (!Objects.equals(this.getJobPositionName(), other.getJobPositionName())) { + if (!Objects.equals(this.getJobPositionId(), other.getJobPositionId())) { return false; - } else if (!Objects.equals(this.getJobPositionId(), other.getJobPositionId())) { + } else if (!Objects.equals(this.getJobPositionName(), other.getJobPositionName())) { return false; } return true; } - @Override - public int hashCode () { - int hash = 7; - - hash = 37 * hash + Objects.hashCode(this.getJobPositionId()); - hash = 37 * hash + Objects.hashCode(this.getJobPositionName()); - - return hash; - } - @Override @SuppressWarnings ("ReturnOfDateField") public Calendar getJobPositionCreated () { @@ -160,4 +150,14 @@ public class EmployeePosition implements JobPosition { this.jobPositionUpdated = jobPositionUpdated; } + @Override + public int hashCode () { + int hash = 7; + + hash = 37 * hash + Objects.hashCode(this.getJobPositionId()); + hash = 37 * hash + Objects.hashCode(this.getJobPositionName()); + + return hash; + } + } diff --git a/src/org/mxchange/jcontactsbusiness/logo/CompanyLogo.java b/src/org/mxchange/jcontactsbusiness/logo/CompanyLogo.java index c115109..07c7a8e 100644 --- a/src/org/mxchange/jcontactsbusiness/logo/CompanyLogo.java +++ b/src/org/mxchange/jcontactsbusiness/logo/CompanyLogo.java @@ -90,14 +90,15 @@ public class CompanyLogo implements BusinessLogo { final BusinessLogo other = (BusinessLogo) object; - return Objects.equals(this.getLogoFileName(), other.getLogoFileName()); - } + if (!Objects.equals(this.getLogoId(), other.getLogoId())) { + return false; + } else if (!Objects.equals(this.getLogoUploader(), other.getLogoUploader())) { + return false; + } else if (!Objects.equals(this.getLogoFileName(), other.getLogoFileName())) { + return false; + } - @Override - public int hashCode () { - int hash = 3; - hash = 53 * hash + Objects.hashCode(this.getLogoFileName()); - return hash; + return true; } @Override @@ -142,4 +143,15 @@ public class CompanyLogo implements BusinessLogo { this.logoUploader = logoUploader; } + @Override + public int hashCode () { + int hash = 3; + + hash = 53 * hash + Objects.hashCode(this.getLogoId()); + hash = 53 * hash + Objects.hashCode(this.getLogoFileName()); + hash = 53 * hash + Objects.hashCode(this.getLogoUploader()); + + return hash; + } + } diff --git a/src/org/mxchange/jcontactsbusiness/opening_times/BusinessOpeningTimes.java b/src/org/mxchange/jcontactsbusiness/opening_times/BusinessOpeningTimes.java index d297db2..60cada6 100644 --- a/src/org/mxchange/jcontactsbusiness/opening_times/BusinessOpeningTimes.java +++ b/src/org/mxchange/jcontactsbusiness/opening_times/BusinessOpeningTimes.java @@ -96,10 +96,10 @@ public class BusinessOpeningTimes implements OpeningTimes { /** * Constructor with all field *

- * @param endDay End day - * @param endTime End time - * @param id Id number - * @param startDay Start day + * @param endDay End day + * @param endTime End time + * @param id Id number + * @param startDay Start day * @param startTime Start time */ public BusinessOpeningTimes (final DayOfWeek endDay, final Calendar endTime, final Long id, final DayOfWeek startDay, final Calendar startTime) { @@ -113,9 +113,9 @@ public class BusinessOpeningTimes implements OpeningTimes { /** * Constructor with all fields except id number *

- * @param endDay End day - * @param endTime End time - * @param startDay Start day + * @param endDay End day + * @param endTime End time + * @param startDay Start day * @param startTime Start time */ public BusinessOpeningTimes (final DayOfWeek endDay, final Calendar endTime, final DayOfWeek startDay, final Calendar startTime) { @@ -153,19 +153,6 @@ public class BusinessOpeningTimes implements OpeningTimes { return true; } - @Override - public int hashCode () { - int hash = 7; - - hash = 97 * hash + Objects.hashCode(this.getId()); - hash = 97 * hash + Objects.hashCode(this.getStartDay()); - hash = 97 * hash + Objects.hashCode(this.getEndDay()); - hash = 97 * hash + Objects.hashCode(this.getStartTime()); - hash = 97 * hash + Objects.hashCode(this.getEndTime()); - - return hash; - } - @Override public DayOfWeek getEndDay () { return this.endDay; @@ -220,4 +207,17 @@ public class BusinessOpeningTimes implements OpeningTimes { this.startTime = startTime; } + @Override + public int hashCode () { + int hash = 7; + + hash = 97 * hash + Objects.hashCode(this.getId()); + hash = 97 * hash + Objects.hashCode(this.getStartDay()); + hash = 97 * hash + Objects.hashCode(this.getEndDay()); + hash = 97 * hash + Objects.hashCode(this.getStartTime()); + hash = 97 * hash + Objects.hashCode(this.getEndTime()); + + return hash; + } + } -- 2.39.5