
org.zalando.riptide.faults.Rule Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of riptide-faults Show documentation
Show all versions of riptide-faults Show documentation
Client side response routing
The newest version!
package org.zalando.riptide.faults;
import lombok.AllArgsConstructor;
import lombok.With;
import org.apiguardian.api.API;
import java.util.function.Predicate;
import static lombok.AccessLevel.PRIVATE;
import static org.apiguardian.api.API.Status.EXPERIMENTAL;
import static org.zalando.riptide.faults.Predicates.alwaysFalse;
import static org.zalando.riptide.faults.Predicates.alwaysTrue;
@API(status = EXPERIMENTAL)
@AllArgsConstructor(staticName = "of")
public final class Rule implements Predicate {
@With(PRIVATE)
private final Predicate include;
@With(PRIVATE)
private final Predicate exclude;
@Override
public boolean test(final T input) {
return include.test(input) && !exclude.test(input);
}
public static Rule of() {
return of(alwaysTrue());
}
public static Rule of(final Predicate predicate) {
return of(predicate, alwaysFalse());
}
public Rule include(final Predicate predicate) {
return withInclude(include.and(predicate));
}
public Rule exclude(final Predicate predicate) {
return withExclude(exclude.or(predicate));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy