From: Roland Häder Date: Tue, 11 Feb 2020 15:09:19 +0000 (+0100) Subject: Please cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8f3f99e03151d1ac98e62ea0b0ef16df3bbc6249;p=jjobs-core.git Please cherry-pick: - added default construtors - added constructors with required entity properties - added missing equals()/hashCode() methods (ALWAYS implement both!) --- diff --git a/src/org/mxchange/jjobs/model/jobskill/JobPositionSkill.java b/src/org/mxchange/jjobs/model/jobskill/JobPositionSkill.java index d7607ee..872a383 100644 --- a/src/org/mxchange/jjobs/model/jobskill/JobPositionSkill.java +++ b/src/org/mxchange/jjobs/model/jobskill/JobPositionSkill.java @@ -90,13 +90,12 @@ public class JobPositionSkill implements SkillableJobPosition { /** * Link to skill entity */ - @JoinColumn(name = "skill_job_skill_id", nullable = false,updatable = false, referencedColumnName = "skill_id") + @JoinColumn (name = "skill_job_skill_id", nullable = false, updatable = false, referencedColumnName = "skill_id") @OneToOne (cascade = CascadeType.REFRESH, targetEntity = JobSkill.class) private Skillable jobSkill; /** - * User added this skill (optional as administrators can add skills, - * too) + * User added this skill (optional as administrators can add skills, too) */ @JoinColumn (name = "skill_job_user_id", referencedColumnName = "user_id") @OneToOne (cascade = CascadeType.REFRESH, targetEntity = LoginUser.class) @@ -109,6 +108,30 @@ public class JobPositionSkill implements SkillableJobPosition { @Column (name = "skill_job_importance", nullable = false) private Short skillImportance; + /** + * Default constructor, required for the JPA. + */ + public JobPositionSkill () { + // Nothing to do here + } + + /** + * Constructor with all required entity properties + *

+ * @param jobPosition An instance of a HireableJobPosition class + * @param jobSkill An instance of a Skillable class + * @param skillImportance Importance level + */ + public JobPositionSkill (final HireableJobPosition jobPosition, final Skillable jobSkill, final Short skillImportance) { + // Invoke default constructor + this(); + + // Set fields + this.jobPosition = jobPosition; + this.jobSkill = jobSkill; + this.skillImportance = skillImportance; + } + @Override public boolean equals (final Object object) { if (this == object) { @@ -119,11 +142,15 @@ public class JobPositionSkill implements SkillableJobPosition { return false; } - final SkillableJobPosition other = (SkillableJobPosition) object; + final SkillableJobPosition jobPosition = (SkillableJobPosition) object; - if (!Objects.equals(this.getJobPositionSkillId(), other.getJobPositionSkillId())) { + if (!Objects.equals(this.getSkillImportance(), jobPosition.getSkillImportance())) { return false; - } else if (!Objects.equals(this.getSkillImportance(), other.getSkillImportance())) { + } else if (!Objects.equals(this.getJobPosition(), jobPosition.getJobPosition())) { + return false; + } else if (!Objects.equals(this.getJobSkill(), jobPosition.getJobSkill())) { + return false; + } else if (!Objects.equals(this.getJobPositionSkillId(), jobPosition.getJobPositionSkillId())) { return false; } @@ -208,8 +235,10 @@ public class JobPositionSkill implements SkillableJobPosition { public int hashCode () { int hash = 5; - hash = 41 * hash + Objects.hashCode(this.getJobPositionSkillId()); + hash = 41 * hash + Objects.hashCode(this.getJobPosition()); + hash = 41 * hash + Objects.hashCode(this.getJobSkill()); hash = 41 * hash + Objects.hashCode(this.getSkillImportance()); + hash = 41 * hash + Objects.hashCode(this.getJobPositionSkillId()); return hash; } diff --git a/src/org/mxchange/jjobs/model/skill/JobSkill.java b/src/org/mxchange/jjobs/model/skill/JobSkill.java index f1dda2c..f3774ba 100644 --- a/src/org/mxchange/jjobs/model/skill/JobSkill.java +++ b/src/org/mxchange/jjobs/model/skill/JobSkill.java @@ -95,6 +95,40 @@ public class JobSkill implements Skillable { @Temporal (TemporalType.TIMESTAMP) private Date skillUpdated; + /** + * Default constructor, required for the JPA. + */ + public JobSkill () { + // Nothing to do here + } + + /** + * Constructor with required fields + *

+ * @param skillName Name of skill + * @param skillStatus Status + */ + public JobSkill (final String skillName, final SkillStatus skillStatus) { + // Call default constructor (always and regardless) + this(); + + // Validate parameter + if (null == skillName) { + // Throw NPE + throw new NullPointerException("skillName is null"); //NOI18N + } else if (skillName.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("skillName is empty"); //NOI18N + } else if (null == skillStatus) { + // Throw NPE + throw new NullPointerException("skillStatus is null"); //NOI18N + } + + // Set fields + this.skillName = skillName; + this.skillStatus = skillStatus; + } + @Override public boolean equals (final Object object) { if (this == object) { @@ -105,11 +139,13 @@ public class JobSkill implements Skillable { return false; } - final Skillable other = (Skillable) object; + final Skillable skill = (Skillable) object; - if (!Objects.equals(this.getSkillName(), other.getSkillName())) { + if (!Objects.equals(this.getSkillStatus(), skill.getSkillStatus())) { + return false; + } else if (!Objects.equals(this.getSkillName(), skill.getSkillName())) { return false; - } else if (!Objects.equals(this.getSkillId(), other.getSkillId())) { + } else if (!Objects.equals(this.getSkillId(), skill.getSkillId())) { return false; } @@ -188,6 +224,7 @@ public class JobSkill implements Skillable { hash = 97 * hash + Objects.hashCode(this.getSkillId()); hash = 97 * hash + Objects.hashCode(this.getSkillName()); + hash = 97 * hash + Objects.hashCode(this.getSkillStatus()); return hash; } diff --git a/src/org/mxchange/jjobs/model/user/skills/UserSkill.java b/src/org/mxchange/jjobs/model/user/skills/UserSkill.java index 326dd82..b4b61c6 100644 --- a/src/org/mxchange/jjobs/model/user/skills/UserSkill.java +++ b/src/org/mxchange/jjobs/model/user/skills/UserSkill.java @@ -19,6 +19,7 @@ package org.mxchange.jjobs.model.user.skills; import org.mxchange.jjobs.model.skill.JobSkill; import org.mxchange.jjobs.model.skill.Skillable; import java.util.Date; +import java.util.Objects; import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -88,6 +89,71 @@ public class UserSkill implements SkillableUser { @Temporal (TemporalType.TIMESTAMP) private Date userSkillUpdated; + /** + * Default constructor, required for the EJB + */ + public UserSkill () { + // Empty by default + } + + /** + * Constructor with all required entity properties + *

+ * @param jobSkill An instance of a Skillable class + * @param skillUser An instance of a User class + */ + public UserSkill (final Skillable jobSkill, final User skillUser) { + // Invoke default constructor + this(); + + // Validate parameter + if (null == jobSkill) { + // Throw NPE + throw new NullPointerException("jobSkill is null"); //NOI18N + } else if (null == skillUser) { + // Throw NPE + throw new NullPointerException("skillUser is null"); //NOI18N + } + + // Set fields + this.jobSkill = jobSkill; + this.skillUser = skillUser; + } + + @Override + public boolean equals (final Object object) { + if (this == object) { + return true; + } else if (object == null) { + return false; + } else if (getClass() != object.getClass()) { + return false; + } + + final SkillableUser skillableUser = (SkillableUser) object; + + if (!Objects.equals(this.getJobSkill(), skillableUser.getJobSkill())) { + return false; + } else if (!Objects.equals(this.getSkillUser(), skillableUser.getSkillUser())) { + return false; + } else if (!Objects.equals(this.getUserSkillId(), skillableUser.getUserSkillId())) { + return false; + } + + return true; + } + + @Override + public int hashCode () { + int hash = 7; + + hash = 17 * hash + Objects.hashCode(this.getJobSkill()); + hash = 17 * hash + Objects.hashCode(this.getSkillUser()); + hash = 17 * hash + Objects.hashCode(this.getUserSkillId()); + + return hash; + } + @Override public Skillable getJobSkill () { return this.jobSkill;