]> git.mxchange.org Git - jjobs-core.git/blob - src/org/mxchange/jjobs/model/skill/JobSkill.java
Continued:
[jjobs-core.git] / src / org / mxchange / jjobs / model / skill / JobSkill.java
1 /*
2  * Copyright (C) 2016 - 2022 Free Software Foundation
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jjobs.model.skill;
18
19 import java.util.Date;
20 import java.util.Objects;
21 import javax.persistence.Basic;
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.EnumType;
25 import javax.persistence.Enumerated;
26 import javax.persistence.GeneratedValue;
27 import javax.persistence.GenerationType;
28 import javax.persistence.Id;
29 import javax.persistence.NamedQueries;
30 import javax.persistence.NamedQuery;
31 import javax.persistence.Table;
32 import javax.persistence.Temporal;
33 import javax.persistence.TemporalType;
34 import javax.persistence.Transient;
35 import org.apache.commons.lang3.StringUtils;
36 import org.mxchange.jcoreutils.comparable.ComparableUtils;
37 import org.mxchange.jcoreutils.enums.EnumUtils;
38 import org.mxchange.jjobs.model.skill.status.SkillStatus;
39
40 /**
41  * A POJO entity for skills
42  * <p>
43  * @author Roland Häder<roland@mxchange.org>
44  */
45 @Entity (name = "skills")
46 @Table (
47                 name = "skills"
48 )
49 @NamedQueries (
50                 @NamedQuery (name = "AllSkills", query = "SELECT s FROM skills AS s ORDER BY s.skillId")
51 )
52 @SuppressWarnings ("PersistenceUnitPresent")
53 public class JobSkill implements Skillable {
54
55         /**
56          * Serial number
57          */
58         @Transient
59         private static final long serialVersionUID = 185_435_718_692L;
60
61         /**
62          * When this entry has been created
63          */
64         @Basic (optional = false)
65         @Column (name = "skill_entry_created", nullable = false, updatable = false)
66         @Temporal (TemporalType.TIMESTAMP)
67         private Date skillEntryCreated;
68
69         /**
70          * When this entry has been updated
71          */
72         @Column (name = "skill_entry_updated", insertable = false)
73         @Temporal (TemporalType.TIMESTAMP)
74         private Date skillEntryUpdated;
75
76         /**
77          * Id number (primary key)
78          */
79         @Id
80         @GeneratedValue (strategy = GenerationType.IDENTITY)
81         @Column (name = "skill_id", nullable = false, updatable = false)
82         private Long skillId;
83
84         /**
85          * When this entry has been last locked
86          */
87         @Column (name = "skill_last_locked", insertable = false)
88         @Temporal (TemporalType.TIMESTAMP)
89         private Date skillLastLocked;
90
91         /**
92          * Skill name
93          */
94         @Basic (optional = false)
95         @Column (name = "skill_name", nullable = false, unique = true)
96         private String skillName;
97
98         /**
99          * Skill status
100          */
101         @Basic (optional = false)
102         @Enumerated (EnumType.STRING)
103         @Column (name = "skill_status", nullable = false)
104         private SkillStatus skillStatus;
105
106         /**
107          * Default constructor, required for the JPA.
108          */
109         public JobSkill () {
110                 // Nothing to do here
111         }
112
113         /**
114          * Constructor with required fields
115          * <p>
116          * @param skillName   Name of skill
117          * @param skillStatus Status
118          */
119         public JobSkill (final String skillName, final SkillStatus skillStatus) {
120                 // Call default constructor (always and regardless)
121                 this();
122
123                 // Validate parameter
124                 if (null == skillName) {
125                         // Throw NPE
126                         throw new NullPointerException("skillName is null"); //NOI18N
127                 } else if (skillName.isEmpty()) {
128                         // Throw IAE
129                         throw new IllegalArgumentException("skillName is empty"); //NOI18N
130                 } else if (null == skillStatus) {
131                         // Throw NPE
132                         throw new NullPointerException("skillStatus is null"); //NOI18N
133                 }
134
135                 // Set fields
136                 this.skillName = skillName;
137                 this.skillStatus = skillStatus;
138         }
139
140         @Override
141         public int compareTo (final Skillable skill) {
142                 // Checkparameter and return 0 if equal
143                 if (null == skill) {
144                         // Should not happen
145                         throw new NullPointerException("Parameter 'skill' is null"); //NOI18N
146                 } else if (Objects.equals(this, skill)) {
147                         // Same object
148                         return 0;
149                 }
150
151                 // Init comparitors
152                 final int comparitors[] = {
153                         // First compare status
154                         EnumUtils.compare(this.getSkillStatus(), skill.getSkillStatus()),
155                         // ... next name
156                         StringUtils.compare(this.getSkillName(), skill.getSkillName())
157                 };
158
159                 // Check all values
160                 final int comparison = ComparableUtils.checkAll(comparitors);
161
162                 // Return value
163                 return comparison;
164         }
165
166         @Override
167         public boolean equals (final Object object) {
168                 if (this == object) {
169                         return true;
170                 } else if (null == object) {
171                         return false;
172                 } else if (this.getClass() != object.getClass()) {
173                         return false;
174                 }
175
176                 final Skillable skill = (Skillable) object;
177
178                 if (!Objects.equals(this.getSkillStatus(), skill.getSkillStatus())) {
179                         return false;
180                 } else if (!Objects.equals(this.getSkillName(), skill.getSkillName())) {
181                         return false;
182                 } else if (!Objects.equals(this.getSkillId(), skill.getSkillId())) {
183                         return false;
184                 }
185
186                 return true;
187         }
188
189         @Override
190         @SuppressWarnings ("ReturnOfDateField")
191         public Date getSkillEntryCreated () {
192                 return this.skillEntryCreated;
193         }
194
195         @Override
196         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
197         public void setSkillEntryCreated (final Date skillEntryCreated) {
198                 this.skillEntryCreated = skillEntryCreated;
199         }
200
201         @Override
202         @SuppressWarnings ("ReturnOfDateField")
203         public Date getSkillEntryUpdated () {
204                 return this.skillEntryUpdated;
205         }
206
207         @Override
208         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
209         public void setSkillEntryUpdated (final Date skillEntryUpdated) {
210                 this.skillEntryUpdated = skillEntryUpdated;
211         }
212
213         @Override
214         public Long getSkillId () {
215                 return this.skillId;
216         }
217
218         @Override
219         public void setSkillId (final Long skillId) {
220                 this.skillId = skillId;
221         }
222
223         @Override
224         @SuppressWarnings ("ReturnOfDateField")
225         public Date getSkillLastLocked () {
226                 return this.skillLastLocked;
227         }
228
229         @Override
230         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
231         public void setSkillLastLocked (final Date skillLastLocked) {
232                 this.skillLastLocked = skillLastLocked;
233         }
234
235         @Override
236         public String getSkillName () {
237                 return this.skillName;
238         }
239
240         @Override
241         public void setSkillName (final String skillName) {
242                 this.skillName = skillName;
243         }
244
245         @Override
246         public SkillStatus getSkillStatus () {
247                 return this.skillStatus;
248         }
249
250         @Override
251         public void setSkillStatus (final SkillStatus skillStatus) {
252                 this.skillStatus = skillStatus;
253         }
254
255         @Override
256         public int hashCode () {
257                 int hash = 7;
258
259                 hash = 97 * hash + Objects.hashCode(this.getSkillId());
260                 hash = 97 * hash + Objects.hashCode(this.getSkillName());
261                 hash = 97 * hash + Objects.hashCode(this.getSkillStatus());
262
263                 return hash;
264         }
265
266 }