22
33import com .google .common .base .Preconditions ;
44import io .split .client .api .SplitView ;
5- import io .split .client .dtos .Partition ;
65import io .split .engine .SDKReadinessGates ;
76import io .split .cache .SplitCache ;
8- import io .split .engine .experiments .ParsedCondition ;
97import io .split .engine .experiments .ParsedSplit ;
8+ import io .split .inputValidation .SplitNameValidator ;
109import org .slf4j .Logger ;
1110import org .slf4j .LoggerFactory ;
1211
1312import java .util .ArrayList ;
1413import java .util .Collection ;
15- import java .util .Collections ;
16- import java .util .HashSet ;
1714import java .util .List ;
18- import java .util .Set ;
1915
16+ import java .util .Optional ;
2017import java .util .concurrent .TimeoutException ;
2118
2219/**
@@ -44,21 +41,20 @@ public List<SplitView> splits() {
4441 List <SplitView > result = new ArrayList <>();
4542 Collection <ParsedSplit > parsedSplits = _splitCache .getAll ();
4643 for (ParsedSplit split : parsedSplits ) {
47- result .add (toSplitView (split ));
44+ result .add (SplitView . fromParsedSplit (split ));
4845 }
46+
4947 return result ;
5048 }
5149
5250 @ Override
5351 public SplitView split (String featureName ) {
54- if (featureName == null ) {
55- _log .error ("split: you passed a null split name, split name must be a non-empty string" );
56- return null ;
57- }
58- if (featureName .isEmpty ()) {
59- _log .error ("split: you passed an empty split name, split name must be a non-empty string" );
52+ Optional <String > result = SplitNameValidator .isValid (featureName , "split" );
53+ if (!result .isPresent ()) {
6054 return null ;
6155 }
56+ featureName = result .get ();
57+
6258 ParsedSplit parsedSplit = _splitCache .get (featureName );
6359 if (parsedSplit == null ) {
6460 if (_gates .isSDKReadyNow ()) {
@@ -67,7 +63,8 @@ public SplitView split(String featureName) {
6763 }
6864 return null ;
6965 }
70- return toSplitView (parsedSplit );
66+
67+ return SplitView .fromParsedSplit (parsedSplit );
7168 }
7269
7370 @ Override
@@ -77,6 +74,7 @@ public List<String> splitNames() {
7774 for (ParsedSplit split : parsedSplits ) {
7875 result .add (split .feature ());
7976 }
77+
8078 return result ;
8179 }
8280
@@ -89,25 +87,4 @@ public void blockUntilReady() throws TimeoutException, InterruptedException {
8987 throw new TimeoutException ("SDK was not ready in " + _config .blockUntilReady ()+ " milliseconds" );
9088 }
9189 }
92-
93- private SplitView toSplitView (ParsedSplit parsedSplit ) {
94- SplitView splitView = new SplitView ();
95- splitView .name = parsedSplit .feature ();
96- splitView .trafficType = parsedSplit .trafficTypeName ();
97- splitView .killed = parsedSplit .killed ();
98- splitView .changeNumber = parsedSplit .changeNumber ();
99-
100- Set <String > treatments = new HashSet <String >();
101- for (ParsedCondition condition : parsedSplit .parsedConditions ()) {
102- for (Partition partition : condition .partitions ()) {
103- treatments .add (partition .treatment );
104- }
105- }
106- treatments .add (parsedSplit .defaultTreatment ());
107-
108- splitView .treatments = new ArrayList <String >(treatments );
109- splitView .configs = parsedSplit .configurations () == null ? Collections .<String , String >emptyMap () : parsedSplit .configurations () ;
110-
111- return splitView ;
112- }
11390}
0 commit comments