Double support
This commit is contained in:
parent
709b589cf3
commit
f37bae77d7
|
|
@ -29,6 +29,15 @@ public interface Features {
|
|||
FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defaultValue, EvaluationContext ctx);
|
||||
FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
|
||||
|
||||
Double getDoubleValue(String key, Double defaultValue);
|
||||
Double getDoubleValue(String key, Double defaultValue, EvaluationContext ctx);
|
||||
Double getDoubleValue(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
|
||||
|
||||
FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue);
|
||||
FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue, EvaluationContext ctx);
|
||||
FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
|
||||
|
||||
|
||||
<T> T getObjectValue(String key, T defaultValue);
|
||||
<T> T getObjectValue(String key, T defaultValue, EvaluationContext ctx);
|
||||
<T> T getObjectValue(String key, T defaultValue, EvaluationContext ctx, FlagEvaluationOptions options);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
package dev.openfeature.javasdk;
|
||||
|
||||
public enum FlagValueType {
|
||||
STRING, INTEGER, OBJECT, BOOLEAN;
|
||||
STRING, INTEGER, DOUBLE, OBJECT, BOOLEAN;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,6 +85,8 @@ public class OpenFeatureClient implements Client {
|
|||
return provider.getStringEvaluation(key, (String) defaultValue, invocationContext, options);
|
||||
case INTEGER:
|
||||
return provider.getIntegerEvaluation(key, (Integer) defaultValue, invocationContext, options);
|
||||
case DOUBLE:
|
||||
return provider.getDoubleEvaluation(key, (Double) defaultValue, invocationContext, options);
|
||||
case OBJECT:
|
||||
return provider.getObjectEvaluation(key, defaultValue, invocationContext, options);
|
||||
default:
|
||||
|
|
@ -182,6 +184,36 @@ public class OpenFeatureClient implements Client {
|
|||
return this.evaluateFlag(FlagValueType.INTEGER, key, defaultValue, ctx, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getDoubleValue(String key, Double defaultValue) {
|
||||
return getDoubleValue(key, defaultValue, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getDoubleValue(String key, Double defaultValue, EvaluationContext ctx) {
|
||||
return getDoubleValue(key, defaultValue, ctx, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getDoubleValue(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
|
||||
return this.evaluateFlag(FlagValueType.DOUBLE, key, defaultValue, ctx, options).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue) {
|
||||
return getDoubleDetails(key, defaultValue, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue, EvaluationContext ctx) {
|
||||
return getDoubleDetails(key, defaultValue, ctx, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
|
||||
return this.evaluateFlag(FlagValueType.DOUBLE, key, defaultValue, ctx, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getObjectValue(String key, T defaultValue) {
|
||||
return getObjectDetails(key, defaultValue).getValue();
|
||||
|
|
|
|||
|
|
@ -74,8 +74,8 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
assertTrue(hooks.contains(m1));
|
||||
assertTrue(hooks.contains(m2));
|
||||
}
|
||||
@Specification(number="1.3.1", text="The client MUST provide methods for flag evaluation, with parameters flag key (string, required), default value (boolean | number | string | structure, required), evaluation context (optional), and evaluation options (optional), which returns the flag value.")
|
||||
@Specification(number="1.3.2.1", text="The client MUST provide methods for typed flag evaluation, including boolean, numeric, string, and structure.")
|
||||
@Specification(number="1.3.1", text="The client MUST provide methods for typed flag evaluation, including boolean, numeric, string, and structure, with parameters flag key (string, required), default value (boolean | number | string | structure, required), evaluation context (optional), and evaluation options (optional), which returns the flag value.")
|
||||
@Specification(number="1.3.2.1", text="The client SHOULD provide functions for floating-point numbers and integers, consistent with language idioms.")
|
||||
@Test void value_flags() {
|
||||
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
|
||||
api.setProvider(new DoSomethingProvider());
|
||||
|
|
@ -95,6 +95,10 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
assertEquals(400, c.getIntegerValue(key, 4, new EvaluationContext()));
|
||||
assertEquals(400, c.getIntegerValue(key, 4, new EvaluationContext(), FlagEvaluationOptions.builder().build()));
|
||||
|
||||
assertEquals(40.0, c.getDoubleValue(key, .4));
|
||||
assertEquals(40.0, c.getDoubleValue(key, .4, new EvaluationContext()));
|
||||
assertEquals(40.0, c.getDoubleValue(key, .4, new EvaluationContext(), FlagEvaluationOptions.builder().build()));
|
||||
|
||||
assertEquals(null, c.getObjectValue(key, new Node<Integer>()));
|
||||
assertEquals(null, c.getObjectValue(key, new Node<Integer>(), new EvaluationContext()));
|
||||
assertEquals(null, c.getObjectValue(key, new Node<Integer>(), new EvaluationContext(), FlagEvaluationOptions.builder().build()));
|
||||
|
|
@ -138,6 +142,14 @@ class FlagEvaluationSpecTest implements HookFixtures {
|
|||
assertEquals(id, c.getIntegerDetails(key, 4, new EvaluationContext()));
|
||||
assertEquals(id, c.getIntegerDetails(key, 4, new EvaluationContext(), FlagEvaluationOptions.builder().build()));
|
||||
|
||||
FlagEvaluationDetails<Double> dd = FlagEvaluationDetails.<Double>builder()
|
||||
.flagKey(key)
|
||||
.value(40.0)
|
||||
.build();
|
||||
assertEquals(dd, c.getDoubleDetails(key, .4));
|
||||
assertEquals(dd, c.getDoubleDetails(key, .4, new EvaluationContext()));
|
||||
assertEquals(dd, c.getDoubleDetails(key, .4, new EvaluationContext(), FlagEvaluationOptions.builder().build()));
|
||||
|
||||
// TODO: Structure detail tests.
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,8 @@ class HookSupportTest implements HookFixtures {
|
|||
return "defaultValue";
|
||||
case OBJECT:
|
||||
return "object";
|
||||
case DOUBLE:
|
||||
return "double";
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue