@@ -95,6 +95,32 @@ public static enum ErrorKind {
9595 */
9696 EXCEPTION
9797 }
98+
99+ /**
100+ * Enumerated type defining the possible values of {@link #getBigSegmentsStatus()}.
101+ */
102+ public static enum BigSegmentsStatus {
103+ /**
104+ * Indicates that the Big Segment query involved in the flag evaluation was successful, and that
105+ * the segment state is considered up to date.
106+ */
107+ HEALTHY ,
108+ /**
109+ * Indicates that the Big Segment query involved in the flag evaluation was successful, but that
110+ * the segment state may not be up to date.
111+ */
112+ STALE ,
113+ /**
114+ * Indicates that Big Segments could not be queried for the flag evaluation because the SDK
115+ * configuration did not include a Big Segment store.
116+ */
117+ NOT_CONFIGURED ,
118+ /**
119+ * Indicates that the Big Segment query involved in the flag evaluation failed, for instance due
120+ * to a database error.
121+ */
122+ STORE_ERROR
123+ }
98124
99125 // static instances to avoid repeatedly allocating reasons for the same parameters
100126 private static final EvaluationReason OFF_INSTANCE = new EvaluationReason (Kind .OFF );
@@ -115,28 +141,30 @@ public static enum ErrorKind {
115141 private final boolean inExperiment ;
116142 private final ErrorKind errorKind ;
117143 private final Exception exception ;
144+ private final BigSegmentsStatus bigSegmentsStatus ;
118145
119146 private EvaluationReason (Kind kind , int ruleIndex , String ruleId , String prerequisiteKey , boolean inExperiment ,
120- ErrorKind errorKind , Exception exception ) {
147+ ErrorKind errorKind , Exception exception , BigSegmentsStatus bigSegmentsStatus ) {
121148 this .kind = kind ;
122149 this .ruleIndex = ruleIndex ;
123150 this .ruleId = ruleId ;
124151 this .prerequisiteKey = prerequisiteKey ;
125152 this .inExperiment = inExperiment ;
126153 this .errorKind = errorKind ;
127154 this .exception = exception ;
155+ this .bigSegmentsStatus = bigSegmentsStatus ;
128156 }
129157
130158 private EvaluationReason (Kind kind ) {
131- this (kind , -1 , null , null , NOT_IN_EXPERIMENT , null , null );
159+ this (kind , -1 , null , null , NOT_IN_EXPERIMENT , null , null , null );
132160 }
133161
134162 private EvaluationReason (Kind kind , boolean inExperiment ) {
135- this (kind , -1 , null , null , inExperiment , null , null );
163+ this (kind , -1 , null , null , inExperiment , null , null , null );
136164 }
137165
138166 private EvaluationReason (ErrorKind errorKind , Exception exception ) {
139- this (Kind .ERROR , -1 , null , null , NOT_IN_EXPERIMENT , errorKind , exception );
167+ this (Kind .ERROR , -1 , null , null , NOT_IN_EXPERIMENT , errorKind , exception , null );
140168 }
141169
142170 /**
@@ -215,7 +243,33 @@ public ErrorKind getErrorKind() {
215243 public Exception getException () {
216244 return exception ;
217245 }
218-
246+
247+ /**
248+ * Describes the validity of Big Segment information, if and only if the flag evaluation required
249+ * querying at least one Big Segment. Otherwise it returns {@code null}.
250+ * <p>
251+ * Big Segments are a specific type of user segments. For more information, read the
252+ * <a href="https://docs.launchdarkly.com/home/users/big-segments">LaunchDarkly documentation
253+ * </a>.
254+ *
255+ * @return the {@link BigSegmentsStatus} from the evaluation or {@code null}
256+ */
257+ public BigSegmentsStatus getBigSegmentsStatus () {
258+ return bigSegmentsStatus ;
259+ }
260+
261+ /**
262+ * Returns a copy of this {@link EvaluationReason} with a specific {@link BigSegmentsStatus}
263+ * value.
264+ *
265+ * @param bigSegmentsStatus the new property value
266+ * @return a new reason object
267+ */
268+ public EvaluationReason withBigSegmentsStatus (BigSegmentsStatus bigSegmentsStatus ) {
269+ return new EvaluationReason (kind , ruleIndex , ruleId , prerequisiteKey , inExperiment , errorKind ,
270+ exception , bigSegmentsStatus );
271+ }
272+
219273 /**
220274 * Returns a simple string representation of the reason.
221275 * <p>
@@ -250,14 +304,16 @@ public boolean equals(Object other) {
250304 Objects .equals (prerequisiteKey , o .prerequisiteKey ) &&
251305 inExperiment == o .inExperiment &&
252306 Objects .equals (errorKind , o .errorKind ) &&
253- Objects .equals (exception , o .exception );
307+ Objects .equals (exception , o .exception ) &&
308+ Objects .equals (bigSegmentsStatus , o .bigSegmentsStatus );
254309 }
255310 return false ;
256311 }
257312
258313 @ Override
259314 public int hashCode () {
260- return Objects .hash (kind , ruleIndex , ruleId , prerequisiteKey , inExperiment , errorKind , exception );
315+ return Objects .hash (kind , ruleIndex , ruleId , prerequisiteKey , inExperiment , errorKind ,
316+ exception , bigSegmentsStatus );
261317 }
262318
263319 /**
@@ -321,7 +377,7 @@ public static EvaluationReason ruleMatch(int ruleIndex, String ruleId) {
321377 * @return a reason object
322378 */
323379 public static EvaluationReason ruleMatch (int ruleIndex , String ruleId , boolean inExperiment ) {
324- return new EvaluationReason (Kind .RULE_MATCH , ruleIndex , ruleId , null , inExperiment , null , null );
380+ return new EvaluationReason (Kind .RULE_MATCH , ruleIndex , ruleId , null , inExperiment , null , null , null );
325381 }
326382
327383 /**
@@ -331,7 +387,7 @@ public static EvaluationReason ruleMatch(int ruleIndex, String ruleId, boolean i
331387 * @return a reason object
332388 */
333389 public static EvaluationReason prerequisiteFailed (String prerequisiteKey ) {
334- return new EvaluationReason (Kind .PREREQUISITE_FAILED , -1 , null , prerequisiteKey , NOT_IN_EXPERIMENT , null , null );
390+ return new EvaluationReason (Kind .PREREQUISITE_FAILED , -1 , null , prerequisiteKey , NOT_IN_EXPERIMENT , null , null , null );
335391 }
336392
337393 /**
0 commit comments