|
1 | 1 | package dev.openfeature.sdk.multiprovider; |
2 | 2 |
|
3 | | -import dev.openfeature.sdk.ErrorCode; |
4 | | -import dev.openfeature.sdk.ImmutableMetadata; |
5 | 3 | import dev.openfeature.sdk.ProviderEvaluation; |
6 | 4 | import java.util.Collections; |
7 | 5 | import java.util.List; |
| 6 | +import lombok.Builder; |
| 7 | +import lombok.Getter; |
| 8 | +import lombok.experimental.SuperBuilder; |
8 | 9 |
|
9 | 10 | /** |
10 | 11 | * A {@link ProviderEvaluation} subtype returned by multi-provider strategies that carries |
|
28 | 29 | * |
29 | 30 | * @param <T> the type of the flag being evaluated |
30 | 31 | */ |
| 32 | +@Getter |
| 33 | +@SuperBuilder |
31 | 34 | public class MultiProviderEvaluation<T> extends ProviderEvaluation<T> { |
32 | 35 |
|
33 | | - private final List<ProviderError> providerErrors; |
34 | | - |
35 | | - private MultiProviderEvaluation( |
36 | | - T value, |
37 | | - String variant, |
38 | | - String reason, |
39 | | - ErrorCode errorCode, |
40 | | - String errorMessage, |
41 | | - ImmutableMetadata flagMetadata, |
42 | | - List<ProviderError> providerErrors) { |
43 | | - super(value, variant, reason, errorCode, errorMessage, flagMetadata); |
44 | | - this.providerErrors = |
45 | | - providerErrors != null ? Collections.unmodifiableList(providerErrors) : Collections.emptyList(); |
46 | | - } |
47 | | - |
48 | 36 | /** |
49 | | - * Returns the per-provider error details. |
| 37 | + * Per-provider error details. |
50 | 38 | * |
51 | 39 | * <p>Each entry describes why a specific provider failed during multi-provider evaluation. |
52 | | - * |
53 | | - * @return an unmodifiable list of per-provider errors, never {@code null} |
54 | | - */ |
55 | | - public List<ProviderError> getProviderErrors() { |
56 | | - return providerErrors; |
57 | | - } |
58 | | - |
59 | | - /** |
60 | | - * Create a new builder for {@link MultiProviderEvaluation}. |
61 | | - * |
62 | | - * @param <T> the flag value type |
63 | | - * @return a new builder |
| 40 | + * Defaults to an empty list when not set. |
64 | 41 | */ |
65 | | - public static <T> Builder<T> multiProviderBuilder() { |
66 | | - return new Builder<>(); |
67 | | - } |
68 | | - |
69 | | - /** |
70 | | - * Builder for {@link MultiProviderEvaluation}. |
71 | | - * |
72 | | - * @param <T> the flag value type |
73 | | - */ |
74 | | - public static class Builder<T> { |
75 | | - private T value; |
76 | | - private String variant; |
77 | | - private String reason; |
78 | | - private ErrorCode errorCode; |
79 | | - private String errorMessage; |
80 | | - private ImmutableMetadata flagMetadata; |
81 | | - private List<ProviderError> providerErrors; |
82 | | - |
83 | | - public Builder<T> value(T value) { |
84 | | - this.value = value; |
85 | | - return this; |
86 | | - } |
87 | | - |
88 | | - public Builder<T> variant(String variant) { |
89 | | - this.variant = variant; |
90 | | - return this; |
91 | | - } |
92 | | - |
93 | | - public Builder<T> reason(String reason) { |
94 | | - this.reason = reason; |
95 | | - return this; |
96 | | - } |
97 | | - |
98 | | - public Builder<T> errorCode(ErrorCode errorCode) { |
99 | | - this.errorCode = errorCode; |
100 | | - return this; |
101 | | - } |
102 | | - |
103 | | - public Builder<T> errorMessage(String errorMessage) { |
104 | | - this.errorMessage = errorMessage; |
105 | | - return this; |
106 | | - } |
107 | | - |
108 | | - public Builder<T> flagMetadata(ImmutableMetadata flagMetadata) { |
109 | | - this.flagMetadata = flagMetadata; |
110 | | - return this; |
111 | | - } |
112 | | - |
113 | | - public Builder<T> providerErrors(List<ProviderError> providerErrors) { |
114 | | - this.providerErrors = providerErrors; |
115 | | - return this; |
116 | | - } |
117 | | - |
118 | | - public MultiProviderEvaluation<T> build() { |
119 | | - return new MultiProviderEvaluation<>( |
120 | | - value, variant, reason, errorCode, errorMessage, flagMetadata, providerErrors); |
121 | | - } |
122 | | - } |
| 42 | + @Builder.Default |
| 43 | + private List<ProviderError> providerErrors = Collections.emptyList(); |
123 | 44 | } |
0 commit comments