diff --git a/client/src/main/java/io/split/client/SplitClientConfig.java b/client/src/main/java/io/split/client/SplitClientConfig.java index 4677e174d..380d33f3e 100644 --- a/client/src/main/java/io/split/client/SplitClientConfig.java +++ b/client/src/main/java/io/split/client/SplitClientConfig.java @@ -934,7 +934,7 @@ public Builder customStorageWrapper(CustomStorageWrapper customStorageWrapper) { */ public Builder flagSetsFilter(List flagSetsFilter) { FSValidatorResult fsValidatorResult = cleanup(flagSetsFilter); - _flagSetsFilter = new HashSet<>(fsValidatorResult.getFlagSets()); + _flagSetsFilter = fsValidatorResult.getFlagSets(); _invalidSets = fsValidatorResult.getInvalidSets(); return this; } diff --git a/client/src/main/java/io/split/inputValidation/FSValidatorResult.java b/client/src/main/java/io/split/inputValidation/FSValidatorResult.java index 87149bb5f..3b0bfe3b3 100644 --- a/client/src/main/java/io/split/inputValidation/FSValidatorResult.java +++ b/client/src/main/java/io/split/inputValidation/FSValidatorResult.java @@ -1,21 +1,24 @@ package io.split.inputValidation; -import java.util.List; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.TreeSet; public class FSValidatorResult { - private final List _flagSets; + private final Set _flagSets; private final int _invalidSets; - public FSValidatorResult(List flagSets, Integer invalidSets) { + public FSValidatorResult(TreeSet flagSets, Integer invalidSets) { _flagSets = flagSets; _invalidSets = invalidSets; } - public List getFlagSets() { - return _flagSets; + public HashSet getFlagSets() { + return new LinkedHashSet<>(_flagSets); } public int getInvalidSets() { return _invalidSets; } -} +} \ No newline at end of file diff --git a/client/src/main/java/io/split/inputValidation/FlagSetsValidator.java b/client/src/main/java/io/split/inputValidation/FlagSetsValidator.java index 8851c5884..77344f41c 100644 --- a/client/src/main/java/io/split/inputValidation/FlagSetsValidator.java +++ b/client/src/main/java/io/split/inputValidation/FlagSetsValidator.java @@ -3,7 +3,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.TreeSet; @@ -19,10 +18,10 @@ private FlagSetsValidator() { } public static FSValidatorResult cleanup(List flagSets) { + TreeSet cleanFlagSets = new TreeSet<>(); if (flagSets == null || flagSets.isEmpty()) { - return new FSValidatorResult(new ArrayList<>(), 0); + return new FSValidatorResult(cleanFlagSets, 0); } - TreeSet cleanFlagSets = new TreeSet<>(); int invalidSets = 0; for (String flagSet: flagSets) { if(flagSet != flagSet.toLowerCase()) { @@ -42,12 +41,12 @@ public static FSValidatorResult cleanup(List flagSets) { } cleanFlagSets.add(flagSet); } - return new FSValidatorResult(new ArrayList<>(cleanFlagSets), invalidSets); + return new FSValidatorResult(cleanFlagSets, invalidSets); } public static FlagSetsValidResult areValid(List flagSets) { FSValidatorResult fsValidatorResult = cleanup(flagSets); - List cleanFlagSets = fsValidatorResult.getFlagSets(); - return new FlagSetsValidResult(cleanFlagSets != null && cleanFlagSets.size() != 0, new HashSet<>(cleanFlagSets)); + HashSet cleanFlagSets = fsValidatorResult.getFlagSets(); + return new FlagSetsValidResult(cleanFlagSets != null && cleanFlagSets.size() != 0, cleanFlagSets); } } \ No newline at end of file diff --git a/client/src/test/java/io/split/client/SplitClientImplTest.java b/client/src/test/java/io/split/client/SplitClientImplTest.java index 964c8d563..5f33cf344 100644 --- a/client/src/test/java/io/split/client/SplitClientImplTest.java +++ b/client/src/test/java/io/split/client/SplitClientImplTest.java @@ -1733,7 +1733,7 @@ public void testTreatmentsByFlagSets() { fetchManyResult.put(test2, parsedSplit2); when(splitCacheConsumer.fetchMany(new ArrayList<>(Arrays.asList(test2, test)))).thenReturn(fetchManyResult); - List sets = new ArrayList<>(Arrays.asList("set3", "set1")); + List sets = new ArrayList<>(Arrays.asList("set1", "set3")); Map> flagsBySets = new HashMap<>(); flagsBySets.put("set1", new HashSet<>(Arrays.asList(test))); flagsBySets.put("set3", new HashSet<>(Arrays.asList(test2))); diff --git a/client/src/test/java/io/split/client/utils/FlagSetsValidatorTest.java b/client/src/test/java/io/split/client/utils/FlagSetsValidatorTest.java index 449af5428..e9943fc8c 100644 --- a/client/src/test/java/io/split/client/utils/FlagSetsValidatorTest.java +++ b/client/src/test/java/io/split/client/utils/FlagSetsValidatorTest.java @@ -71,11 +71,12 @@ public void testFlagSetsInOrder() { flagSets.add(" 2test "); FSValidatorResult cleanFlagSets = cleanup(flagSets); Assert.assertEquals(5, cleanFlagSets.getFlagSets().size()); - Assert.assertEquals("1test", cleanFlagSets.getFlagSets().get(0)); - Assert.assertEquals("2test", cleanFlagSets.getFlagSets().get(1)); - Assert.assertEquals("test1", cleanFlagSets.getFlagSets().get(2)); - Assert.assertEquals("test2", cleanFlagSets.getFlagSets().get(3)); - Assert.assertEquals("test3", cleanFlagSets.getFlagSets().get(4)); + List sets = new ArrayList<>(cleanFlagSets.getFlagSets()); + Assert.assertEquals("1test", sets.get(0)); + Assert.assertEquals("2test", sets.get(1)); + Assert.assertEquals("test1", sets.get(2)); + Assert.assertEquals("test2", sets.get(3)); + Assert.assertEquals("test3", sets.get(4)); } @Test