2 * Copyright (C) 2023 Roland Häder<roland@mxchange.org>
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.
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.
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/>.
17 package org.mxchange.jjobs.model.utils;
19 import java.util.Objects;
20 import org.apache.commons.lang3.StringUtils;
21 import org.mxchange.jjobs.model.skill.Skillable;
24 * Utilities class for skills to learn and practice
26 * @author Roland Häder<roland@mxchange.org>
28 public class SkillUtils {
31 * Compares two skills with each other
33 * @param skill1 Skill instance 1
34 * @param skill2 Skill instance 2
36 * @return Comparison value
38 public static int compare (final Skillable skill1, final Skillable skill2) {
39 // Check equality, then at least first must be given
40 if (Objects.equals(skill1, skill2)) {
43 } else if (null == skill1) {
46 } else if (null == skill2) {
51 // Invoke compare() method
52 return skill1.compareTo(skill2);
56 * Copies all fields exception created/updated timestamps from source
57 * Skillable instance to target instance all fields.
59 * @param sourceSkillable Source instance of a Skillable class
60 * @param targetSkillable Target instance of a Skillable class
62 public static void copySkillData (final Skillable sourceSkillable, final Skillable targetSkillable) {
63 // Check that both parameters are not null
64 if (null == sourceSkillable) {
66 throw new NullPointerException("sourceSkillable is null"); //NOI18N
67 } else if (null == targetSkillable) {
69 throw new NullPointerException("targetSkillable is null"); //NOI18N
70 } else if (Objects.equals(sourceSkillable, targetSkillable)) {
72 throw new IllegalArgumentException("sourceSkillable and targetSkillable are the same"); //NOI18N
76 targetSkillable.setSkillId(sourceSkillable.getSkillId());
77 targetSkillable.setSkillLastLocked(sourceSkillable.getSkillLastLocked());
78 targetSkillable.setSkillName(sourceSkillable.getSkillName());
79 targetSkillable.setSkillStatus(sourceSkillable.getSkillStatus());
83 * Checks if both instances are the same
85 * @param skillable1 First instance of a Skillable class
86 * @param skillable2 Second instance of a Skillable class
88 * @return Whether they are the same
90 public static boolean isSameSkill (final Skillable skillable1, final Skillable skillable2) {
92 if (null == skillable1) {
94 throw new NullPointerException("Parameter 'skillable1' is null"); // NOI18N
95 } else if (null == skillable2) {
97 throw new NullPointerException("Parameter 'skillable2' is null"); // NOI18N
98 } else if (Objects.equals(skillable1, skillable2)) {
101 } else if (skillable1.getSkillName() == null) {
103 throw new NullPointerException("skillable1.skillName is null"); // NOI18N
104 } else if (skillable1.getSkillName().isEmpty()) {
106 throw new IllegalArgumentException("skillable1.skillName is empty"); // NOI18N
107 } else if (skillable2.getSkillName() == null) {
109 throw new NullPointerException("skillable2.skillName is null"); // NOI18N
110 } else if (skillable2.getSkillName() == null) {
112 throw new NullPointerException("skillable2.skillName is null"); // NOI18N
113 } else if (skillable2.getSkillName().isEmpty()) {
115 throw new IllegalArgumentException("skillable2.skillName is empty"); // NOI18N
116 } else if (skillable1.getSkillStatus() == null) {
118 throw new NullPointerException("skillable1.skillStatus is null"); // NOI18N
119 } else if (skillable2.getSkillStatus() == null) {
121 throw new NullPointerException("skillable2.skillStatus is null"); // NOI18N
124 // Now that all at least required fields are there, let's check them all
125 return ((StringUtils.equals(skillable1.getSkillName(), skillable2.getSkillName())) &&
126 (skillable1.getSkillStatus().equals(skillable2.getSkillStatus())));
130 * Utilities classes don't have constructors
132 private SkillUtils () {