2013-02-25 22:43:37 +01:00
|
|
|
package com.gmail.nossr50.skills.child;
|
|
|
|
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
|
|
|
|
2013-02-25 22:43:37 +01:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
public class FamilyTree {
|
2019-01-13 08:54:53 +01:00
|
|
|
private static HashMap<PrimarySkillType, Set<PrimarySkillType>> tree = new HashMap<PrimarySkillType, Set<PrimarySkillType>>();
|
2013-02-25 22:43:37 +01:00
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
public static Set<PrimarySkillType> getParents(PrimarySkillType childSkill) {
|
2013-02-25 22:43:37 +01:00
|
|
|
enforceChildSkill(childSkill);
|
|
|
|
|
|
|
|
// We do not check if we have the child skill in question, as not having it would mean we did something wrong, and an NPE is desired.
|
|
|
|
return tree.get(childSkill);
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
protected static void registerParent(PrimarySkillType childSkill, PrimarySkillType parentSkill) {
|
2013-02-25 22:43:37 +01:00
|
|
|
enforceChildSkill(childSkill);
|
|
|
|
enforceNotChildSkill(parentSkill);
|
|
|
|
|
|
|
|
if (!tree.containsKey(childSkill)) {
|
2019-01-13 08:54:53 +01:00
|
|
|
tree.put(childSkill, EnumSet.noneOf(PrimarySkillType.class));
|
2013-02-25 22:43:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
tree.get(childSkill).add(parentSkill);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static void closeRegistration() {
|
2019-01-13 08:54:53 +01:00
|
|
|
for (PrimarySkillType childSkill : tree.keySet()) {
|
|
|
|
Set<PrimarySkillType> immutableSet = Collections.unmodifiableSet(tree.get(childSkill));
|
2013-02-25 22:43:37 +01:00
|
|
|
tree.put(childSkill, immutableSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-28 00:46:19 +02:00
|
|
|
protected static void clearRegistrations() {
|
|
|
|
tree.clear();
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
protected static void enforceChildSkill(PrimarySkillType skill) {
|
2013-02-25 22:43:37 +01:00
|
|
|
if (!skill.isChildSkill()) {
|
|
|
|
throw new IllegalArgumentException(skill.name() + " is not a child skill!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-13 08:54:53 +01:00
|
|
|
protected static void enforceNotChildSkill(PrimarySkillType skill) {
|
2013-02-25 22:43:37 +01:00
|
|
|
if (skill.isChildSkill()) {
|
|
|
|
throw new IllegalArgumentException(skill.name() + " is a child skill!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|