This repository has been archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a77e817
commit 5f92f7f
Showing
32 changed files
with
1,998 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
version=4.2.2 | ||
version=4.3.0 | ||
ossrhUsername= | ||
ossrhPassword= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/main/java/com/launchdarkly/client/EvaluationDetail.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.launchdarkly.client; | ||
|
||
import com.google.common.base.Objects; | ||
|
||
/** | ||
* An object returned by the "variation detail" methods such as {@link LDClientInterface#boolVariationDetail(String, LDUser, boolean)}, | ||
* combining the result of a flag evaluation with an explanation of how it was calculated. | ||
* @since 4.3.0 | ||
*/ | ||
public class EvaluationDetail<T> { | ||
|
||
private final EvaluationReason reason; | ||
private final Integer variationIndex; | ||
private final T value; | ||
|
||
public EvaluationDetail(EvaluationReason reason, Integer variationIndex, T value) { | ||
this.reason = reason; | ||
this.variationIndex = variationIndex; | ||
this.value = value; | ||
} | ||
|
||
static <T> EvaluationDetail<T> error(EvaluationReason.ErrorKind errorKind, T defaultValue) { | ||
return new EvaluationDetail<>(EvaluationReason.error(errorKind), null, defaultValue); | ||
} | ||
|
||
/** | ||
* An object describing the main factor that influenced the flag evaluation value. | ||
* @return an {@link EvaluationReason} | ||
*/ | ||
public EvaluationReason getReason() { | ||
return reason; | ||
} | ||
|
||
/** | ||
* The index of the returned value within the flag's list of variations, e.g. 0 for the first variation - | ||
* or {@code null} if the default value was returned. | ||
* @return the variation index or null | ||
*/ | ||
public Integer getVariationIndex() { | ||
return variationIndex; | ||
} | ||
|
||
/** | ||
* The result of the flag evaluation. This will be either one of the flag's variations or the default | ||
* value that was passed to the {@code variation} method. | ||
* @return the flag value | ||
*/ | ||
public T getValue() { | ||
return value; | ||
} | ||
|
||
/** | ||
* Returns true if the flag evaluation returned the default value, rather than one of the flag's | ||
* variations. | ||
* @return true if this is the default value | ||
*/ | ||
public boolean isDefaultValue() { | ||
return variationIndex == null; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other instanceof EvaluationDetail) { | ||
@SuppressWarnings("unchecked") | ||
EvaluationDetail<T> o = (EvaluationDetail<T>)other; | ||
return Objects.equal(reason, o.reason) && Objects.equal(variationIndex, o.variationIndex) && Objects.equal(value, o.value); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(reason, variationIndex, value); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "{" + reason + "," + variationIndex + "," + value + "}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.