Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/main/java/cloud/eppo/BanditEvaluationResult.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package cloud.eppo;

import java.util.Objects;

import cloud.eppo.api.DiscriminableAttributes;

public class BanditEvaluationResult {
Expand Down Expand Up @@ -35,6 +37,40 @@ public BanditEvaluationResult(
this.optimalityGap = optimalityGap;
}

@Override
public String toString() {
return "BanditEvaluationResult{" +
"flagKey='" + flagKey + '\'' +
", subjectKey='" + subjectKey + '\'' +
", subjectAttributes=" + subjectAttributes +
", actionKey='" + actionKey + '\'' +
", actionAttributes=" + actionAttributes +
", actionScore=" + actionScore +
", actionWeight=" + actionWeight +
", gamma=" + gamma +
", optimalityGap=" + optimalityGap +
'}';
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
BanditEvaluationResult that = (BanditEvaluationResult) o;
return Double.compare(actionScore, that.actionScore) == 0
&& Double.compare(actionWeight, that.actionWeight) == 0
&& Double.compare(gamma, that.gamma) == 0
&& Double.compare(optimalityGap, that.optimalityGap) == 0
&& Objects.equals(flagKey, that.flagKey)
&& Objects.equals(subjectKey, that.subjectKey)
&& Objects.equals(subjectAttributes, that.subjectAttributes)
&& Objects.equals(actionKey, that.actionKey) && Objects.equals(actionAttributes, that.actionAttributes);
}

@Override
public int hashCode() {
return Objects.hash(flagKey, subjectKey, subjectAttributes, actionKey, actionAttributes, actionScore, actionWeight, gamma, optimalityGap);
}

public String getFlagKey() {
return flagKey;
}
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/cloud/eppo/FlagEvaluationResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import cloud.eppo.api.Attributes;
import cloud.eppo.ufc.dto.Variation;
import java.util.Map;
import java.util.Objects;

public class FlagEvaluationResult {

Expand Down Expand Up @@ -31,6 +32,37 @@ public FlagEvaluationResult(
this.doLog = doLog;
}

@Override
public String toString() {
return "FlagEvaluationResult{" +
"flagKey='" + flagKey + '\'' +
", subjectKey='" + subjectKey + '\'' +
", subjectAttributes=" + subjectAttributes +
", allocationKey='" + allocationKey + '\'' +
", variation=" + variation +
", extraLogging=" + extraLogging +
", doLog=" + doLog +
'}';
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
FlagEvaluationResult that = (FlagEvaluationResult) o;
return doLog == that.doLog
&& Objects.equals(flagKey, that.flagKey)
&& Objects.equals(subjectKey, that.subjectKey)
&& Objects.equals(subjectAttributes, that.subjectAttributes)
&& Objects.equals(allocationKey, that.allocationKey)
&& Objects.equals(variation, that.variation)
&& Objects.equals(extraLogging, that.extraLogging);
}

@Override
public int hashCode() {
return Objects.hash(flagKey, subjectKey, subjectAttributes, allocationKey, variation, extraLogging, doLog);
}

public String getFlagKey() {
return flagKey;
}
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/cloud/eppo/SDKKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -24,6 +26,27 @@ public SDKKey(String sdkToken) {
this.decodedParams = decodeToken(sdkToken);
}

@Override
public String toString() {
return "SDKKey{" +
"sdkTokenString='" + sdkTokenString + '\'' +
", decodedParams=" + decodedParams +
'}';
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
SDKKey sdkKey = (SDKKey) o;
return Objects.equals(sdkTokenString, sdkKey.sdkTokenString) &&
Objects.equals(decodedParams, sdkKey.decodedParams);
}

@Override
public int hashCode() {
return Objects.hash(sdkTokenString, decodedParams);
}

private Map<String, String> decodeToken(String token) {
try {
String[] parts = token.split("\\.");
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/cloud/eppo/api/BanditResult.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package cloud.eppo.api;

import java.util.Objects;

public class BanditResult {
private final String variation;
private final String action;
Expand All @@ -9,6 +11,27 @@ public BanditResult(String variation, String action) {
this.action = action;
}

@Override
public String toString() {
return "BanditResult{" +
"variation='" + variation + '\'' +
", action='" + action + '\'' +
'}';
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
BanditResult that = (BanditResult) o;
return Objects.equals(variation, that.variation)
&& Objects.equals(action, that.action);
}

@Override
public int hashCode() {
return Objects.hash(variation, action);
}

public String getVariation() {
return variation;
}
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/cloud/eppo/api/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -107,6 +109,35 @@ public static Configuration emptyConfig() {
null);
}

@Override
public String toString() {
return "Configuration{" +
"banditReferences=" + banditReferences +
", flags=" + flags +
", bandits=" + bandits +
", isConfigObfuscated=" + isConfigObfuscated +
", flagConfigJson=" + Arrays.toString(flagConfigJson) +
", banditParamsJson=" + Arrays.toString(banditParamsJson) +
'}';
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
Configuration that = (Configuration) o;
return isConfigObfuscated == that.isConfigObfuscated
&& Objects.equals(banditReferences, that.banditReferences)
&& Objects.equals(flags, that.flags)
&& Objects.equals(bandits, that.bandits)
&& Objects.deepEquals(flagConfigJson, that.flagConfigJson)
&& Objects.deepEquals(banditParamsJson, that.banditParamsJson);
}

@Override
public int hashCode() {
return Objects.hash(banditReferences, flags, bandits, isConfigObfuscated, Arrays.hashCode(flagConfigJson), Arrays.hashCode(banditParamsJson));
}

public FlagConfig getFlag(String flagKey) {
String flagKeyForLookup = flagKey;
if (isConfigObfuscated()) {
Expand Down
34 changes: 21 additions & 13 deletions src/main/java/cloud/eppo/cache/AssignmentCacheEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,27 @@ public static AssignmentCacheEntry fromBanditAssignment(BanditAssignment assignm
new BanditCacheValue(assignment.getBandit(), assignment.getAction()));
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
AssignmentCacheEntry that = (AssignmentCacheEntry) o;
return Objects.equals(key, that.key)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a behavior change. Does that matter?

Old:

    return Objects.equals(key, that.key)
        && Objects.equals(value.getValueIdentifier(), that.value.getValueIdentifier());

New:

    return Objects.equals(key, that.key)
     && Objects.equals(value, that.value);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this in a separate medium, and we want to revert this change.

&& Objects.equals(value, that.value);
}

@Override
public int hashCode() {
return Objects.hash(key, value);
}

@Override
public String toString() {
return "AssignmentCacheEntry{" +
"key=" + key +
", value=" + value +
'}';
}

@NotNull public AssignmentCacheKey getKey() {
return key;
}
Expand All @@ -43,17 +64,4 @@ public static AssignmentCacheEntry fromBanditAssignment(BanditAssignment assignm
return value;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not still a useful check for equivalency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is. I just moved the method to be consistent with the where you had the methods in other bean classes.

if (o == null || getClass() != o.getClass()) return false;
AssignmentCacheEntry that = (AssignmentCacheEntry) o;
return Objects.equals(key, that.key)
&& Objects.equals(value.getValueIdentifier(), that.value.getValueIdentifier());
}

@Override
public int hashCode() {
return Objects.hash(key, value);
}
}
21 changes: 11 additions & 10 deletions src/main/java/cloud/eppo/cache/AssignmentCacheKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,30 @@ public AssignmentCacheKey(String subjectKey, String flagKey) {
this.flagKey = flagKey;
}

public String getSubjectKey() {
return subjectKey;
}

public String getFlagKey() {
return flagKey;
}

@Override
public String toString() {
return subjectKey + ";" + flagKey;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AssignmentCacheKey that = (AssignmentCacheKey) o;
return Objects.equals(toString(), that.toString());
return Objects.equals(subjectKey, that.subjectKey)
&& Objects.equals(flagKey, that.flagKey);
}

@Override
public int hashCode() {
return Objects.hash(subjectKey, flagKey);
}

public String getSubjectKey() {
return subjectKey;
}

public String getFlagKey() {
return flagKey;
}

}
15 changes: 15 additions & 0 deletions src/main/java/cloud/eppo/model/ShardRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Objects;

/** Shard Range Class */
public class ShardRange {
private final int start;
Expand All @@ -14,6 +16,19 @@ public ShardRange(@JsonProperty("start") int start, @JsonProperty("end") int end
this.end = end;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
ShardRange that = (ShardRange) o;
return start == that.start &&
end == that.end;
}

@Override
public int hashCode() {
return Objects.hash(start, end);
}

@Override
public String toString() {
return "[start: " + start + "| end: " + end + "]";
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/cloud/eppo/ufc/dto/Allocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Set;

public class Allocation {
Expand All @@ -27,6 +28,35 @@ public Allocation(
this.doLog = doLog;
}

@Override
public String toString() {
return "Allocation{" +
"key='" + key + '\'' +
", rules=" + rules +
", startAt=" + startAt +
", endAt=" + endAt +
", splits=" + splits +
", doLog=" + doLog +
'}';
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
Allocation that = (Allocation) o;
return doLog == that.doLog
&& Objects.equals(key, that.key)
&& Objects.equals(rules, that.rules)
&& Objects.equals(startAt, that.startAt)
&& Objects.equals(endAt, that.endAt)
&& Objects.equals(splits, that.splits);
}

@Override
public int hashCode() {
return Objects.hash(key, rules, startAt, endAt, splits, doLog);
}

public String getKey() {
return key;
}
Expand Down
Loading
Loading