Skip to content

Commit 8d6eec4

Browse files
committed
update to use SuperBuilder for MultiProviderEvaluation
Signed-off-by: Parth Suthar <parth.suthar@dynatrace.com>
1 parent 59b34a2 commit 8d6eec4

4 files changed

Lines changed: 13 additions & 91 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import lombok.Builder;
55
import lombok.Data;
66
import lombok.NoArgsConstructor;
7+
import lombok.experimental.SuperBuilder;
78

89
/**
910
* Contains information about how the a flag was evaluated, including the resolved value.
1011
*
1112
* @param <T> the type of the flag being evaluated.
1213
*/
1314
@Data
14-
@Builder
15+
@SuperBuilder
1516
@NoArgsConstructor
1617
@AllArgsConstructor
1718
public class ProviderEvaluation<T> implements BaseEvaluation<T> {

src/main/java/dev/openfeature/sdk/multiprovider/FirstMatchStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public <T> ProviderEvaluation<T> evaluate(
6464
}
6565

6666
// All providers either threw or returned FLAG_NOT_FOUND
67-
return MultiProviderEvaluation.<T>multiProviderBuilder()
67+
return MultiProviderEvaluation.<T>builder()
6868
.errorMessage(ProviderError.buildAggregateMessage("Flag not found in any provider", collectedErrors))
6969
.errorCode(FLAG_NOT_FOUND)
7070
.providerErrors(collectedErrors)

src/main/java/dev/openfeature/sdk/multiprovider/FirstSuccessfulStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public <T> ProviderEvaluation<T> evaluate(
4949
}
5050
}
5151

52-
return MultiProviderEvaluation.<T>multiProviderBuilder()
52+
return MultiProviderEvaluation.<T>builder()
5353
.errorMessage(
5454
ProviderError.buildAggregateMessage("No provider successfully responded", collectedErrors))
5555
.errorCode(ErrorCode.GENERAL)
Lines changed: 9 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package dev.openfeature.sdk.multiprovider;
22

3-
import dev.openfeature.sdk.ErrorCode;
4-
import dev.openfeature.sdk.ImmutableMetadata;
53
import dev.openfeature.sdk.ProviderEvaluation;
64
import java.util.Collections;
75
import java.util.List;
6+
import lombok.Builder;
7+
import lombok.Getter;
8+
import lombok.experimental.SuperBuilder;
89

910
/**
1011
* A {@link ProviderEvaluation} subtype returned by multi-provider strategies that carries
@@ -28,96 +29,16 @@
2829
*
2930
* @param <T> the type of the flag being evaluated
3031
*/
32+
@Getter
33+
@SuperBuilder
3134
public class MultiProviderEvaluation<T> extends ProviderEvaluation<T> {
3235

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-
4836
/**
49-
* Returns the per-provider error details.
37+
* Per-provider error details.
5038
*
5139
* <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.
6441
*/
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();
12344
}

0 commit comments

Comments
 (0)