Skip to content

Commit

Permalink
[SDKS-7538] Pr suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
nmayorsplit committed Oct 5, 2023
1 parent a816701 commit 1c6a1ef
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ public Builder customStorageWrapper(CustomStorageWrapper customStorageWrapper) {
*/
public Builder flagSetsFilter(List<String> flagSetsFilter) {
FSValidatorResult fsValidatorResult = cleanup(flagSetsFilter);
_flagSetsFilter = new HashSet<>(fsValidatorResult.getFlagSets());
_flagSetsFilter = fsValidatorResult.getFlagSets();
_invalidSets = fsValidatorResult.getInvalidSets();
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> _flagSets;
private final Set<String> _flagSets;
private final int _invalidSets;

public FSValidatorResult(List<String> flagSets, Integer invalidSets) {
public FSValidatorResult(TreeSet<String> flagSets, Integer invalidSets) {
_flagSets = flagSets;
_invalidSets = invalidSets;
}

public List<String> getFlagSets() {
return _flagSets;
public HashSet<String> getFlagSets() {
return new LinkedHashSet<>(_flagSets);
}

public int getInvalidSets() {
return _invalidSets;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,10 +18,10 @@ private FlagSetsValidator() {
}

public static FSValidatorResult cleanup(List<String> flagSets) {
TreeSet<String> cleanFlagSets = new TreeSet<>();
if (flagSets == null || flagSets.isEmpty()) {
return new FSValidatorResult(new ArrayList<>(), 0);
return new FSValidatorResult(cleanFlagSets, 0);
}
TreeSet<String> cleanFlagSets = new TreeSet<>();
int invalidSets = 0;
for (String flagSet: flagSets) {
if(flagSet != flagSet.toLowerCase()) {
Expand All @@ -42,12 +41,12 @@ public static FSValidatorResult cleanup(List<String> flagSets) {
}
cleanFlagSets.add(flagSet);
}
return new FSValidatorResult(new ArrayList<>(cleanFlagSets), invalidSets);
return new FSValidatorResult(cleanFlagSets, invalidSets);
}

public static FlagSetsValidResult areValid(List<String> flagSets) {
FSValidatorResult fsValidatorResult = cleanup(flagSets);
List<String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ public void testTreatmentsByFlagSets() {
fetchManyResult.put(test2, parsedSplit2);
when(splitCacheConsumer.fetchMany(new ArrayList<>(Arrays.asList(test2, test)))).thenReturn(fetchManyResult);

List<String> sets = new ArrayList<>(Arrays.asList("set3", "set1"));
List<String> sets = new ArrayList<>(Arrays.asList("set1", "set3"));
Map<String, HashSet<String>> flagsBySets = new HashMap<>();
flagsBySets.put("set1", new HashSet<>(Arrays.asList(test)));
flagsBySets.put("set3", new HashSet<>(Arrays.asList(test2)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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
Expand Down

0 comments on commit 1c6a1ef

Please sign in to comment.