|
|
@@ -6,8 +6,6 @@ import java.util.Map;
|
|
|
import org.leumasjaffe.charsheet.model.features.DDFeaturePredicate;
|
|
|
import org.leumasjaffe.charsheet.model.magic.DDSpell;
|
|
|
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.NonNull;
|
|
|
import lombok.SneakyThrows;
|
|
|
@@ -19,25 +17,21 @@ public class SpellMatcher implements DDFeaturePredicate {
|
|
|
@Override @SneakyThrows
|
|
|
public boolean accepts(Object value) {
|
|
|
if (!(value instanceof DDSpell)) return false;
|
|
|
- final ObjectMapper mapper = new ObjectMapper();
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- Map<String, Object> json = mapper.treeToValue(mapper.valueToTree((DDSpell) value), Map.class);
|
|
|
- for (final String key : properties.keySet()) {
|
|
|
- if (!matches(properties.get(key), json.get(key))) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
+ DDSpell spell = (DDSpell) value;
|
|
|
+ if (!accepts("school", spell.getSchool())) { return false; }
|
|
|
+ else if (!accepts("subschool", spell.getSubSchool())) { return false; }
|
|
|
+ else if (!accepts("keywords", spell.getKeywords())) { return false; }
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- private boolean matches(Object match, Object json) {
|
|
|
- if (match instanceof String) {
|
|
|
- return ((String) json).matches((String) match);
|
|
|
- } else if (match instanceof Collection) {
|
|
|
- ((Collection<String>) json).containsAll((Collection<String>) match);
|
|
|
- }
|
|
|
- return false;
|
|
|
+
|
|
|
+ private boolean accepts(String key, Collection<String> value) {
|
|
|
+ return !properties.containsKey(key) || value.contains(properties.get(key));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private boolean accepts(String key, Enum<?> value) {
|
|
|
+ return !properties.containsKey(key) || properties.get(key).equals(value.name());
|
|
|
}
|
|
|
|
|
|
}
|