Repository: open-feature/java-sdk (java)

Issue:
Get float value?
It seems like the Java SDK doesn't support floats. Is that something that should be supported? I suppose this can be worked around with strings, but I wonder if decimal values are important enough to be supported, especially fractional values like .5 could be practical.

Relevant part of the spec: https://github.com/open-feature/spec/blob/main/specification/types.md#number

Pull request:
feat: Add method to get double
This PR adds the support of `double` value from the flags.

Resolves #32

Patch:
diff --git a/src/main/java/dev/openfeature/javasdk/FeatureProvider.java b/src/main/java/dev/openfeature/javasdk/FeatureProvider.java
index c131083..8f22faa 100644
--- a/src/main/java/dev/openfeature/javasdk/FeatureProvider.java
+++ b/src/main/java/dev/openfeature/javasdk/FeatureProvider.java
@@ -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);
 }
diff --git a/src/main/java/dev/openfeature/javasdk/NoOpProvider.java b/src/main/java/dev/openfeature/javasdk/NoOpProvider.java
index ff5aa73..d8e5131 100644
--- a/src/main/java/dev/openfeature/javasdk/NoOpProvider.java
+++ b/src/main/java/dev/openfeature/javasdk/NoOpProvider.java
@@ -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()


Test patch:
diff --git a/src/test/java/dev/openfeature/javasdk/AlwaysBrokenProvider.java b/src/test/java/dev/openfeature/javasdk/AlwaysBrokenProvider.java
index 1a24235..e02a0db 100644
--- a/src/test/java/dev/openfeature/javasdk/AlwaysBrokenProvider.java
+++ b/src/test/java/dev/openfeature/javasdk/AlwaysBrokenProvider.java
@@ -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");
diff --git a/src/test/java/dev/openfeature/javasdk/DoSomethingProvider.java b/src/test/java/dev/openfeature/javasdk/DoSomethingProvider.java
index 9bb6d06..dd6f802 100644
--- a/src/test/java/dev/openfeature/javasdk/DoSomethingProvider.java
+++ b/src/test/java/dev/openfeature/javasdk/DoSomethingProvider.java
@@ -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()
diff --git a/src/test/java/dev/openfeature/javasdk/NoOpProviderTest.java b/src/test/java/dev/openfeature/javasdk/NoOpProviderTest.java
index 9378561..531d96f 100644
--- a/src/test/java/dev/openfeature/javasdk/NoOpProviderTest.java
+++ b/src/test/java/dev/openfeature/javasdk/NoOpProviderTest.java
@@ -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>();
diff --git a/src/test/java/dev/openfeature/javasdk/ProviderSpecTest.java b/src/test/java/dev/openfeature/javasdk/ProviderSpecTest.java
index b5b08cd..eb5e494 100644
--- a/src/test/java/dev/openfeature/javasdk/ProviderSpecTest.java
+++ b/src/test/java/dev/openfeature/javasdk/ProviderSpecTest.java
@@ -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());