diff --git a/libjf-base/src/main/java/io/gitlab/jfronny/libjf/generic/ThrowingBooleanSupplier.java b/libjf-base/src/main/java/io/gitlab/jfronny/libjf/generic/ThrowingBooleanSupplier.java index 0b9dc45..2547f2c 100644 --- a/libjf-base/src/main/java/io/gitlab/jfronny/libjf/generic/ThrowingBooleanSupplier.java +++ b/libjf-base/src/main/java/io/gitlab/jfronny/libjf/generic/ThrowingBooleanSupplier.java @@ -8,6 +8,44 @@ import java.util.function.Predicate; public interface ThrowingBooleanSupplier { boolean get() throws TEx; + default ThrowingPredicate and(ThrowingPredicate other) { + Objects.requireNonNull(other); + return (t) -> this.get() && other.test(t); + } + + default ThrowingBooleanSupplier and(ThrowingBooleanSupplier other) { + Objects.requireNonNull(other); + return () -> this.get() && other.get(); + } + + default ThrowingPredicate or(ThrowingPredicate other) { + Objects.requireNonNull(other); + return (t) -> this.get() || other.test(t); + } + + default ThrowingBooleanSupplier or(ThrowingBooleanSupplier other) { + Objects.requireNonNull(other); + return () -> this.get() || other.get(); + } + + default ThrowingPredicate xor(ThrowingPredicate other) { + Objects.requireNonNull(other); + return (t) -> this.get() ^ other.test(t); + } + + default ThrowingBooleanSupplier xor(ThrowingBooleanSupplier other) { + Objects.requireNonNull(other); + return () -> this.get() ^ other.get(); + } + + default ThrowingBooleanSupplier negate() { + return () -> !this.get(); + } + + static ThrowingBooleanSupplier not(ThrowingBooleanSupplier target) { + return Objects.requireNonNull(target).negate(); + } + default BooleanSupplier addHandler(Predicate handler) { Objects.requireNonNull(handler); return () -> { diff --git a/libjf-base/src/main/java/io/gitlab/jfronny/libjf/generic/ThrowingPredicate.java b/libjf-base/src/main/java/io/gitlab/jfronny/libjf/generic/ThrowingPredicate.java index f79ad45..3d154b9 100644 --- a/libjf-base/src/main/java/io/gitlab/jfronny/libjf/generic/ThrowingPredicate.java +++ b/libjf-base/src/main/java/io/gitlab/jfronny/libjf/generic/ThrowingPredicate.java @@ -22,8 +22,9 @@ public interface ThrowingPredicate { return (t) -> this.test(t) && other.test(t); } - default ThrowingPredicate negate() { - return (t) -> !this.test(t); + default ThrowingPredicate and(ThrowingBooleanSupplier other) { + Objects.requireNonNull(other); + return (t) -> this.test(t) && other.get(); } default ThrowingPredicate or(ThrowingPredicate other) { @@ -31,13 +32,31 @@ public interface ThrowingPredicate { return (t) -> this.test(t) || other.test(t); } + default ThrowingPredicate or(ThrowingBooleanSupplier other) { + Objects.requireNonNull(other); + return (t) -> this.test(t) || other.get(); + } + + default ThrowingPredicate xor(ThrowingPredicate other) { + Objects.requireNonNull(other); + return (t) -> this.test(t) ^ other.test(t); + } + + default ThrowingPredicate xor(ThrowingBooleanSupplier other) { + Objects.requireNonNull(other); + return (t) -> this.test(t) ^ other.get(); + } + + default ThrowingPredicate negate() { + return (t) -> !this.test(t); + } + static ThrowingPredicate isEqual(Object targetRef) { return null == targetRef ? Objects::isNull : targetRef::equals; } static ThrowingPredicate not(ThrowingPredicate target) { - Objects.requireNonNull(target); - return target.negate(); + return Objects.requireNonNull(target).negate(); } default Predicate addHandler(Predicate handler) {