[main] Allow logic compounds between ThrowingBooleanSupplier and ThrowingPredicate
This commit is contained in:
parent
c2681c29c5
commit
10d62e5a61
@ -8,6 +8,44 @@ import java.util.function.Predicate;
|
|||||||
public interface ThrowingBooleanSupplier<TEx extends Throwable> {
|
public interface ThrowingBooleanSupplier<TEx extends Throwable> {
|
||||||
boolean get() throws TEx;
|
boolean get() throws TEx;
|
||||||
|
|
||||||
|
default <T> ThrowingPredicate<T, TEx> and(ThrowingPredicate<? super T, ? extends TEx> other) {
|
||||||
|
Objects.requireNonNull(other);
|
||||||
|
return (t) -> this.get() && other.test(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
default ThrowingBooleanSupplier<TEx> and(ThrowingBooleanSupplier<? extends TEx> other) {
|
||||||
|
Objects.requireNonNull(other);
|
||||||
|
return () -> this.get() && other.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
default <T> ThrowingPredicate<T, TEx> or(ThrowingPredicate<? super T, ? extends TEx> other) {
|
||||||
|
Objects.requireNonNull(other);
|
||||||
|
return (t) -> this.get() || other.test(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
default ThrowingBooleanSupplier<TEx> or(ThrowingBooleanSupplier<? extends TEx> other) {
|
||||||
|
Objects.requireNonNull(other);
|
||||||
|
return () -> this.get() || other.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
default <T> ThrowingPredicate<T, TEx> xor(ThrowingPredicate<? super T, ? extends TEx> other) {
|
||||||
|
Objects.requireNonNull(other);
|
||||||
|
return (t) -> this.get() ^ other.test(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
default ThrowingBooleanSupplier<TEx> xor(ThrowingBooleanSupplier<? extends TEx> other) {
|
||||||
|
Objects.requireNonNull(other);
|
||||||
|
return () -> this.get() ^ other.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
default ThrowingBooleanSupplier<TEx> negate() {
|
||||||
|
return () -> !this.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
static <TEx extends Throwable> ThrowingBooleanSupplier<TEx> not(ThrowingBooleanSupplier<TEx> target) {
|
||||||
|
return Objects.requireNonNull(target).negate();
|
||||||
|
}
|
||||||
|
|
||||||
default BooleanSupplier addHandler(Predicate<Throwable> handler) {
|
default BooleanSupplier addHandler(Predicate<Throwable> handler) {
|
||||||
Objects.requireNonNull(handler);
|
Objects.requireNonNull(handler);
|
||||||
return () -> {
|
return () -> {
|
||||||
|
@ -22,8 +22,9 @@ public interface ThrowingPredicate<T, TEx extends Throwable> {
|
|||||||
return (t) -> this.test(t) && other.test(t);
|
return (t) -> this.test(t) && other.test(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
default ThrowingPredicate<T, TEx> negate() {
|
default ThrowingPredicate<T, TEx> and(ThrowingBooleanSupplier<? extends TEx> other) {
|
||||||
return (t) -> !this.test(t);
|
Objects.requireNonNull(other);
|
||||||
|
return (t) -> this.test(t) && other.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
default ThrowingPredicate<T, TEx> or(ThrowingPredicate<? super T, ? extends TEx> other) {
|
default ThrowingPredicate<T, TEx> or(ThrowingPredicate<? super T, ? extends TEx> other) {
|
||||||
@ -31,13 +32,31 @@ public interface ThrowingPredicate<T, TEx extends Throwable> {
|
|||||||
return (t) -> this.test(t) || other.test(t);
|
return (t) -> this.test(t) || other.test(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default ThrowingPredicate<T, TEx> or(ThrowingBooleanSupplier<? extends TEx> other) {
|
||||||
|
Objects.requireNonNull(other);
|
||||||
|
return (t) -> this.test(t) || other.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
default ThrowingPredicate<T, TEx> xor(ThrowingPredicate<? super T, ? extends TEx> other) {
|
||||||
|
Objects.requireNonNull(other);
|
||||||
|
return (t) -> this.test(t) ^ other.test(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
default ThrowingPredicate<T, TEx> xor(ThrowingBooleanSupplier<? extends TEx> other) {
|
||||||
|
Objects.requireNonNull(other);
|
||||||
|
return (t) -> this.test(t) ^ other.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
default ThrowingPredicate<T, TEx> negate() {
|
||||||
|
return (t) -> !this.test(t);
|
||||||
|
}
|
||||||
|
|
||||||
static <T> ThrowingPredicate<T, Throwable> isEqual(Object targetRef) {
|
static <T> ThrowingPredicate<T, Throwable> isEqual(Object targetRef) {
|
||||||
return null == targetRef ? Objects::isNull : targetRef::equals;
|
return null == targetRef ? Objects::isNull : targetRef::equals;
|
||||||
}
|
}
|
||||||
|
|
||||||
static <T, TEx extends Throwable> ThrowingPredicate<T, TEx> not(ThrowingPredicate<T, TEx> target) {
|
static <T, TEx extends Throwable> ThrowingPredicate<T, TEx> not(ThrowingPredicate<T, TEx> target) {
|
||||||
Objects.requireNonNull(target);
|
return Objects.requireNonNull(target).negate();
|
||||||
return target.negate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default Predicate<T> addHandler(Predicate<Throwable> handler) {
|
default Predicate<T> addHandler(Predicate<Throwable> handler) {
|
||||||
|
Loading…
Reference in New Issue
Block a user