]> 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.Table;
30 import javax.persistence.Temporal;
31 import javax.persistence.TemporalType;
32 import javax.persistence.Transient;
33 import org.apache.commons.lang3.StringUtils;
34 import org.mxchange.jcoreutils.comparable.ComparableUtils;
35 import org.mxchange.jcoreutils.enums.EnumUtils;
36 import org.mxchange.jjobs.model.skill.status.SkillStatus;
37
38 /**
39  * A POJO entity for skills
40  * <p>
41  * @author Roland Häder<roland@mxchange.org>
42  */
43 @Entity (name = "skills")
44 @Table (
45                 name = "skills"
46 )
47 @SuppressWarnings ("PersistenceUnitPresent")
48 public class JobSkill implements Skillable {
49
50         /**
51          * Serial number
52          */
53         @Transient
54         private static final long serialVersionUID = 185435718692L;
55
56         /**
57          * When this entry has been created
58          */
59         @Basic (optional = false)
60         @Column (name = "skill_created", nullable = false, updatable = false)
61         @Temporal (TemporalType.TIMESTAMP)
62         private Date skillCreated;
63
64         /**
65          * Id number (primary key)
66          */
67         @Id
68         @GeneratedValue (strategy = GenerationType.IDENTITY)
69         @Column (name = "skill_id", nullable = false, updatable = false)
70         private Long skillId;
71
72         /**
73          * When this entry has been last locked
74          */
75         @Column (name = "skill_last_locked", insertable = false)
76         @Temporal (TemporalType.TIMESTAMP)
77         private Date skillLastLocked;
78
79         /**
80          * Skill name
81          */
82         @Basic (optional = false)
83         @Column (name = "skill_name", nullable = false, unique = true)
84         private String skillName;
85
86         /**
87          * Skill status
88          */
89         @Basic (optional = false)
90         @Enumerated (EnumType.STRING)
91         @Column (name = "skill_status", nullable = false)
92         private SkillStatus skillStatus;
93
94         /**
95          * When this entry has been updated
96          */
97         @Column (name = "skill_updated", insertable = false)
98         @Temporal (TemporalType.TIMESTAMP)
99         private Date skillUpdated;
100
101         /**
102          * Default constructor, required for the JPA.
103          */
104         public JobSkill () {
105                 // Nothing to do here
106         }
107
108         /**
109          * Constructor with required fields
110          * <p>
111          * @param skillName   Name of skill
112          * @param skillStatus Status
113          */
114         public JobSkill (final String skillName, final SkillStatus skillStatus) {
115                 // Call default constructor (always and regardless)
116                 this();
117
118                 // Validate parameter
119                 if (null == skillName) {
120                         // Throw NPE
121                         throw new NullPointerException("skillName is null"); //NOI18N
122                 } else if (skillName.isEmpty()) {
123                         // Throw IAE
124                         throw new IllegalArgumentException("skillName is empty"); //NOI18N
125                 } else if (null == skillStatus) {
126                         // Throw NPE
127                         throw new NullPointerException("skillStatus is null"); //NOI18N
128                 }
129
130                 // Set fields
131                 this.skillName = skillName;
132                 this.skillStatus = skillStatus;
133         }
134
135         @Override
136         public int compareTo (final Skillable skill) {
137                 // Checkparameter and return 0 if equal
138                 if (null == skill) {
139                         // Should not happen
140                         throw new NullPointerException("Parameter 'skill' is null"); //NOI18N
141                 } else if (Objects.equals(this, skill)) {
142                         // Same object
143                         return 0;
144                 }
145
146                 // Init comparitors
147                 final int comparitors[] = {
148                         // First compare status
149                         EnumUtils.compare(this.getSkillStatus(), skill.getSkillStatus()),
150                         // ... next name
151                         StringUtils.compare(this.getSkillName(), skill.getSkillName())
152                 };
153
154                 // Check all values
155                 final int comparison = ComparableUtils.checkAll(comparitors);
156
157                 // Return value
158                 return comparison;
159         }
160
161         @Override
162         public boolean equals (final Object object) {
163                 if (this == object) {
164                         return true;
165                 } else if (null == object) {
166                         return false;
167                 } else if (this.getClass() != object.getClass()) {
168                         return false;
169                 }
170
171                 final Skillable skill = (Skillable) object;
172
173                 if (!Objects.equals(this.getSkillStatus(), skill.getSkillStatus())) {
174                         return false;
175                 } else if (!Objects.equals(this.getSkillName(), skill.getSkillName())) {
176                         return false;
177                 } else if (!Objects.equals(this.getSkillId(), skill.getSkillId())) {
178                         return false;
179                 }
180
181                 return true;
182         }
183
184         @Override
185         @SuppressWarnings ("ReturnOfDateField")
186         public Date getSkillCreated () {
187                 return this.skillCreated;
188         }
189
190         @Override
191         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
192         public void setSkillCreated (final Date skillCreated) {
193                 this.skillCreated = skillCreated;
194         }
195
196         @Override
197         public Long getSkillId () {
198                 return this.skillId;
199         }
200
201         @Override
202         public void setSkillId (final Long skillId) {
203                 this.skillId = skillId;
204         }
205
206         @Override
207         @SuppressWarnings ("ReturnOfDateField")
208         public Date getSkillLastLocked () {
209                 return this.skillLastLocked;
210         }
211
212         @Override
213         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
214         public void setSkillLastLocked (final Date skillLastLocked) {
215                 this.skillLastLocked = skillLastLocked;
216         }
217
218         @Override
219         public String getSkillName () {
220                 return this.skillName;
221         }
222
223         @Override
224         public void setSkillName (final String skillName) {
225                 this.skillName = skillName;
226         }
227
228         @Override
229         public SkillStatus getSkillStatus () {
230                 return this.skillStatus;
231         }
232
233         @Override
234         public void setSkillStatus (final SkillStatus skillStatus) {
235                 this.skillStatus = skillStatus;
236         }
237
238         @Override
239         @SuppressWarnings ("ReturnOfDateField")
240         public Date getSkillUpdated () {
241                 return this.skillUpdated;
242         }
243
244         @Override
245         @SuppressWarnings ("AssignmentToDateFieldFromParameter")
246         public void setSkillUpdated (final Date skillUpdated) {
247                 this.skillUpdated = skillUpdated;
248         }
249
250         @Override
251         public int hashCode () {
252                 int hash = 7;
253
254                 hash = 97 * hash + Objects.hashCode(this.getSkillId());
255                 hash = 97 * hash + Objects.hashCode(this.getSkillName());
256                 hash = 97 * hash + Objects.hashCode(this.getSkillStatus());
257
258                 return hash;
259         }
260
261 }