-
Notifications
You must be signed in to change notification settings - Fork 1
/
PredicateManagerDefault.java
49 lines (42 loc) · 1.38 KB
/
PredicateManagerDefault.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package io.github.thiagolvlsantos.json.predicate.impl;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import io.github.thiagolvlsantos.git.commons.properties.PropertyUtils;
import io.github.thiagolvlsantos.json.predicate.IPredicate;
import io.github.thiagolvlsantos.json.predicate.IPredicateManager;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class PredicateManagerDefault implements IPredicateManager {
private Map<String, Class<? extends IPredicate>> map = new LinkedHashMap<>();
@SuppressWarnings("unchecked")
@SneakyThrows
public PredicateManagerDefault() {
Properties p = PropertyUtils.merged("json-predicate.properties");
for (Entry<Object, Object> e : p.entrySet()) {
String[] ops = String.valueOf(e.getKey()).split(",");
Class<?> type = Class.forName(String.valueOf(e.getValue()));
for (String op : ops) {
log.trace("OP:{}, CLASS:{}", op, type);
put(op, (Class<? extends IPredicate>) type);
}
}
log.info("OPS:{}", map);
}
@Override
public void put(String id, Class<? extends IPredicate> clazz) {
if (id == null) {
throw new IllegalArgumentException("Id cannot be null.");
}
map.put(id.toLowerCase(), clazz);
}
@Override
public Class<? extends IPredicate> get(String id) {
if (id == null) {
return null;
}
return map.get(id.toLowerCase());
}
}