]> git.mxchange.org Git - jjobs-core.git/blob - src/org/mxchange/jjobs/model/utils/SkillUtils.java
2a57e2ec270e0ae603fa43ee65e73cbb374d0ff5
[jjobs-core.git] / src / org / mxchange / jjobs / model / utils / SkillUtils.java
1 /*
2  * Copyright (C) 2023 Roland Häder<roland@mxchange.org>
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.utils;
18
19 import java.util.Objects;
20 import org.mxchange.jjobs.model.skill.Skillable;
21
22 /**
23  * Utilities class for skills to learn and practice
24  * <p>
25  * @author Roland Häder<roland@mxchange.org>
26  */
27 public class SkillUtils {
28
29         /**
30          * Compares two skills with each other
31          * <p>
32          * @param skill1 Skill instance 1
33          * @param skill2 Skill instance 2
34          * <p>
35          * @return Comparison value
36          */
37         public static int compare (final Skillable skill1, final Skillable skill2) {
38                 // Check equality, then at least first must be given
39                 if (Objects.equals(skill1, skill2)) {
40                         // Both are same
41                         return 0;
42                 } else if (null == skill1) {
43                         // First is null
44                         return -1;
45                 } else if (null == skill2) {
46                         // Second is null
47                         return 1;
48                 }
49
50                 // Invoke compare() method
51                 return skill1.compareTo(skill2);
52         }
53
54         /**
55          * Copies all fields exception created/updated timestamps from source
56          * Skillable instance to target instance all fields.
57          * <p>
58          * @param sourceSkillable Source instance of a Skillable class
59          * @param targetSkillable Target instance of a Skillable class
60          */
61         public static void copySkillData (final Skillable sourceSkillable, final Skillable targetSkillable) {
62                 // Check that both parameters are not null
63                 if (null == sourceSkillable) {
64                         // Throw NPE
65                         throw new NullPointerException("sourceSkillable is null"); //NOI18N
66                 } else if (null == targetSkillable) {
67                         // Throw NPE
68                         throw new NullPointerException("targetSkillable is null"); //NOI18N
69                 } else if (Objects.equals(sourceSkillable, targetSkillable)) {
70                         // Throw IAE
71                         throw new IllegalArgumentException("sourceSkillable and targetSkillable are the same"); //NOI18N
72                 }
73
74                 // Copy all fields
75                 targetSkillable.setSkillId(sourceSkillable.getSkillId());
76                 targetSkillable.setSkillLastLocked(sourceSkillable.getSkillLastLocked());
77                 targetSkillable.setSkillName(sourceSkillable.getSkillName());
78                 targetSkillable.setSkillStatus(sourceSkillable.getSkillStatus());
79         }
80
81         /**
82          * Utilities classes don't have constructors
83          */
84         private SkillUtils () {
85         }
86 }