Skip to content

Commit cfc94c5

Browse files
thomaspoignantrgrassian-split
authored andcommitted
Add method to get double
Signed-off-by: Thomas Poignant <thomas.poignant@gofeatureflag.org> Signed-off-by: Robert Grassian <robert.grassian@split.io>
1 parent 1508c94 commit cfc94c5

File tree

6 files changed

+33
-1
lines changed

6 files changed

+33
-1
lines changed

src/main/java/dev/openfeature/javasdk/FeatureProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ public interface FeatureProvider {
88
ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
99
ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
1010
ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
11+
ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
1112
<T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options);
1213
}

src/main/java/dev/openfeature/javasdk/NoOpProvider.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defa
4646
.reason(Reason.DEFAULT)
4747
.build();
4848
}
49-
49+
@Override
50+
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
51+
return ProviderEvaluation.<Double>builder()
52+
.value(defaultValue)
53+
.variant(PASSED_IN_DEFAULT)
54+
.reason(Reason.DEFAULT)
55+
.build();
56+
}
5057
@Override
5158
public <T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options) {
5259
return ProviderEvaluation.<T>builder()

src/test/java/dev/openfeature/javasdk/AlwaysBrokenProvider.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defa
2727
throw new NotImplementedException("BORK");
2828
}
2929

30+
@Override
31+
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
32+
throw new NotImplementedException("BORK");
33+
}
34+
3035
@Override
3136
public <T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options) {
3237
throw new NotImplementedException("BORK");

src/test/java/dev/openfeature/javasdk/DoSomethingProvider.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defa
2727
.build();
2828
}
2929

30+
@Override
31+
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
32+
return ProviderEvaluation.<Double>builder()
33+
.value(defaultValue * 100)
34+
.build();
35+
}
36+
3037
@Override
3138
public <T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options) {
3239
return ProviderEvaluation.<T>builder()

src/test/java/dev/openfeature/javasdk/NoOpProviderTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ public class NoOpProviderTest {
2424
assertEquals(4, eval.getValue());
2525
}
2626

27+
@Test void noOpdouble() {
28+
NoOpProvider p = new NoOpProvider();
29+
ProviderEvaluation<Double> eval = p.getDoubleEvaluation("key", 0.4, null, null);
30+
assertEquals(0.4, eval.getValue());
31+
}
32+
2733
@Test void structure() {
2834
NoOpProvider p = new NoOpProvider();
2935
Node<Integer> node = new Node<Integer>();

src/test/java/dev/openfeature/javasdk/ProviderSpecTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public class ProviderSpecTest {
2727
ProviderEvaluation<Integer> int_result = p.getIntegerEvaluation("key", 4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
2828
assertNotNull(int_result.getValue());
2929

30+
ProviderEvaluation<Double> double_result = p.getDoubleEvaluation("key", 0.4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
31+
assertNotNull(double_result.getValue());
32+
3033
ProviderEvaluation<String> string_result = p.getStringEvaluation("key", "works", new EvaluationContext(), FlagEvaluationOptions.builder().build());
3134
assertNotNull(string_result.getValue());
3235

@@ -67,6 +70,9 @@ public class ProviderSpecTest {
6770
ProviderEvaluation<Integer> int_result = p.getIntegerEvaluation("key", 4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
6871
assertNotNull(int_result.getReason());
6972

73+
ProviderEvaluation<Double> double_result = p.getDoubleEvaluation("key", 0.4, new EvaluationContext(), FlagEvaluationOptions.builder().build());
74+
assertNotNull(double_result.getReason());
75+
7076
ProviderEvaluation<String> string_result = p.getStringEvaluation("key", "works", new EvaluationContext(), FlagEvaluationOptions.builder().build());
7177
assertNotNull(string_result.getReason());
7278

0 commit comments

Comments
 (0)