Skip to content

Commit 89ea363

Browse files
Merge pull request open-feature#65 from open-feature/breaking-changes
Collection of small, breaking changes
2 parents 35c9c7e + 60fad05 commit 89ea363

15 files changed

+128
-56
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dev.openfeature.javasdk;
22

3-
import java.time.ZonedDateTime;
3+
import java.time.Instant;
44
import java.util.List;
55

66
import lombok.Getter;
@@ -76,7 +76,7 @@ public EvaluationContext add(String key, Double value) {
7676
return this;
7777
}
7878

79-
public EvaluationContext add(String key, ZonedDateTime value) {
79+
public EvaluationContext add(String key, Instant value) {
8080
this.structure.add(key, value);
8181
return this;
8282
}
@@ -123,7 +123,7 @@ public Structure add(String ignoredKey, Structure ignoredValue) {
123123
return null;
124124
}
125125

126-
public Structure add(String ignoredKey, ZonedDateTime ignoredValue) {
126+
public Structure add(String ignoredKey, Instant ignoredValue) {
127127
return null;
128128
}
129129
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ default List<Hook> getProviderHooks() {
2121

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

24-
ProviderEvaluation<Structure> getObjectEvaluation(String key, Structure defaultValue, EvaluationContext ctx);
24+
ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue, EvaluationContext ctx);
2525
}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ FlagEvaluationDetails<Integer> getIntegerDetails(String key, Integer defaultValu
5757
FlagEvaluationDetails<Double> getDoubleDetails(String key, Double defaultValue, EvaluationContext ctx,
5858
FlagEvaluationOptions options);
5959

60-
Structure getObjectValue(String key, Structure defaultValue);
60+
Value getObjectValue(String key, Value defaultValue);
6161

62-
Structure getObjectValue(String key, Structure defaultValue, EvaluationContext ctx);
62+
Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx);
6363

64-
Structure getObjectValue(String key, Structure defaultValue, EvaluationContext ctx,
64+
Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx,
6565
FlagEvaluationOptions options);
6666

67-
FlagEvaluationDetails<Structure> getObjectDetails(String key, Structure defaultValue);
67+
FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue);
6868

69-
FlagEvaluationDetails<Structure> getObjectDetails(String key, Structure defaultValue,
69+
FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue,
7070
EvaluationContext ctx);
7171

72-
FlagEvaluationDetails<Structure> getObjectDetails(String key, Structure defaultValue,
72+
FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue,
7373
EvaluationContext ctx,
7474
FlagEvaluationOptions options);
7575
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double default
5757
}
5858

5959
@Override
60-
public ProviderEvaluation<Structure> getObjectEvaluation(String key, Structure defaultValue,
60+
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue,
6161
EvaluationContext invocationContext) {
62-
return ProviderEvaluation.<Structure>builder()
62+
return ProviderEvaluation.<Value>builder()
6363
.value(defaultValue)
6464
.variant(PASSED_IN_DEFAULT)
6565
.reason(Reason.DEFAULT)

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private <T> ProviderEvaluation<?> createProviderEvaluation(
122122
case DOUBLE:
123123
return provider.getDoubleEvaluation(key, (Double) defaultValue, invocationContext);
124124
case OBJECT:
125-
return provider.getObjectEvaluation(key, (Structure) defaultValue, invocationContext);
125+
return provider.getObjectEvaluation(key, (Value) defaultValue, invocationContext);
126126
default:
127127
throw new GeneralError("Unknown flag type");
128128
}
@@ -257,34 +257,34 @@ public FlagEvaluationDetails<Double> getDoubleDetails(String key, Double default
257257
}
258258

259259
@Override
260-
public Structure getObjectValue(String key, Structure defaultValue) {
260+
public Value getObjectValue(String key, Value defaultValue) {
261261
return getObjectDetails(key, defaultValue).getValue();
262262
}
263263

264264
@Override
265-
public Structure getObjectValue(String key, Structure defaultValue, EvaluationContext ctx) {
265+
public Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx) {
266266
return getObjectDetails(key, defaultValue, ctx).getValue();
267267
}
268268

269269
@Override
270-
public Structure getObjectValue(String key, Structure defaultValue, EvaluationContext ctx,
270+
public Value getObjectValue(String key, Value defaultValue, EvaluationContext ctx,
271271
FlagEvaluationOptions options) {
272272
return getObjectDetails(key, defaultValue, ctx, options).getValue();
273273
}
274274

275275
@Override
276-
public FlagEvaluationDetails<Structure> getObjectDetails(String key, Structure defaultValue) {
276+
public FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue) {
277277
return getObjectDetails(key, defaultValue, null);
278278
}
279279

280280
@Override
281-
public FlagEvaluationDetails<Structure> getObjectDetails(String key, Structure defaultValue,
281+
public FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue,
282282
EvaluationContext ctx) {
283283
return getObjectDetails(key, defaultValue, ctx, FlagEvaluationOptions.builder().build());
284284
}
285285

286286
@Override
287-
public FlagEvaluationDetails<Structure> getObjectDetails(String key, Structure defaultValue, EvaluationContext ctx,
287+
public FlagEvaluationDetails<Value> getObjectDetails(String key, Value defaultValue, EvaluationContext ctx,
288288
FlagEvaluationOptions options) {
289289
return this.evaluateFlag(FlagValueType.OBJECT, key, defaultValue, ctx, options);
290290
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dev.openfeature.javasdk;
22

3-
import java.time.ZonedDateTime;
3+
import java.time.Instant;
44
import java.util.HashMap;
55
import java.util.List;
66
import java.util.Map;
@@ -73,7 +73,7 @@ public Structure add(String key, Double value) {
7373
* @param value date-time value
7474
* @return Structure
7575
*/
76-
public Structure add(String key, ZonedDateTime value) {
76+
public Structure add(String key, Instant value) {
7777
attributes.put(key, new Value(value));
7878
return this;
7979
}

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

+41-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package dev.openfeature.javasdk;
22

3-
import java.time.ZonedDateTime;
3+
import java.time.Instant;
44
import java.util.List;
55

66
import lombok.EqualsAndHashCode;
77
import lombok.ToString;
88

99
/**
10-
* Values serve as a return type for provider objects.
10+
* Values serve as a generic return type for structure data from providers.
1111
* Providers may deal in JSON, protobuf, XML or some other data-interchange format.
1212
* This intermediate representation provides a good medium of exchange.
1313
*/
@@ -19,7 +19,27 @@ public class Value {
1919
private final Object innerObject;
2020

2121
public Value() {
22-
this.innerObject = null;
22+
this.innerObject = null;
23+
}
24+
25+
/**
26+
* Construct a new Value with an Object.
27+
* @param value to be wrapped.
28+
* @throws InstantiationException if value is not a valid type
29+
* (boolean, string, int, double, list, structure, instant)
30+
*/
31+
public Value(Object value) throws InstantiationException {
32+
// integer is a special case, convert those.
33+
this.innerObject = value instanceof Integer ? ((Integer)value).doubleValue() : value;
34+
if (!this.isNull()
35+
&& !this.isBoolean()
36+
&& !this.isString()
37+
&& !this.isNumber()
38+
&& !this.isStructure()
39+
&& !this.isList()
40+
&& !this.isInstant()) {
41+
throw new InstantiationException("Invalid value type: " + value.getClass());
42+
}
2343
}
2444

2545
public Value(Value value) {
@@ -50,7 +70,7 @@ public Value(List<Value> value) {
5070
this.innerObject = value;
5171
}
5272

53-
public Value(ZonedDateTime value) {
73+
public Value(Instant value) {
5474
this.innerObject = value;
5575
}
5676

@@ -109,12 +129,12 @@ public boolean isList() {
109129
}
110130

111131
/**
112-
* Check if this Value represents a ZonedDateTime.
132+
* Check if this Value represents an Instant.
113133
*
114134
* @return boolean
115135
*/
116-
public boolean isZonedDateTime() {
117-
return this.innerObject instanceof ZonedDateTime;
136+
public boolean isInstant() {
137+
return this.innerObject instanceof Instant;
118138
}
119139

120140
/**
@@ -131,6 +151,15 @@ public Boolean asBoolean() {
131151
return null;
132152
}
133153

154+
/**
155+
* Retrieve the underlying object.
156+
*
157+
* @return Object
158+
*/
159+
public Object asObject() {
160+
return this.innerObject;
161+
}
162+
134163
/**
135164
* Retrieve the underlying String value, or null.
136165
*
@@ -194,13 +223,13 @@ public List<Value> asList() {
194223
}
195224

196225
/**
197-
* Retrieve the underlying ZonedDateTime value, or null.
226+
* Retrieve the underlying Instant value, or null.
198227
*
199-
* @return ZonedDateTime
228+
* @return Instant
200229
*/
201-
public ZonedDateTime asZonedDateTime() {
202-
if (this.isZonedDateTime()) {
203-
return (ZonedDateTime)this.innerObject;
230+
public Instant asInstant() {
231+
if (this.isInstant()) {
232+
return (Instant)this.innerObject;
204233
}
205234
return null;
206235
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double default
3333
}
3434

3535
@Override
36-
public ProviderEvaluation<Structure> getObjectEvaluation(String key, Structure defaultValue, EvaluationContext invocationContext) {
36+
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue, EvaluationContext invocationContext) {
3737
throw new NotImplementedException("BORK");
3838
}
3939
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double default
4444
}
4545

4646
@Override
47-
public ProviderEvaluation<Structure> getObjectEvaluation(String key, Structure defaultValue, EvaluationContext invocationContext) {
47+
public ProviderEvaluation<Value> getObjectEvaluation(String key, Value defaultValue, EvaluationContext invocationContext) {
4848
savedContext = invocationContext;
49-
return ProviderEvaluation.<Structure>builder()
49+
return ProviderEvaluation.<Value>builder()
5050
.value(null)
5151
.build();
5252
}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44

5-
import java.time.ZonedDateTime;
5+
import java.time.Instant;
66
import java.util.ArrayList;
77
import java.util.List;
88
import java.util.Map;
@@ -34,9 +34,9 @@ public class EvalContextTest {
3434
ec.add("int", 4);
3535
assertEquals(4, ec.getValue("int").asInteger());
3636

37-
ZonedDateTime dt = ZonedDateTime.now();
37+
Instant dt = Instant.now();
3838
ec.add("dt", dt);
39-
assertEquals(dt, ec.getValue("dt").asZonedDateTime());
39+
assertEquals(dt, ec.getValue("dt").asInstant());
4040
}
4141

4242
@Specification(number="3.1.2", text="The evaluation context MUST support the inclusion of " +
@@ -72,7 +72,7 @@ public class EvalContextTest {
7272
ec.add("int", 4);
7373
ec.add("int2", 2);
7474

75-
ZonedDateTime dt = ZonedDateTime.now();
75+
Instant dt = Instant.now();
7676
ec.add("dt", dt);
7777

7878
ec.add("obj", new Structure().add("val1", 1).add("val2", "2"));
@@ -121,14 +121,14 @@ public class EvalContextTest {
121121
.add("Double", (Double)null)
122122
.add("Structure", (Structure)null)
123123
.add("List", (List<Value>)null)
124-
.add("ZonedDateTime", (ZonedDateTime)null);
124+
.add("Instant", (Instant)null);
125125
assertEquals(6, ec.asMap().size());
126126
assertEquals(null, ec.getValue("Boolean").asBoolean());
127127
assertEquals(null, ec.getValue("String").asString());
128128
assertEquals(null, ec.getValue("Double").asDouble());
129129
assertEquals(null, ec.getValue("Structure").asStructure());
130130
assertEquals(null, ec.getValue("List").asList());
131-
assertEquals(null, ec.getValue("ZonedDateTime").asString());
131+
assertEquals(null, ec.getValue("Instant").asString());
132132
}
133133

134134
@Test void merge_targeting_key() {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ private Client _client() {
115115
assertEquals(40.0, c.getDoubleValue(key, .4, new EvaluationContext()));
116116
assertEquals(40.0, c.getDoubleValue(key, .4, new EvaluationContext(), FlagEvaluationOptions.builder().build()));
117117

118-
assertEquals(null, c.getObjectValue(key, new Structure()));
119-
assertEquals(null, c.getObjectValue(key, new Structure(), new EvaluationContext()));
120-
assertEquals(null, c.getObjectValue(key, new Structure(), new EvaluationContext(), FlagEvaluationOptions.builder().build()));
118+
assertEquals(null, c.getObjectValue(key, new Value()));
119+
assertEquals(null, c.getObjectValue(key, new Value(), new EvaluationContext()));
120+
assertEquals(null, c.getObjectValue(key, new Value(), new EvaluationContext(), FlagEvaluationOptions.builder().build()));
121121
}
122122

123123
@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.")

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public class NoOpProviderTest {
3030
assertEquals(0.4, eval.getValue());
3131
}
3232

33-
@Test void structure() {
33+
@Test void value() {
3434
NoOpProvider p = new NoOpProvider();
35-
Structure s = new Structure();
36-
ProviderEvaluation<Structure> eval = p.getObjectEvaluation("key", s, null);
35+
Value s = new Value();
36+
ProviderEvaluation<Value> eval = p.getObjectEvaluation("key", s, null);
3737
assertEquals(s, eval.getValue());
3838
}
3939
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class ProviderSpecTest {
3636
ProviderEvaluation<Boolean> boolean_result = p.getBooleanEvaluation("key", false, new EvaluationContext());
3737
assertNotNull(boolean_result.getValue());
3838

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

4242
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import static org.junit.jupiter.api.Assertions.assertNotSame;
55
import static org.junit.jupiter.api.Assertions.assertTrue;
66

7-
import java.time.ZonedDateTime;
7+
import java.time.Instant;
88
import java.util.ArrayList;
99
import java.util.HashMap;
1010
import java.util.List;
@@ -44,7 +44,7 @@ public class StructureTest {
4444
String STRING_VAL = "val";
4545
int INT_VAL = 13;
4646
double DOUBLE_VAL = .5;
47-
ZonedDateTime DATE_VAL = ZonedDateTime.now();
47+
Instant DATE_VAL = Instant.now();
4848
Structure STRUCT_VAL = new Structure();
4949
List<Value> LIST_VAL = new ArrayList<Value>();
5050
Value VALUE_VAL = new Value();
@@ -63,7 +63,7 @@ public class StructureTest {
6363
assertEquals(STRING_VAL, structure.getValue(STRING_KEY).asString());
6464
assertEquals(INT_VAL, structure.getValue(INT_KEY).asInteger());
6565
assertEquals(DOUBLE_VAL, structure.getValue(DOUBLE_KEY).asDouble());
66-
assertEquals(DATE_VAL, structure.getValue(DATE_KEY).asZonedDateTime());
66+
assertEquals(DATE_VAL, structure.getValue(DATE_KEY).asInstant());
6767
assertEquals(STRUCT_VAL, structure.getValue(STRUCT_KEY).asStructure());
6868
assertEquals(LIST_VAL, structure.getValue(LIST_KEY).asList());
6969
assertTrue(structure.getValue(VALUE_KEY).isNull());

0 commit comments

Comments
 (0)