Skip to content

Commit 14638db

Browse files
committed
fixup: pr comments
Signed-off-by: Simon Schrottner <[email protected]>
1 parent 711e0be commit 14638db

File tree

6 files changed

+13
-45
lines changed

6 files changed

+13
-45
lines changed

src/main/java/dev/openfeature/sdk/HookContext.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
/**
66
* A interface to hold immutable context that {@link Hook} instances use.
7-
*
87
*/
98
public interface HookContext<T> {
109
/**
@@ -18,7 +17,6 @@ public interface HookContext<T> {
1817
* @param defaultValue Fallback value
1918
* @param <T> type that the flag is evaluating against
2019
* @return resulting context for hook
21-
*
2220
* @deprecated this should not be instantiated outside the SDK anymore
2321
*/
2422
@Deprecated
@@ -29,14 +27,7 @@ static <T> HookContext<T> from(
2927
Metadata providerMetadata,
3028
EvaluationContext ctx,
3129
T defaultValue) {
32-
return HookContextWithoutData.<T>builder()
33-
.flagKey(key)
34-
.type(type)
35-
.clientMetadata(clientMetadata)
36-
.providerMetadata(providerMetadata)
37-
.ctx(ctx)
38-
.defaultValue(defaultValue)
39-
.build();
30+
return new HookContextWithoutData<>(key, type, defaultValue, ctx, clientMetadata, providerMetadata);
4031
}
4132

4233
/**

src/main/java/dev/openfeature/sdk/HookContextWithoutData.java

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
package dev.openfeature.sdk;
22

3-
import lombok.AccessLevel;
4-
import lombok.Builder;
5-
import lombok.Data;
6-
import lombok.NonNull;
7-
import lombok.Setter;
8-
import lombok.With;
3+
import lombok.*;
94

105
/**
116
* A data class to hold immutable context that {@link Hook} instances use.
@@ -36,25 +31,13 @@ class HookContextWithoutData<T> implements HookContext<T> {
3631
* @param type flag value type
3732
* @param clientMetadata info on which client is calling
3833
* @param providerMetadata info on the provider
39-
* @param ctx Evaluation Context for the request
4034
* @param defaultValue Fallback value
4135
* @param <T> type that the flag is evaluating against
4236
* @return resulting context for hook
4337
*/
4438
static <T> HookContextWithoutData<T> from(
45-
String key,
46-
FlagValueType type,
47-
ClientMetadata clientMetadata,
48-
Metadata providerMetadata,
49-
EvaluationContext ctx,
50-
T defaultValue) {
51-
return HookContextWithoutData.<T>builder()
52-
.flagKey(key)
53-
.type(type)
54-
.clientMetadata(clientMetadata)
55-
.providerMetadata(providerMetadata)
56-
.ctx(ImmutableContext.EMPTY)
57-
.defaultValue(defaultValue)
58-
.build();
39+
String key, FlagValueType type, ClientMetadata clientMetadata, Metadata providerMetadata, T defaultValue) {
40+
return new HookContextWithoutData<>(
41+
key, type, defaultValue, ImmutableContext.EMPTY, clientMetadata, providerMetadata);
5942
}
6043
}

src/main/java/dev/openfeature/sdk/HookData.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ static HookData create() {
4747
/**
4848
* Default implementation of HookData.
4949
*/
50-
public class DefaultHookData implements HookData {
50+
class DefaultHookData implements HookData {
5151
private Map<String, Object> data;
5252

5353
@Override
5454
public void set(String key, Object value) {
55-
if(data == null) {
55+
if (data == null) {
5656
data = new HashMap<>();
5757
}
5858
data.put(key, value);
5959
}
6060

6161
@Override
6262
public Object get(String key) {
63-
if(data == null) {
63+
if (data == null) {
6464
return null;
6565
}
6666
return data.get(key);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,11 @@ private <T> FlagEvaluationDetails<T> evaluateFlag(
173173
// provider must be accessed once to maintain a consistent reference
174174
final var provider = stateManager.getProvider();
175175
final var state = stateManager.getState();
176-
hookContext = HookContextWithoutData.from(
177-
key, type, this.getMetadata(), provider.getMetadata(), null, defaultValue);
176+
hookContext =
177+
HookContextWithoutData.from(key, type, this.getMetadata(), provider.getMetadata(), defaultValue);
178178

179+
// we are setting the evaluation context one after the other, so that we have a hook context in each
180+
// possible exception case.
179181
hookContext.setCtx(mergeEvaluationContext(ctx));
180182

181183
mergedHooks = ObjectUtils.merge(

src/main/java/dev/openfeature/sdk/Pair.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ private Pair(K key, V value) {
99
this.value = value;
1010
}
1111

12-
public K getKey() {
13-
return key;
14-
}
15-
16-
public V getValue() {
17-
return value;
18-
}
19-
2012
public K getLeft() {
2113
return key;
2214
}

src/test/java/dev/openfeature/sdk/HookContextTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void shouldCreateHookContextWithHookData() {
3535
HookData hookData = HookData.create();
3636
hookData.set("test", "value");
3737

38-
HookContext<String> context = HookContextWithData.of(null, hookData);
38+
HookContextWithData context = HookContextWithData.of(mock(HookContext.class), hookData);
3939

4040
assertNotNull(context.getHookData());
4141
assertEquals("value", context.getHookData().get("test"));

0 commit comments

Comments
 (0)