Skip to content

Commit 914493a

Browse files
committed
Tidy First: replace Guava with standard Java in evaluation code
Replace Guava dependencies in the evaluation engine with standard Java 8 equivalents to prepare for extraction into a zero-dependency targeting-engine module: - checkNotNull → Objects.requireNonNull (EvaluatorImp, EvaluationContext) - ImmutableList → Collections.unmodifiableList (ParsedSplit, CombiningMatcher) - Lists.newArrayList / checkArgument → ArrayList / IllegalArgumentException (CombiningMatcher, SplitParser)
1 parent 288e1e2 commit 914493a

5 files changed

Lines changed: 22 additions & 22 deletions

File tree

client/src/main/java/io/split/engine/evaluator/EvaluationContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import io.split.storages.RuleBasedSegmentCacheConsumer;
44
import io.split.storages.SegmentCacheConsumer;
55

6-
import static com.google.common.base.Preconditions.checkNotNull;
6+
import java.util.Objects;
77

88
public class EvaluationContext {
99
private final Evaluator _evaluator;
@@ -12,9 +12,9 @@ public class EvaluationContext {
1212

1313
public EvaluationContext(Evaluator evaluator, SegmentCacheConsumer segmentCacheConsumer,
1414
RuleBasedSegmentCacheConsumer ruleBasedSegmentCacheConsumer) {
15-
_evaluator = checkNotNull(evaluator);
16-
_segmentCacheConsumer = checkNotNull(segmentCacheConsumer);
17-
_ruleBasedSegmentCacheConsumer = checkNotNull(ruleBasedSegmentCacheConsumer);
15+
_evaluator = Objects.requireNonNull(evaluator);
16+
_segmentCacheConsumer = Objects.requireNonNull(segmentCacheConsumer);
17+
_ruleBasedSegmentCacheConsumer = Objects.requireNonNull(ruleBasedSegmentCacheConsumer);
1818
}
1919

2020
public Evaluator getEvaluator() {

client/src/main/java/io/split/engine/evaluator/EvaluatorImp.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.util.List;
2020
import java.util.Map;
2121

22-
import static com.google.common.base.Preconditions.checkNotNull;
22+
import java.util.Objects;
2323

2424
public class EvaluatorImp implements Evaluator {
2525
private static final Logger _log = LoggerFactory.getLogger(EvaluatorImp.class);
@@ -33,8 +33,8 @@ public class EvaluatorImp implements Evaluator {
3333
public EvaluatorImp(SplitCacheConsumer splitCacheConsumer, SegmentCacheConsumer segmentCache,
3434
RuleBasedSegmentCacheConsumer ruleBasedSegmentCacheConsumer,
3535
FallbackTreatmentCalculator fallbackTreatmentCalculator) {
36-
_splitCacheConsumer = checkNotNull(splitCacheConsumer);
37-
_segmentCacheConsumer = checkNotNull(segmentCache);
36+
_splitCacheConsumer = Objects.requireNonNull(splitCacheConsumer);
37+
_segmentCacheConsumer = Objects.requireNonNull(segmentCache);
3838
_evaluationContext = new EvaluationContext(this, _segmentCacheConsumer, ruleBasedSegmentCacheConsumer);
3939
_fallbackTreatmentCalculator = fallbackTreatmentCalculator;
4040
}

client/src/main/java/io/split/engine/experiments/ParsedSplit.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.split.engine.experiments;
22

3-
import com.google.common.collect.ImmutableList;
3+
import java.util.ArrayList;
4+
import java.util.Collections;
45
import io.split.engine.matchers.AttributeMatcher;
56
import io.split.engine.matchers.PrerequisitesMatcher;
67
import io.split.engine.matchers.RuleBasedSegmentMatcher;
@@ -26,7 +27,7 @@ public class ParsedSplit {
2627
private final int _seed;
2728
private final boolean _killed;
2829
private final String _defaultTreatment;
29-
private final ImmutableList<ParsedCondition> _parsedCondition;
30+
private final List<ParsedCondition> _parsedCondition;
3031
private final String _trafficTypeName;
3132
private final long _changeNumber;
3233
private final int _trafficAllocation;
@@ -120,7 +121,7 @@ public ParsedSplit(
120121
_seed = seed;
121122
_killed = killed;
122123
_defaultTreatment = defaultTreatment;
123-
_parsedCondition = ImmutableList.copyOf(matcherAndSplits);
124+
_parsedCondition = Collections.unmodifiableList(new ArrayList<>(matcherAndSplits));
124125
_trafficTypeName = trafficTypeName;
125126
_changeNumber = changeNumber;
126127
_algo = algo;

client/src/main/java/io/split/engine/experiments/SplitParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.split.engine.experiments;
22

3-
import com.google.common.collect.Lists;
3+
import java.util.ArrayList;
44

55
import io.split.client.dtos.Condition;
66
import io.split.client.dtos.Partition;
@@ -39,7 +39,7 @@ public ParsedSplit parse(Split split) {
3939
}
4040

4141
private ParsedSplit parseWithoutExceptionHandling(Split split) {
42-
List<ParsedCondition> parsedConditionList = Lists.newArrayList();
42+
List<ParsedCondition> parsedConditionList = new ArrayList<>();
4343
if (Objects.isNull(split.impressionsDisabled)) {
4444
_log.debug("impressionsDisabled field not detected for Feature flag `" + split.name + "`, setting it to `false`.");
4545
split.impressionsDisabled = false;

client/src/main/java/io/split/engine/matchers/CombiningMatcher.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,40 @@
11
package io.split.engine.matchers;
22

3-
import com.google.common.collect.ImmutableList;
4-
import com.google.common.collect.Lists;
53
import io.split.client.dtos.MatcherCombiner;
64
import io.split.engine.evaluator.EvaluationContext;
75

6+
import java.util.ArrayList;
7+
import java.util.Arrays;
8+
import java.util.Collections;
89
import java.util.List;
910
import java.util.Map;
1011
import java.util.Objects;
1112

12-
import static com.google.common.base.Preconditions.checkArgument;
13-
1413
/**
1514
* Combines the results of multiple matchers using the logical OR or AND.
1615
*
1716
* @author adil
1817
*/
1918
public class CombiningMatcher {
2019

21-
private final ImmutableList<AttributeMatcher> _delegates;
20+
private final List<AttributeMatcher> _delegates;
2221
private final MatcherCombiner _combiner;
2322

2423
public static CombiningMatcher of(Matcher matcher) {
2524
return new CombiningMatcher(MatcherCombiner.AND,
26-
Lists.newArrayList(AttributeMatcher.vanilla(matcher)));
25+
new ArrayList<>(Arrays.asList(AttributeMatcher.vanilla(matcher))));
2726
}
2827

2928
public static CombiningMatcher of(String attribute, Matcher matcher) {
3029
return new CombiningMatcher(MatcherCombiner.AND,
31-
Lists.newArrayList(new AttributeMatcher(attribute, matcher, false)));
30+
new ArrayList<>(Arrays.asList(new AttributeMatcher(attribute, matcher, false))));
3231
}
3332

3433
public CombiningMatcher(MatcherCombiner combiner, List<AttributeMatcher> delegates) {
35-
_delegates = ImmutableList.copyOf(delegates);
34+
_delegates = Collections.unmodifiableList(new ArrayList<>(delegates));
3635
_combiner = combiner;
3736

38-
checkArgument(_delegates.size() > 0);
37+
if (_delegates.isEmpty()) throw new IllegalArgumentException("Delegates must not be empty");
3938
}
4039

4140
public boolean match(String key, String bucketingKey, Map<String, Object> attributes, EvaluationContext evaluationContext) {
@@ -60,7 +59,7 @@ private boolean and(String key, String bucketingKey, Map<String, Object> attribu
6059
return result;
6160
}
6261

63-
public ImmutableList<AttributeMatcher> attributeMatchers() {
62+
public List<AttributeMatcher> attributeMatchers() {
6463
return _delegates;
6564
}
6665

0 commit comments

Comments
 (0)