com.launchdarkly.client.SegmentRule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of launchdarkly-client Show documentation
Show all versions of launchdarkly-client Show documentation
Official LaunchDarkly SDK for Java
package com.launchdarkly.client;
import java.util.List;
public class SegmentRule {
private final List clauses;
private final Integer weight;
private final String bucketBy;
public SegmentRule(List clauses, Integer weight, String bucketBy) {
this.clauses = clauses;
this.weight = weight;
this.bucketBy = bucketBy;
}
public boolean matchUser(LDUser user, String segmentKey, String salt) {
for (Clause c: clauses) {
if (!c.matchesUserNoSegments(user)) {
return false;
}
}
// If the Weight is absent, this rule matches
if (weight == null) {
return true;
}
// All of the clauses are met. See if the user buckets in
String by = (bucketBy == null) ? "key" : bucketBy;
double bucket = VariationOrRollout.bucketUser(user, segmentKey, by, salt);
double weight = (double)this.weight / 100000.0;
return bucket < weight;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy