Skip to content

Commit

Permalink
Readability changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea committed Sep 4, 2023
1 parent 4eaaa30 commit 56bd11a
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private static class ValidationTag {
public static final String GET_TREATMENT_WITH_CONFIG = "getTreatmentWithConfig";
public static final String GET_TREATMENTS_WITH_CONFIG = "getTreatmentsWithConfig";
public static final String GET_TREATMENTS_BY_FLAG_SET = "getTreatmentsByFlagSet";
public static final String GET_TREATMENTS_BY_FLAG_SETS = "getFeatureFlagNamesToEvaluate";
public static final String GET_TREATMENTS_BY_FLAG_SETS = "getTreatmentsByFlagSets";
public static final String GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET = "getTreatmentsWithConfigByFlagSet";
public static final String GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS = "getTreatmentsWithConfigByFlagSets";
}
Expand Down Expand Up @@ -184,7 +184,8 @@ public Map<String, SplitResult> getTreatmentsWithConfig(List<String> splits, Map
public Map<String, String> getTreatmentsByFlagSet(@NonNull String flagSet, @Nullable Map<String, Object> attributes, boolean isClientDestroyed) {
long start = System.currentTimeMillis();
try {
return evaluateFeaturesGeneric(getFeatureFlagNamesToEvaluate(ValidationTag.GET_TREATMENTS_BY_FLAG_SET, Collections.singletonList(flagSet), isClientDestroyed), attributes, ValidationTag.GET_TREATMENTS_BY_FLAG_SET, SplitResult::treatment);
Set<String> names = getNamesFromSet(ValidationTag.GET_TREATMENTS_BY_FLAG_SET, Collections.singletonList(flagSet), isClientDestroyed);
return evaluateFeatures(names, attributes, ValidationTag.GET_TREATMENTS_BY_FLAG_SET, SplitResult::treatment);
} finally {
recordLatency(Method.TREATMENTS_BY_FLAG_SET, start);
}
Expand All @@ -194,7 +195,8 @@ public Map<String, String> getTreatmentsByFlagSet(@NonNull String flagSet, @Null
public Map<String, String> getTreatmentsByFlagSets(@NonNull List<String> flagSets, @Nullable Map<String, Object> attributes, boolean isClientDestroyed) {
long start = System.currentTimeMillis();
try {
return evaluateFeaturesGeneric(getFeatureFlagNamesToEvaluate(ValidationTag.GET_TREATMENTS_BY_FLAG_SETS, flagSets, isClientDestroyed), attributes, ValidationTag.GET_TREATMENTS_BY_FLAG_SETS, SplitResult::treatment);
Set<String> names = getNamesFromSet(ValidationTag.GET_TREATMENTS_BY_FLAG_SETS, flagSets, isClientDestroyed);
return evaluateFeatures(names, attributes, ValidationTag.GET_TREATMENTS_BY_FLAG_SETS, SplitResult::treatment);
} finally {
recordLatency(Method.TREATMENTS_BY_FLAG_SETS, start);
}
Expand All @@ -204,7 +206,8 @@ public Map<String, String> getTreatmentsByFlagSets(@NonNull List<String> flagSet
public Map<String, SplitResult> getTreatmentsWithConfigByFlagSet(@NonNull String flagSet, @Nullable Map<String, Object> attributes, boolean isClientDestroyed) {
long start = System.currentTimeMillis();
try {
return evaluateFeaturesGeneric(getFeatureFlagNamesToEvaluate(ValidationTag.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, Collections.singletonList(flagSet), isClientDestroyed), attributes, ValidationTag.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, splitResult -> splitResult);
Set<String> names = getNamesFromSet(ValidationTag.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, Collections.singletonList(flagSet), isClientDestroyed);
return evaluateFeatures(names, attributes, ValidationTag.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET, splitResult -> splitResult);
} finally {
recordLatency(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET, start);
}
Expand All @@ -214,7 +217,8 @@ public Map<String, SplitResult> getTreatmentsWithConfigByFlagSet(@NonNull String
public Map<String, SplitResult> getTreatmentsWithConfigByFlagSets(@NonNull List<String> flagSets, @Nullable Map<String, Object> attributes, boolean isClientDestroyed) {
long start = System.currentTimeMillis();
try {
return evaluateFeaturesGeneric(getFeatureFlagNamesToEvaluate(ValidationTag.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, flagSets, isClientDestroyed), attributes, ValidationTag.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, splitResult -> splitResult);
Set<String> names = getNamesFromSet(ValidationTag.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, flagSets, isClientDestroyed);
return evaluateFeatures(names, attributes, ValidationTag.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, splitResult -> splitResult);
} finally {
recordLatency(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, start);
}
Expand Down Expand Up @@ -341,9 +345,9 @@ private void recordLatency(Method treatment, long startTime) {
}

@NonNull
private Set<String> getFeatureFlagNamesToEvaluate(String validationTag,
@NonNull List<String> flagSets,
boolean isClientDestroyed) {
private Set<String> getNamesFromSet(String validationTag,
@NonNull List<String> flagSets,
boolean isClientDestroyed) {
if (isClientDestroyed) {
mValidationLogger.e(CLIENT_DESTROYED_MESSAGE, validationTag);
return new HashSet<>();
Expand Down Expand Up @@ -378,7 +382,7 @@ private Set<String> getFeatureFlagNamesToEvaluate(String validationTag,
return mSplitsStorage.getNamesByFlagSets(setsToEvaluate);
}

private <T> Map<String, T> evaluateFeaturesGeneric(Set<String> names, @Nullable Map<String, Object> attributes, String validationTag, ResultTransformer<T> transformer) {
private <T> Map<String, T> evaluateFeatures(Set<String> names, @Nullable Map<String, Object> attributes, String validationTag, ResultTransformer<T> transformer) {
Map<String, T> result = new HashMap<>();
for (String featureFlagName : names) {
SplitResult splitResult = getTreatmentWithConfigWithoutMetrics(featureFlagName, attributes, validationTag);
Expand Down

0 comments on commit 56bd11a

Please sign in to comment.