Skip to content

Commit

Permalink
feat!: use value for object resolver
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <toddbaert@gmail.com>
  • Loading branch information
toddbaert committed Sep 9, 2022
1 parent 3e62414 commit 5d26247
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/main/java/dev/openfeature/javasdk/FeatureProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ default List<Hook> getProviderHooks() {

ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx);

ProviderEvaluation<Structure> getObjectEvaluation(String key, Structure defaultValue, EvaluationContext ctx);
ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue, EvaluationContext ctx);
}
12 changes: 6 additions & 6 deletions src/main/java/dev/openfeature/javasdk/Features.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defaultValu
FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options);

Structure getObjectValue(String key, Structure defaultValue);
Value getObjectValue(String key, Value defaultValue);

Structure getObjectValue(String key, Structure defaultValue, EvaluationContext ctx);
Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx);

Structure getObjectValue(String key, Structure defaultValue, EvaluationContext ctx,
Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options);

FlagEvaluationDetails<Structure> getObjectDetails(String key, Structure defaultValue);
FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue);

FlagEvaluationDetails<Structure> getObjectDetails(String key, Structure defaultValue,
FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue,
EvaluationContext ctx);

FlagEvaluationDetails<Structure> getObjectDetails(String key, Structure defaultValue,
FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue,
EvaluationContext ctx,
FlagEvaluationOptions options);
}
4 changes: 2 additions & 2 deletions src/main/java/dev/openfeature/javasdk/NoOpProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double default
}

@Override
public ProviderEvaluation<Structure> getObjectEvaluation(String key, Structure defaultValue,
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue,
EvaluationContext invocationContext) {
return ProviderEvaluation.<Structure>builder()
return ProviderEvaluation.<Value>builder()
.value(defaultValue)
.variant(PASSED_IN_DEFAULT)
.reason(Reason.DEFAULT)
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/dev/openfeature/javasdk/OpenFeatureClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private <T> ProviderEvaluation<?> createProviderEvaluation(
case DOUBLE:
return provider.getDoubleEvaluation(key, (Double) defaultValue, invocationContext);
case OBJECT:
return provider.getObjectEvaluation(key, (Structure) defaultValue, invocationContext);
return provider.getObjectEvaluation(key, (Value) defaultValue, invocationContext);
default:
throw new GeneralError("Unknown flag type");
}
Expand Down Expand Up @@ -257,34 +257,34 @@ public FlagEvaluationDetails<Double> getDoubleDetails(String key, Double default
}

@Override
public Structure getObjectValue(String key, Structure defaultValue) {
public Value getObjectValue(String key, Value defaultValue) {
return getObjectDetails(key, defaultValue).getValue();
}

@Override
public Structure getObjectValue(String key, Structure defaultValue, EvaluationContext ctx) {
public Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx) {
return getObjectDetails(key, defaultValue, ctx).getValue();
}

@Override
public Structure getObjectValue(String key, Structure defaultValue, EvaluationContext ctx,
public Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options) {
return getObjectDetails(key, defaultValue, ctx, options).getValue();
}

@Override
public FlagEvaluationDetails<Structure> getObjectDetails(String key, Structure defaultValue) {
public FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue) {
return getObjectDetails(key, defaultValue, null);
}

@Override
public FlagEvaluationDetails<Structure> getObjectDetails(String key, Structure defaultValue,
public FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue,
EvaluationContext ctx) {
return getObjectDetails(key, defaultValue, ctx, FlagEvaluationOptions.builder().build());
}

@Override
public FlagEvaluationDetails<Structure> getObjectDetails(String key, Structure defaultValue, EvaluationContext ctx,
public FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue, EvaluationContext ctx,
FlagEvaluationOptions options) {
return this.evaluateFlag(FlagValueType.OBJECT, key, defaultValue, ctx, options);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/openfeature/javasdk/Value.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import lombok.ToString;

/**
* Values serve as a return type for provider objects.
* Values serve as a generic return type for structure data from providers.
* Providers may deal in JSON, protobuf, XML or some other data-interchange format.
* This intermediate representation provides a good medium of exchange.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double default
}

@Override
public ProviderEvaluation<Structure> getObjectEvaluation(String key, Structure defaultValue, EvaluationContext invocationContext) {
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue, EvaluationContext invocationContext) {
throw new NotImplementedException("BORK");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double default
}

@Override
public ProviderEvaluation<Structure> getObjectEvaluation(String key, Structure defaultValue, EvaluationContext invocationContext) {
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue, EvaluationContext invocationContext) {
savedContext = invocationContext;
return ProviderEvaluation.<Structure>builder()
return ProviderEvaluation.<Value>builder()
.value(null)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ private Client _client() {
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 Structure()));
assertEquals(null, c.getObjectValue(key, new Structure(), new EvaluationContext()));
assertEquals(null, c.getObjectValue(key, new Structure(), new EvaluationContext(), FlagEvaluationOptions.builder().build()));
assertEquals(null, c.getObjectValue(key, new Value()));
assertEquals(null, c.getObjectValue(key, new Value(), new EvaluationContext()));
assertEquals(null, c.getObjectValue(key, new Value(), new EvaluationContext(), FlagEvaluationOptions.builder().build()));
}

@Specification(number="1.4.1", text="The client MUST provide methods for detailed flag value evaluation with parameters flag key (string, required), default value (boolean | number | string | structure, required), evaluation context (optional), and evaluation options (optional), which returns an evaluation details structure.")
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/dev/openfeature/javasdk/NoOpProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public class NoOpProviderTest {
assertEquals(0.4, eval.getValue());
}

@Test void structure() {
@Test void value() {
NoOpProvider p = new NoOpProvider();
Structure s = new Structure();
ProviderEvaluation<Structure> eval = p.getObjectEvaluation("key", s, null);
Value s = new Value();
ProviderEvaluation<Value> eval = p.getObjectEvaluation("key", s, null);
assertEquals(s, eval.getValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ProviderSpecTest {
ProviderEvaluation<Boolean> boolean_result = p.getBooleanEvaluation("key", false, new EvaluationContext());
assertNotNull(boolean_result.getValue());

ProviderEvaluation<Structure> object_result = p.getObjectEvaluation("key", new Structure(), new EvaluationContext());
ProviderEvaluation<Value> object_result = p.getObjectEvaluation("key", new Value(), new EvaluationContext());
assertNotNull(object_result.getValue());

}
Expand Down

0 comments on commit 5d26247

Please sign in to comment.