diff --git a/src/main/java/org/apache/commons/lang3/Functions.java b/src/main/java/org/apache/commons/lang3/Functions.java index 7186caa52..ff4134fc1 100644 --- a/src/main/java/org/apache/commons/lang3/Functions.java +++ b/src/main/java/org/apache/commons/lang3/Functions.java @@ -32,6 +32,7 @@ import java.util.function.Supplier; import java.util.stream.Stream; import org.apache.commons.lang3.Streams.FailableStream; +import org.apache.commons.lang3.function.FailableBooleanSupplier; /** * This class provides utility functions, and classes for working with the {@code java.util.function} package, or more @@ -93,7 +94,7 @@ public class Functions { */ void accept(O1 object1, O2 object2) throws T; } - + /** * A functional interface like {@link BiFunction} that declares a {@code Throwable}. * @@ -477,6 +478,21 @@ public class Functions { } } + /** + * Invokes a boolean supplier, and returns the result. + * + * @param supplier The boolean supplier to invoke. + * @param The type of checked exception, which the supplier can throw. + * @return The boolean, which has been created by the supplier + */ + private static boolean getAsBoolean(final FailableBooleanSupplier supplier) { + try { + return supplier.getAsBoolean(); + } catch (final Throwable t) { + throw rethrow(t); + } + } + /** *

* Rethrows a {@link Throwable} as an unchecked exception. If the argument is already unchecked, namely a @@ -574,7 +590,7 @@ public class Functions { */ public static boolean test(final FailableBiPredicate predicate, final O1 object1, final O2 object2) { - return get(() -> predicate.test(object1, object2)); + return getAsBoolean(() -> predicate.test(object1, object2)); } /** @@ -587,7 +603,7 @@ public class Functions { * @return the boolean value returned by the predicate */ public static boolean test(final FailablePredicate predicate, final O object) { - return get(() -> predicate.test(object)); + return getAsBoolean(() -> predicate.test(object)); } /**