-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathParsedCondition.java
More file actions
120 lines (94 loc) · 3.13 KB
/
ParsedCondition.java
File metadata and controls
120 lines (94 loc) · 3.13 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package io.split.engine.experiments;
import io.split.client.dtos.ConditionType;
import io.split.client.dtos.Partition;
import io.split.engine.matchers.CombiningMatcher;
import java.util.List;
/**
* A pair of matcher and partitions.
*
* @author adil
*/
public final class ParsedCondition {
private final ConditionType _conditionType;
private final CombiningMatcher _matcher;
private final List<Partition> _partitions;
private final String _label;
public static ParsedCondition createParsedConditionForTests(CombiningMatcher matcher, List<Partition> partitions) {
return new ParsedCondition(ConditionType.ROLLOUT, matcher, partitions, null);
}
public ParsedCondition(ConditionType conditionType, CombiningMatcher matcher, List<Partition> partitions, String label) {
_conditionType = conditionType;
_matcher = matcher;
_partitions = partitions;
_label = label;
}
public ConditionType conditionType() {
return _conditionType;
}
public CombiningMatcher matcher() {
return _matcher;
}
public List<Partition> partitions() {
return _partitions;
}
public String label() {
return _label;
}
@Override
public int hashCode() {
int result = 17;
result = 31 * result + _matcher.hashCode();
int partitionsHashCode = 17;
if (_partitions != null) {
for (Partition p : _partitions) {
partitionsHashCode = 31 * partitionsHashCode + p.treatment.hashCode();
partitionsHashCode = 31 * partitionsHashCode + p.size;
}
}
result = 31 * result + partitionsHashCode;
return result;
}
@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (this == obj) return true;
if (!(obj instanceof ParsedCondition)) return false;
ParsedCondition other = (ParsedCondition) obj;
boolean result = _matcher.equals(other._matcher);
if (!result) {
return result;
}
if (_partitions == null) {
return result & (_partitions == other._partitions);
}
if (_partitions.size() != other._partitions.size()) {
return result;
}
for (int i = 0; i < _partitions.size(); i++) {
Partition first = _partitions.get(i);
Partition second = other._partitions.get(i);
result &= (first.size == second.size && first.treatment.equals(second.treatment));
}
return result;
}
@Override
public String toString() {
StringBuilder bldr = new StringBuilder();
bldr.append(_matcher);
bldr.append(" then split ");
boolean first = true;
if (_partitions == null) {
return bldr.toString();
}
for (Partition partition : _partitions) {
if (!first) {
bldr.append(',');
}
bldr.append(partition.size);
bldr.append(':');
bldr.append(partition.treatment);
first = false;
}
return bldr.toString();
}
}