11package dev .openfeature .sdk ;
22
3+ import dev .openfeature .sdk .internal .ExcludeFromGeneratedCoverageReport ;
34import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
45import java .util .Objects ;
6+ import lombok .EqualsAndHashCode ;
57import lombok .Generated ;
68import lombok .NonNull ;
9+ import lombok .ToString ;
710
811/**
912 * A data class to hold immutable context that {@link Hook} instances use.
1013 *
1114 * @param <T> the type for the flag being evaluated
1215 */
16+ @ EqualsAndHashCode
17+ @ ToString
1318public final class HookContext <T > {
1419 private final SharedHookContext <T > sharedContext ;
1520 private EvaluationContext ctx ;
@@ -93,7 +98,6 @@ public static <T> HookContextBuilder<T> builder() {
9398 return sharedContext .getFlagKey ();
9499 }
95100
96- @ Generated
97101 public @ NonNull FlagValueType getType () {
98102 return sharedContext .getType ();
99103 }
@@ -119,32 +123,6 @@ public HookData getHookData() {
119123 return this .hookData ;
120124 }
121125
122- @ Generated
123- @ Override
124- public boolean equals (Object o ) {
125- if (o == null || getClass () != o .getClass ()) {
126- return false ;
127- }
128- HookContext <?> that = (HookContext <?>) o ;
129- return Objects .equals (ctx , that .ctx )
130- && Objects .equals (hookData , that .hookData )
131- && Objects .equals (sharedContext , that .sharedContext );
132- }
133-
134- @ Generated
135- @ Override
136- public int hashCode () {
137- return Objects .hash (ctx , hookData , sharedContext );
138- }
139-
140- @ Generated
141- @ Override
142- public String toString () {
143- return "HookContext(flagKey=" + this .getFlagKey () + ", type=" + this .getType () + ", defaultValue="
144- + this .getDefaultValue () + ", ctx=" + this .getCtx () + ", clientMetadata=" + this .getClientMetadata ()
145- + ", providerMetadata=" + this .getProviderMetadata () + ", hookData=" + this .getHookData () + ")" ;
146- }
147-
148126 void setCtx (@ NonNull EvaluationContext ctx ) {
149127 this .ctx = ctx ;
150128 }
@@ -156,7 +134,7 @@ void setCtx(@NonNull EvaluationContext ctx) {
156134 * @return new HookContext with updated flagKey or the same instance if unchanged
157135 * @deprecated HookContext is initialized by the SDK and passed to hooks. Users should not create new instances.
158136 */
159- @ Generated
137+ @ ExcludeFromGeneratedCoverageReport
160138 @ Deprecated
161139 public HookContext <T > withFlagKey (@ NonNull String flagKey ) {
162140 return Objects .equals (this .getFlagKey (), flagKey )
@@ -178,7 +156,7 @@ public HookContext<T> withFlagKey(@NonNull String flagKey) {
178156 * @return new HookContext with updated type or the same instance if unchanged
179157 * @deprecated HookContext is initialized by the SDK and passed to hooks. Users should not create new instances.
180158 */
181- @ Generated
159+ @ ExcludeFromGeneratedCoverageReport
182160 @ Deprecated
183161 public HookContext <T > withType (@ NonNull FlagValueType type ) {
184162 return this .getType () == type
@@ -200,7 +178,7 @@ public HookContext<T> withType(@NonNull FlagValueType type) {
200178 * @return new HookContext with updated defaultValue or the same instance if unchanged
201179 * @deprecated HookContext is initialized by the SDK and passed to hooks. Users should not create new instances.
202180 */
203- @ Generated
181+ @ ExcludeFromGeneratedCoverageReport
204182 @ Deprecated
205183 public HookContext <T > withDefaultValue (@ NonNull T defaultValue ) {
206184 return this .getDefaultValue () == defaultValue
@@ -222,7 +200,7 @@ public HookContext<T> withDefaultValue(@NonNull T defaultValue) {
222200 * @return new HookContext with updated ctx or the same instance if unchanged
223201 * @deprecated HookContext is initialized by the SDK and passed to hooks. Users should not create new instances.
224202 */
225- @ Generated
203+ @ ExcludeFromGeneratedCoverageReport
226204 @ Deprecated
227205 public HookContext <T > withCtx (@ NonNull EvaluationContext ctx ) {
228206 return this .ctx == ctx
@@ -244,7 +222,7 @@ public HookContext<T> withCtx(@NonNull EvaluationContext ctx) {
244222 * @return new HookContext with updated clientMetadata or the same instance if unchanged
245223 * @deprecated HookContext is initialized by the SDK and passed to hooks. Users should not create new instances.
246224 */
247- @ Generated
225+ @ ExcludeFromGeneratedCoverageReport
248226 @ Deprecated
249227 public HookContext <T > withClientMetadata (ClientMetadata clientMetadata ) {
250228 return this .getClientMetadata () == clientMetadata
@@ -266,7 +244,7 @@ public HookContext<T> withClientMetadata(ClientMetadata clientMetadata) {
266244 * @return new HookContext with updated providerMetadata or the same instance if unchanged
267245 * @deprecated HookContext is initialized by the SDK and passed to hooks. Users should not create new instances.
268246 */
269- @ Generated
247+ @ ExcludeFromGeneratedCoverageReport
270248 @ Deprecated
271249 public HookContext <T > withProviderMetadata (Metadata providerMetadata ) {
272250 return this .getProviderMetadata () == providerMetadata
@@ -288,7 +266,7 @@ public HookContext<T> withProviderMetadata(Metadata providerMetadata) {
288266 * @return new HookContext with updated hookData or the same instance if unchanged
289267 * @deprecated HookContext is initialized by the SDK and passed to hooks. Users should not create new instances.
290268 */
291- @ Generated
269+ @ ExcludeFromGeneratedCoverageReport
292270 @ Deprecated
293271 public HookContext <T > withHookData (HookData hookData ) {
294272 return this .hookData == hookData
@@ -309,8 +287,8 @@ public HookContext<T> withHookData(HookData hookData) {
309287 * @param <T> The flag type.
310288 * @deprecated HookContext is initialized by the SDK and passed to hooks. Users should not create new instances.
311289 */
312- @ Generated
313290 @ Deprecated
291+ @ ToString
314292 public static class HookContextBuilder <T > {
315293 private String flagKey ;
316294 private FlagValueType type ;
@@ -322,37 +300,44 @@ public static class HookContextBuilder<T> {
322300
323301 HookContextBuilder () {}
324302
303+ @ ExcludeFromGeneratedCoverageReport
325304 public HookContextBuilder <T > flagKey (@ NonNull String flagKey ) {
326305 this .flagKey = flagKey ;
327306 return this ;
328307 }
329308
309+ @ ExcludeFromGeneratedCoverageReport
330310 public HookContextBuilder <T > type (@ NonNull FlagValueType type ) {
331311 this .type = type ;
332312 return this ;
333313 }
334314
315+ @ ExcludeFromGeneratedCoverageReport
335316 public HookContextBuilder <T > defaultValue (@ NonNull T defaultValue ) {
336317 this .defaultValue = defaultValue ;
337318 return this ;
338319 }
339320
321+ @ ExcludeFromGeneratedCoverageReport
340322 public HookContextBuilder <T > ctx (@ NonNull EvaluationContext ctx ) {
341323 this .ctx = ctx ;
342324 return this ;
343325 }
344326
327+ @ ExcludeFromGeneratedCoverageReport
345328 public HookContextBuilder <T > clientMetadata (ClientMetadata clientMetadata ) {
346329 this .clientMetadata = clientMetadata ;
347330 return this ;
348331 }
349332
333+ @ ExcludeFromGeneratedCoverageReport
350334 public HookContextBuilder <T > providerMetadata (Metadata providerMetadata ) {
351335 this .providerMetadata = providerMetadata ;
352336 return this ;
353337 }
354338
355339 @ SuppressFBWarnings (value = "EI_EXPOSE_REP2" , justification = "Intentional exposure of hookData" )
340+ @ ExcludeFromGeneratedCoverageReport
356341 public HookContextBuilder <T > hookData (HookData hookData ) {
357342 this .hookData = hookData ;
358343 return this ;
@@ -363,6 +348,7 @@ public HookContextBuilder<T> hookData(HookData hookData) {
363348 *
364349 * @return a new HookContext
365350 */
351+ @ ExcludeFromGeneratedCoverageReport
366352 public HookContext <T > build () {
367353 return new HookContext <T >(
368354 this .flagKey ,
@@ -373,13 +359,5 @@ public HookContext<T> build() {
373359 this .providerMetadata ,
374360 this .hookData );
375361 }
376-
377- @ Generated
378- @ Override
379- public String toString () {
380- return "HookContext.HookContextBuilder(flagKey=" + this .flagKey + ", type=" + this .type + ", defaultValue="
381- + this .defaultValue + ", ctx=" + this .ctx + ", clientMetadata=" + this .clientMetadata
382- + ", providerMetadata=" + this .providerMetadata + ", hookData=" + this .hookData + ")" ;
383- }
384362 }
385363}
0 commit comments