-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathPrerequisitesMatcher.java
More file actions
62 lines (51 loc) · 2.01 KB
/
PrerequisitesMatcher.java
File metadata and controls
62 lines (51 loc) · 2.01 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
package io.split.engine.matchers;
import io.split.client.dtos.Prerequisites;
import io.split.engine.evaluator.EvaluationContext;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
public class PrerequisitesMatcher implements Matcher {
private List<Prerequisites> _prerequisites;
public PrerequisitesMatcher(List<Prerequisites> prerequisites) {
_prerequisites = prerequisites;
}
@Override
public boolean match(Object matchValue, String bucketingKey, Map<String, Object> attributes, EvaluationContext evaluationContext) {
if (matchValue == null) {
return false;
}
if (!(matchValue instanceof String)) {
return false;
}
for (Prerequisites prerequisites : _prerequisites) {
String treatment = evaluationContext.getEvaluator().evaluateFeature((String) matchValue, bucketingKey,
prerequisites.featureFlagName, attributes). treatment;
if (!prerequisites.treatments.contains(treatment)) {
return false;
}
}
return true;
}
@Override
public String toString() {
StringBuilder bldr = new StringBuilder();
bldr.append("prerequisites: ");
bldr.append(this._prerequisites.stream().map(pr -> pr.featureFlagName + " " +
pr.treatments.toString()).map(Object::toString).collect(Collectors.joining(", ")));
return bldr.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PrerequisitesMatcher that = (PrerequisitesMatcher) o;
return Objects.equals(_prerequisites, that._prerequisites);
}
@Override
public int hashCode() {
int result = _prerequisites != null ? _prerequisites.hashCode() : 0;
result = 31 * result + (_prerequisites != null ? _prerequisites.hashCode() : 0);
return result;
}
}