| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package org.leumasjaffe.charsheet.model.skill;
- import java.util.Collection;
- import java.util.Collections;
- import java.util.Map;
- import java.util.TreeMap;
- import java.util.stream.Collectors;
- import org.leumasjaffe.observer.Observable;
- import com.fasterxml.jackson.annotation.JsonCreator;
- import com.fasterxml.jackson.annotation.JsonValue;
- import lombok.AccessLevel;
- import lombok.experimental.FieldDefaults;
- @FieldDefaults(level=AccessLevel.PRIVATE, makeFinal=true)
- public class DDSkills extends Observable.Instance {
- Map<String, DDSkill> skills = new TreeMap<>();
-
- @JsonCreator
- public DDSkills(Collection<DDSkill> in) {
- skills.putAll(DDSkillPrototype.all().collect(Collectors.toMap(t -> t.getName(), t -> new DDSkill(t))));
- skills.putAll(in.stream().collect(Collectors.toMap(t -> t.getName(), t -> t)));
- }
-
- @JsonValue
- private Collection<DDSkill> getSerial() {
- return skills.values().stream().filter(s -> s.getPointsSpent() > 0).collect(Collectors.toList());
- }
- public Collection<DDSkill> getSkills() {
- return Collections.unmodifiableCollection(skills.values());
- }
- public DDSkill getSkill(String name) {
- skills.computeIfAbsent(name, DDSkill::new);
- return skills.get(name);
- }
-
- public void removeSkill(DDSkill skill) {
- final DDSkill removed = skills.get(skill.getName());
- if (removed != null && !skill.equals(removed)) {
- throw new IllegalArgumentException("Attempting to remove a skill (" + skill.getName() + ") not in the object");
- }
- skills.remove(skill.getName());
- }
- }
|