Skip to content

Commit 4bee2e3

Browse files
committed
Revert "Factory code cleanup"
This reverts commit 5d1e670.
1 parent 041d12b commit 4bee2e3

File tree

3 files changed

+43
-60
lines changed

3 files changed

+43
-60
lines changed

client/src/main/java/io/split/client/LocalhostSplitClient.java

Lines changed: 37 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
import io.split.client.api.Key;
44
import io.split.client.api.SplitResult;
55
import io.split.grammar.Treatments;
6-
import io.split.inputValidation.KeyValidator;
7-
import io.split.inputValidation.SplitNameValidator;
86
import org.slf4j.Logger;
97
import org.slf4j.LoggerFactory;
108

119
import java.util.Map;
12-
import java.util.Optional;
1310
import java.util.concurrent.TimeoutException;
1411

1512
import static com.google.common.base.Preconditions.checkNotNull;
@@ -63,6 +60,43 @@ public SplitResult getTreatmentWithConfig(Key key, String split, Map<String, Obj
6360
return getTreatmentAndConfigInternal(key.matchingKey(), split, attributes);
6461
}
6562

63+
private SplitResult getTreatmentAndConfigInternal(String key, String split) {
64+
return getTreatmentAndConfigInternal(key, split, null);
65+
}
66+
67+
private SplitResult getTreatmentAndConfigInternal(String key, String split, Map<String, Object> attributes) {
68+
if (key == null || split == null) {
69+
return SPLIT_RESULT_CONTROL;
70+
}
71+
72+
SplitAndKey override = SplitAndKey.of(split, key);
73+
if (_map.containsKey(override)) {
74+
return toSplitResult(_map.get(override));
75+
}
76+
77+
SplitAndKey splitDefaultTreatment = SplitAndKey.of(split);
78+
79+
LocalhostSplit localhostSplit = _map.get(splitDefaultTreatment);
80+
81+
if (localhostSplit == null) {
82+
return SPLIT_RESULT_CONTROL;
83+
}
84+
85+
return toSplitResult(localhostSplit);
86+
}
87+
88+
private SplitResult toSplitResult(LocalhostSplit localhostSplit) {
89+
return new SplitResult(localhostSplit.treatment,localhostSplit.config);
90+
}
91+
92+
public void updateFeatureToTreatmentMap(Map<SplitAndKey, LocalhostSplit> map) {
93+
if (map == null) {
94+
_log.warn("A null map was passed as an update. Ignoring this update.");
95+
return;
96+
}
97+
_map = map;
98+
}
99+
66100
@Override
67101
public void destroy() {
68102
_map.clear();
@@ -93,50 +127,4 @@ public void blockUntilReady() throws TimeoutException, InterruptedException {
93127
// LocalhostSplitClient is always ready
94128
}
95129

96-
public void updateFeatureToTreatmentMap(Map<SplitAndKey, LocalhostSplit> map) {
97-
if (map == null) {
98-
_log.warn("A null map was passed as an update. Ignoring this update.");
99-
return;
100-
}
101-
_map = map;
102-
}
103-
104-
private SplitResult getTreatmentAndConfigInternal(String key, String split, Map<String, Object> attributes) {
105-
boolean keyIsValid = KeyValidator.isValid(key, "matchingKey", "getTreatment");
106-
107-
if (!keyIsValid) {
108-
return SPLIT_RESULT_CONTROL;
109-
}
110-
111-
Optional<String> splitName = SplitNameValidator.isValid(split, "getTreatment");
112-
113-
if (!splitName.isPresent()) {
114-
return SPLIT_RESULT_CONTROL;
115-
}
116-
117-
split = splitName.get();
118-
119-
SplitAndKey override = SplitAndKey.of(split, key);
120-
if (_map.containsKey(override)) {
121-
return toSplitResult(_map.get(override));
122-
}
123-
124-
SplitAndKey splitDefaultTreatment = SplitAndKey.of(split);
125-
126-
LocalhostSplit localhostSplit = _map.get(splitDefaultTreatment);
127-
128-
if (localhostSplit == null) {
129-
return SPLIT_RESULT_CONTROL;
130-
}
131-
132-
return toSplitResult(localhostSplit);
133-
}
134-
135-
private SplitResult toSplitResult(LocalhostSplit localhostSplit) {
136-
return new SplitResult(localhostSplit.treatment,localhostSplit.config);
137-
}
138-
139-
private SplitResult getTreatmentAndConfigInternal(String key, String split) {
140-
return getTreatmentAndConfigInternal(key, split, null);
141-
}
142130
}

client/src/main/java/io/split/client/LocalhostSplitClientAndFactory.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ public final class LocalhostSplitClientAndFactory implements SplitClient {
2525
private LocalhostSplitClient _splitClient;
2626

2727
public LocalhostSplitClientAndFactory(LocalhostSplitFactory container, LocalhostSplitClient client) {
28-
_factory = checkNotNull(container);
29-
_splitClient = checkNotNull(client);
28+
_factory = container;
29+
_splitClient = client;
30+
31+
checkNotNull(_factory);
32+
checkNotNull(_splitClient);
3033
}
3134

3235
@Override

client/src/main/java/io/split/inputValidation/KeyValidator.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
public class KeyValidator {
77
private static final Logger _log = LoggerFactory.getLogger(KeyValidator.class);
88

9-
public static boolean isValid(String key, String propertyName, String method) {
9+
public static boolean isValid(String key, String propertyName, int maxStringLength, String method) {
1010
if (key == null) {
1111
_log.error(String.format("%s: you passed a null %s, %s must be a non-empty string", method, propertyName, propertyName));
1212
return false;
@@ -17,14 +17,6 @@ public static boolean isValid(String key, String propertyName, String method) {
1717
return false;
1818
}
1919

20-
return true;
21-
}
22-
23-
public static boolean isValid(String key, String propertyName, int maxStringLength, String method) {
24-
if (!isValid(key, propertyName, method)) {
25-
return false;
26-
}
27-
2820
if (key.length() > maxStringLength) {
2921
_log.error(String.format("%s: %s too long - must be %s characters or less", method, propertyName, maxStringLength));
3022
return false;

0 commit comments

Comments
 (0)