Skip to content

Commit 5fb278b

Browse files
feat: hook executor impl (WIP)
Signed-off-by: Alexandra Oberaigner <[email protected]>
1 parent 3b113c1 commit 5fb278b

File tree

8 files changed

+394
-229
lines changed

8 files changed

+394
-229
lines changed

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

Lines changed: 237 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,41 @@
11
package dev.openfeature.sdk;
22

3-
import lombok.Builder;
4-
import lombok.Data;
53
import lombok.NonNull;
6-
import lombok.With;
74

85
/**
96
* A data class to hold immutable context that {@link Hook} instances use.
107
*
118
* @param <T> the type for the flag being evaluated
129
*/
13-
@Data
14-
@Builder
15-
@With
16-
public class HookContext<T> {
17-
@NonNull String flagKey;
10+
public final class HookContext<T> {
11+
@NonNull
12+
private final String flagKey;
1813

19-
@NonNull FlagValueType type;
14+
@NonNull
15+
private final FlagValueType type;
2016

21-
@NonNull T defaultValue;
17+
@NonNull
18+
private final T defaultValue;
2219

23-
@NonNull EvaluationContext ctx;
20+
@NonNull
21+
private EvaluationContext ctx;
2422

25-
ClientMetadata clientMetadata;
26-
Metadata providerMetadata;
23+
private final ClientMetadata clientMetadata;
24+
private final Metadata providerMetadata;
25+
26+
private final HookData hookData;
27+
28+
HookContext(@NonNull String flagKey, @NonNull FlagValueType type, @NonNull T defaultValue,
29+
@NonNull EvaluationContext ctx, ClientMetadata clientMetadata, Metadata providerMetadata,
30+
HookData hookData) {
31+
this.flagKey = flagKey;
32+
this.type = type;
33+
this.defaultValue = defaultValue;
34+
this.ctx = ctx;
35+
this.clientMetadata = clientMetadata;
36+
this.providerMetadata = providerMetadata;
37+
this.hookData = hookData;
38+
}
2739

2840
/**
2941
* Builds {@link HookContext} instances from request data.
@@ -51,10 +63,220 @@ public static <T> HookContext<T> from(
5163
.providerMetadata(providerMetadata)
5264
.ctx(ctx)
5365
.defaultValue(defaultValue)
66+
.hookData(null)
5467
.build();
5568
}
5669

57-
HookData getHookData() {
58-
return null;
70+
public static <T> HookContextBuilder<T> builder() {return new HookContextBuilder<T>();}
71+
72+
public @NonNull String getFlagKey() {
73+
return this.flagKey;
74+
}
75+
76+
public @NonNull FlagValueType getType() {
77+
return this.type;
78+
}
79+
80+
public @NonNull T getDefaultValue() {
81+
return this.defaultValue;
82+
}
83+
84+
public @NonNull EvaluationContext getCtx() {
85+
return this.ctx;
86+
}
87+
88+
public ClientMetadata getClientMetadata() {
89+
return this.clientMetadata;
90+
}
91+
92+
public Metadata getProviderMetadata() {
93+
return this.providerMetadata;
94+
}
95+
96+
public HookData getHookData() {
97+
return this.hookData;
98+
}
99+
100+
@Override
101+
public boolean equals(final Object o) {
102+
if (o == this) {
103+
return true;
104+
}
105+
if (!(o instanceof HookContext)) {
106+
return false;
107+
}
108+
final HookContext<?> other = (HookContext<?>) o;
109+
final Object this$flagKey = this.getFlagKey();
110+
final Object other$flagKey = other.getFlagKey();
111+
if (this$flagKey == null ? other$flagKey != null : !this$flagKey.equals(other$flagKey)) {
112+
return false;
113+
}
114+
final Object this$type = this.getType();
115+
final Object other$type = other.getType();
116+
if (this$type == null ? other$type != null : !this$type.equals(other$type)) {
117+
return false;
118+
}
119+
final Object this$defaultValue = this.getDefaultValue();
120+
final Object other$defaultValue = other.getDefaultValue();
121+
if (this$defaultValue == null ? other$defaultValue != null : !this$defaultValue.equals(other$defaultValue)) {
122+
return false;
123+
}
124+
final Object this$ctx = this.getCtx();
125+
final Object other$ctx = other.getCtx();
126+
if (this$ctx == null ? other$ctx != null : !this$ctx.equals(other$ctx)) {
127+
return false;
128+
}
129+
final Object this$clientMetadata = this.getClientMetadata();
130+
final Object other$clientMetadata = other.getClientMetadata();
131+
if (this$clientMetadata == null
132+
? other$clientMetadata != null
133+
: !this$clientMetadata.equals(other$clientMetadata)) {
134+
return false;
135+
}
136+
final Object this$providerMetadata = this.getProviderMetadata();
137+
final Object other$providerMetadata = other.getProviderMetadata();
138+
if (this$providerMetadata == null
139+
? other$providerMetadata != null
140+
: !this$providerMetadata.equals(other$providerMetadata)) {
141+
return false;
142+
}
143+
final Object this$hookData = this.getHookData();
144+
final Object other$hookData = other.getHookData();
145+
if (this$hookData == null ? other$hookData != null : !this$hookData.equals(other$hookData)) {
146+
return false;
147+
}
148+
return true;
149+
}
150+
151+
@Override
152+
public int hashCode() {
153+
final int PRIME = 59;
154+
int result = 1;
155+
final Object $flagKey = this.getFlagKey();
156+
result = result * PRIME + ($flagKey == null ? 43 : $flagKey.hashCode());
157+
final Object $type = this.getType();
158+
result = result * PRIME + ($type == null ? 43 : $type.hashCode());
159+
final Object $defaultValue = this.getDefaultValue();
160+
result = result * PRIME + ($defaultValue == null ? 43 : $defaultValue.hashCode());
161+
final Object $ctx = this.getCtx();
162+
result = result * PRIME + ($ctx == null ? 43 : $ctx.hashCode());
163+
final Object $clientMetadata = this.getClientMetadata();
164+
result = result * PRIME + ($clientMetadata == null ? 43 : $clientMetadata.hashCode());
165+
final Object $providerMetadata = this.getProviderMetadata();
166+
result = result * PRIME + ($providerMetadata == null ? 43 : $providerMetadata.hashCode());
167+
final Object $hookData = this.getHookData();
168+
result = result * PRIME + ($hookData == null ? 43 : $hookData.hashCode());
169+
return result;
170+
}
171+
172+
@Override
173+
public String toString() {
174+
return "HookContext(flagKey=" + this.getFlagKey() + ", type=" + this.getType() + ", defaultValue="
175+
+ this.getDefaultValue() + ", ctx=" + this.getCtx() + ", clientMetadata=" + this.getClientMetadata()
176+
+ ", providerMetadata=" + this.getProviderMetadata() + ", hookData=" + this.getHookData() + ")";
177+
}
178+
179+
void setCtx(@NonNull EvaluationContext ctx) {
180+
this.ctx = ctx;
181+
}
182+
183+
public HookContext<T> withFlagKey(@NonNull String flagKey) {
184+
return this.flagKey == flagKey ? this
185+
: new HookContext<T>(flagKey, this.type, this.defaultValue, this.ctx, this.clientMetadata,
186+
this.providerMetadata, this.hookData);
187+
}
188+
189+
public HookContext<T> withType(@NonNull FlagValueType type) {
190+
return this.type == type ? this
191+
: new HookContext<T>(this.flagKey, type, this.defaultValue, this.ctx, this.clientMetadata,
192+
this.providerMetadata, this.hookData);
193+
}
194+
195+
public HookContext<T> withDefaultValue(@NonNull T defaultValue) {
196+
return this.defaultValue == defaultValue ? this
197+
: new HookContext<T>(this.flagKey, this.type, defaultValue, this.ctx, this.clientMetadata,
198+
this.providerMetadata, this.hookData);
199+
}
200+
201+
public HookContext<T> withCtx(@NonNull EvaluationContext ctx) {
202+
return this.ctx == ctx ? this
203+
: new HookContext<T>(this.flagKey, this.type, this.defaultValue, ctx, this.clientMetadata,
204+
this.providerMetadata, this.hookData);
205+
}
206+
207+
public HookContext<T> withClientMetadata(ClientMetadata clientMetadata) {
208+
return this.clientMetadata == clientMetadata ? this
209+
: new HookContext<T>(this.flagKey, this.type, this.defaultValue, this.ctx, clientMetadata,
210+
this.providerMetadata, this.hookData);
211+
}
212+
213+
public HookContext<T> withProviderMetadata(Metadata providerMetadata) {
214+
return this.providerMetadata == providerMetadata ? this
215+
: new HookContext<T>(this.flagKey, this.type, this.defaultValue, this.ctx, this.clientMetadata,
216+
providerMetadata, this.hookData);
217+
}
218+
219+
public HookContext<T> withHookData(HookData hookData) {
220+
return this.hookData == hookData ? this
221+
: new HookContext<T>(this.flagKey, this.type, this.defaultValue, this.ctx, this.clientMetadata,
222+
this.providerMetadata, hookData);
223+
}
224+
225+
public static class HookContextBuilder<T> {
226+
private @NonNull String flagKey;
227+
private @NonNull FlagValueType type;
228+
private @NonNull T defaultValue;
229+
private @NonNull EvaluationContext ctx;
230+
private ClientMetadata clientMetadata;
231+
private Metadata providerMetadata;
232+
private HookData hookData;
233+
234+
HookContextBuilder() {}
235+
236+
public HookContextBuilder<T> flagKey(@NonNull String flagKey) {
237+
this.flagKey = flagKey;
238+
return this;
239+
}
240+
241+
public HookContextBuilder<T> type(@NonNull FlagValueType type) {
242+
this.type = type;
243+
return this;
244+
}
245+
246+
public HookContextBuilder<T> defaultValue(@NonNull T defaultValue) {
247+
this.defaultValue = defaultValue;
248+
return this;
249+
}
250+
251+
public HookContextBuilder<T> ctx(@NonNull EvaluationContext ctx) {
252+
this.ctx = ctx;
253+
return this;
254+
}
255+
256+
public HookContextBuilder<T> clientMetadata(ClientMetadata clientMetadata) {
257+
this.clientMetadata = clientMetadata;
258+
return this;
259+
}
260+
261+
public HookContextBuilder<T> providerMetadata(Metadata providerMetadata) {
262+
this.providerMetadata = providerMetadata;
263+
return this;
264+
}
265+
266+
public HookContextBuilder<T> hookData(HookData hookData) {
267+
this.hookData = hookData;
268+
return this;
269+
}
270+
271+
public HookContext<T> build() {
272+
return new HookContext<T>(this.flagKey, this.type, this.defaultValue, this.ctx, this.clientMetadata,
273+
this.providerMetadata, this.hookData);
274+
}
275+
276+
public String toString() {
277+
return "HookContext.HookContextBuilder(flagKey=" + this.flagKey + ", type=" + this.type + ", defaultValue="
278+
+ this.defaultValue + ", ctx=" + this.ctx + ", clientMetadata=" + this.clientMetadata
279+
+ ", providerMetadata=" + this.providerMetadata + ", hookData=" + this.hookData + ")";
280+
}
59281
}
60282
}

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

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

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)