![JAR search and dependency download from the Maven repository](/logo.png)
io.getunleash.strategy.ConstraintUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unleash-client-java Show documentation
Show all versions of unleash-client-java Show documentation
A client library for Unleash
package io.getunleash.strategy;
import io.getunleash.Constraint;
import io.getunleash.Operator;
import io.getunleash.UnleashContext;
import io.getunleash.lang.Nullable;
import java.util.List;
import java.util.Optional;
public class ConstraintUtil {
public static boolean validate(@Nullable List constraints, UnleashContext context) {
if (constraints != null && constraints.size() > 0) {
return constraints.stream().allMatch(c -> validateConstraint(c, context));
} else {
return true;
}
}
private static boolean validateConstraint(Constraint constraint, UnleashContext context) {
Optional contextValue = context.getByName(constraint.getContextName());
boolean isIn =
contextValue.isPresent()
&& constraint.getValues().contains(contextValue.get().trim());
return (constraint.getOperator() == Operator.IN) == isIn;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy