Add method to get double

Signed-off-by: Thomas Poignant <thomas.poignant@gofeatureflag.org>
Signed-off-by: Robert Grassian <robert.grassian@split.io>
This commit is contained in:
Thomas Poignant 2022-07-23 19:35:56 +02:00 committed by Robert Grassian
parent 1508c94119
commit cfc94c5b77
6 changed files with 33 additions and 1 deletions

View File

@ -8,5 +8,6 @@ public interface FeatureProvider {
ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
<T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options);
}

View File

@ -46,7 +46,14 @@ public class NoOpProvider implements FeatureProvider {
.reason(Reason.DEFAULT)
.build();
}
@Override
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
return ProviderEvaluation.<Double>builder()
.value(defaultValue)
.variant(PASSED_IN_DEFAULT)
.reason(Reason.DEFAULT)
.build();
}
@Override
public <T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options) {
return ProviderEvaluation.<T>builder()

View File

@ -27,6 +27,11 @@ public class AlwaysBrokenProvider implements FeatureProvider {
throw new NotImplementedException("BORK");
}
@Override
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
throw new NotImplementedException("BORK");
}
@Override
public <T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options) {
throw new NotImplementedException("BORK");

View File

@ -27,6 +27,13 @@ public class DoSomethingProvider implements FeatureProvider {
.build();
}
@Override
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
return ProviderEvaluation.<Double>builder()
.value(defaultValue * 100)
.build();
}
@Override
public <T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options) {
return ProviderEvaluation.<T>builder()

View File

@ -24,6 +24,12 @@ public class NoOpProviderTest {
assertEquals(4, eval.getValue());
}
@Test void noOpdouble() {
NoOpProvider p = new NoOpProvider();
ProviderEvaluation<Double> eval = p.getDoubleEvaluation("key", 0.4, null, null);
assertEquals(0.4, eval.getValue());
}
@Test void structure() {
NoOpProvider p = new NoOpProvider();
Node<Integer> node = new Node<Integer>();

View File

@ -27,6 +27,9 @@ public class ProviderSpecTest {
ProviderEvaluation<Integer> int_result = p.getIntegerEvaluation("key", 4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
assertNotNull(int_result.getValue());
ProviderEvaluation<Double> double_result = p.getDoubleEvaluation("key", 0.4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
assertNotNull(double_result.getValue());
ProviderEvaluation<String> string_result = p.getStringEvaluation("key", "works", new EvaluationContext(), FlagEvaluationOptions.builder().build());
assertNotNull(string_result.getValue());
@ -67,6 +70,9 @@ public class ProviderSpecTest {
ProviderEvaluation<Integer> int_result = p.getIntegerEvaluation("key", 4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
assertNotNull(int_result.getReason());
ProviderEvaluation<Double> double_result = p.getDoubleEvaluation("key", 0.4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
assertNotNull(double_result.getReason());
ProviderEvaluation<String> string_result = p.getStringEvaluation("key", "works", new EvaluationContext(), FlagEvaluationOptions.builder().build());
assertNotNull(string_result.getReason());