From 9365cf808c140d14ceda2b04c3bcd635eed75a1e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 21 Jan 2023 10:05:54 +0100 Subject: [PATCH] Continued: - always (null == variable) to avoid accidental assignments - okay, Java doesn't support this anyway, maybe I just took this over from PHP? - also always invoke simplier constructors --- .../model/basicdata/BusinessBasicData.java | 5 ++- .../headquarter/BusinessHeadquarter.java | 2 +- .../model/jobposition/EmployeePosition.java | 38 +++++++++++++++++++ .../model/logo/BusinessLogo.java | 3 +- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java b/src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java index 38308b7..f4d4047 100644 --- a/src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java +++ b/src/org/mxchange/jcontactsbusiness/model/basicdata/BusinessBasicData.java @@ -206,8 +206,11 @@ public class BusinessBasicData implements BasicData { * @param companyShortName Company short name */ public BusinessBasicData (final String companyShortName) { + // Call other constructor + this(); + // First, validate all parameter - if (companyShortName == null) { + if (null == companyShortName) { // Is null throw new NullPointerException("companyShortName is null"); //NOI18N } else if (companyShortName.isEmpty()) { diff --git a/src/org/mxchange/jcontactsbusiness/model/headquarter/BusinessHeadquarter.java b/src/org/mxchange/jcontactsbusiness/model/headquarter/BusinessHeadquarter.java index 386f25b..8cae86b 100644 --- a/src/org/mxchange/jcontactsbusiness/model/headquarter/BusinessHeadquarter.java +++ b/src/org/mxchange/jcontactsbusiness/model/headquarter/BusinessHeadquarter.java @@ -239,7 +239,7 @@ public class BusinessHeadquarter implements Headquarter { this(); // First, validate all parameter - if (headquarterCompanyName == null) { + if (null == headquarterCompanyName) { // Is null throw new NullPointerException("headquarterCompanyName is null"); //NOI18N } else if (headquarterCompanyName.isEmpty()) { diff --git a/src/org/mxchange/jcontactsbusiness/model/jobposition/EmployeePosition.java b/src/org/mxchange/jcontactsbusiness/model/jobposition/EmployeePosition.java index b94ed3c..e9cd81f 100644 --- a/src/org/mxchange/jcontactsbusiness/model/jobposition/EmployeePosition.java +++ b/src/org/mxchange/jcontactsbusiness/model/jobposition/EmployeePosition.java @@ -132,6 +132,44 @@ public class EmployeePosition implements HireableJobPosition { @Enumerated (EnumType.STRING) private JobPositionStatus jobPositionStatus; + /** + * Default constructor is for the entity manager + */ + public EmployeePosition () { + } + + /** + * Constructor with all mandatory entity properties + *

+ * @param jobPositionName Job name + * @param jobPositionStart When the job starts + * @param jobPositionStatus Status of the job + */ + public EmployeePosition (final String jobPositionName, final Date jobPositionStart, final JobPositionStatus jobPositionStatus) { + // Invoke simplier constructor + this(); + + // Validate all parameter + if (null == jobPositionName) { + // Throw NPE + throw new NullPointerException("Parameter 'jobPositionName' is null"); //NOI18N + } else if (jobPositionName.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("Parameter 'jobPositionName' is empty"); //NOI18N + } else if (null == jobPositionStart) { + // Throw NPE again + throw new NullPointerException("Parameter 'jobPositionStart' is null"); //NOI18N + } else if (null == jobPositionStatus) { + // Throw it again + throw new NullPointerException("Parameter 'jobPositionStatus' is null"); //NOI18N + } + + // Set all parameter + this.jobPositionName = jobPositionName; + this.jobPositionStart = jobPositionStart; + this.jobPositionStatus = jobPositionStatus; + } + @Override public int compareTo (final HireableJobPosition jobPosition) { // Check parameter on null-reference and equality to this diff --git a/src/org/mxchange/jcontactsbusiness/model/logo/BusinessLogo.java b/src/org/mxchange/jcontactsbusiness/model/logo/BusinessLogo.java index 3ff722a..cae9b72 100644 --- a/src/org/mxchange/jcontactsbusiness/model/logo/BusinessLogo.java +++ b/src/org/mxchange/jcontactsbusiness/model/logo/BusinessLogo.java @@ -103,11 +103,10 @@ public class BusinessLogo implements Logo { // Init comparisons final int[] comparators = { - // First file name ... // First file name ... StringUtils.compareIgnoreCase(this.getLogoFileName(), logo.getLogoFileName()), // ... then uploader instance -UserUtils.compare(this.getLogoUploaderUser(), logo.getLogoUploaderUser()) + UserUtils.compare(this.getLogoUploaderUser(), logo.getLogoUploaderUser()) }; // Check all values -- 2.39.5