From 3b47454999c15a645f640680ee4cd7b5250d6322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Va=C5=BEan?= Date: Wed, 19 Jul 2023 18:14:52 +0000 Subject: [PATCH] Use spaces instead of tabs --- scripts/generate.py | 5 +- .../noexception/CheckedExceptionHandler.java | 3814 ++++++++--------- .../noexception/ExceptionFilter.java | 3506 +++++++-------- .../noexception/ExceptionHandler.java | 3710 ++++++++-------- .../optional/DefaultBiFunction.java | 20 +- .../optional/DefaultBiPredicate.java | 20 +- .../optional/DefaultBinaryOperator.java | 20 +- .../optional/DefaultBooleanSupplier.java | 20 +- .../optional/DefaultComparator.java | 20 +- .../optional/DefaultDoubleBinaryOperator.java | 20 +- .../optional/DefaultDoubleFunction.java | 20 +- .../optional/DefaultDoublePredicate.java | 20 +- .../optional/DefaultDoubleSupplier.java | 20 +- .../optional/DefaultDoubleToIntFunction.java | 20 +- .../optional/DefaultDoubleToLongFunction.java | 20 +- .../optional/DefaultDoubleUnaryOperator.java | 20 +- .../noexception/optional/DefaultFunction.java | 20 +- .../optional/DefaultIntBinaryOperator.java | 20 +- .../optional/DefaultIntFunction.java | 20 +- .../optional/DefaultIntPredicate.java | 20 +- .../optional/DefaultIntSupplier.java | 20 +- .../optional/DefaultIntToDoubleFunction.java | 20 +- .../optional/DefaultIntToLongFunction.java | 20 +- .../optional/DefaultIntUnaryOperator.java | 20 +- .../optional/DefaultLongBinaryOperator.java | 20 +- .../optional/DefaultLongFunction.java | 20 +- .../optional/DefaultLongPredicate.java | 20 +- .../optional/DefaultLongSupplier.java | 20 +- .../optional/DefaultLongToDoubleFunction.java | 20 +- .../optional/DefaultLongToIntFunction.java | 20 +- .../optional/DefaultLongUnaryOperator.java | 20 +- .../optional/DefaultPredicate.java | 20 +- .../noexception/optional/DefaultSupplier.java | 20 +- .../optional/DefaultToDoubleBiFunction.java | 20 +- .../optional/DefaultToDoubleFunction.java | 20 +- .../optional/DefaultToIntBiFunction.java | 20 +- .../optional/DefaultToIntFunction.java | 20 +- .../optional/DefaultToLongBiFunction.java | 20 +- .../optional/DefaultToLongFunction.java | 20 +- .../optional/DefaultUnaryOperator.java | 20 +- .../optional/FallbackBiFunction.java | 20 +- .../optional/FallbackBiPredicate.java | 20 +- .../optional/FallbackBinaryOperator.java | 20 +- .../optional/FallbackBooleanSupplier.java | 20 +- .../optional/FallbackComparator.java | 20 +- .../FallbackDoubleBinaryOperator.java | 20 +- .../optional/FallbackDoubleFunction.java | 20 +- .../optional/FallbackDoublePredicate.java | 20 +- .../optional/FallbackDoubleSupplier.java | 20 +- .../optional/FallbackDoubleToIntFunction.java | 20 +- .../FallbackDoubleToLongFunction.java | 20 +- .../optional/FallbackDoubleUnaryOperator.java | 20 +- .../optional/FallbackFunction.java | 20 +- .../optional/FallbackIntBinaryOperator.java | 20 +- .../optional/FallbackIntFunction.java | 20 +- .../optional/FallbackIntPredicate.java | 20 +- .../optional/FallbackIntSupplier.java | 20 +- .../optional/FallbackIntToDoubleFunction.java | 20 +- .../optional/FallbackIntToLongFunction.java | 20 +- .../optional/FallbackIntUnaryOperator.java | 20 +- .../optional/FallbackLongBinaryOperator.java | 20 +- .../optional/FallbackLongFunction.java | 20 +- .../optional/FallbackLongPredicate.java | 20 +- .../optional/FallbackLongSupplier.java | 20 +- .../FallbackLongToDoubleFunction.java | 20 +- .../optional/FallbackLongToIntFunction.java | 20 +- .../optional/FallbackLongUnaryOperator.java | 20 +- .../optional/FallbackPredicate.java | 20 +- .../optional/FallbackSupplier.java | 20 +- .../optional/FallbackToDoubleBiFunction.java | 20 +- .../optional/FallbackToDoubleFunction.java | 20 +- .../optional/FallbackToIntBiFunction.java | 20 +- .../optional/FallbackToIntFunction.java | 20 +- .../optional/FallbackToLongBiFunction.java | 20 +- .../optional/FallbackToLongFunction.java | 20 +- .../optional/FallbackUnaryOperator.java | 20 +- .../optional/OptionalBiFunction.java | 90 +- .../optional/OptionalBiPredicate.java | 88 +- .../optional/OptionalBinaryOperator.java | 90 +- .../optional/OptionalBooleanSupplier.java | 82 +- .../optional/OptionalComparator.java | 88 +- .../OptionalDoubleBinaryOperator.java | 88 +- .../optional/OptionalDoubleFunction.java | 86 +- .../optional/OptionalDoublePredicate.java | 84 +- .../optional/OptionalDoubleSupplier.java | 82 +- .../optional/OptionalDoubleToIntFunction.java | 86 +- .../OptionalDoubleToLongFunction.java | 86 +- .../optional/OptionalDoubleUnaryOperator.java | 86 +- .../optional/OptionalFunction.java | 86 +- .../optional/OptionalIntBinaryOperator.java | 88 +- .../optional/OptionalIntFunction.java | 86 +- .../optional/OptionalIntPredicate.java | 84 +- .../optional/OptionalIntSupplier.java | 82 +- .../optional/OptionalIntToDoubleFunction.java | 86 +- .../optional/OptionalIntToLongFunction.java | 86 +- .../optional/OptionalIntUnaryOperator.java | 86 +- .../optional/OptionalLongBinaryOperator.java | 88 +- .../optional/OptionalLongFunction.java | 86 +- .../optional/OptionalLongPredicate.java | 84 +- .../optional/OptionalLongSupplier.java | 82 +- .../OptionalLongToDoubleFunction.java | 86 +- .../optional/OptionalLongToIntFunction.java | 86 +- .../optional/OptionalLongUnaryOperator.java | 86 +- .../optional/OptionalPredicate.java | 84 +- .../optional/OptionalSupplier.java | 82 +- .../optional/OptionalToDoubleBiFunction.java | 90 +- .../optional/OptionalToDoubleFunction.java | 86 +- .../optional/OptionalToIntBiFunction.java | 90 +- .../optional/OptionalToIntFunction.java | 86 +- .../optional/OptionalToLongBiFunction.java | 90 +- .../optional/OptionalToLongFunction.java | 86 +- .../optional/OptionalUnaryOperator.java | 86 +- .../throwing/ThrowingBiConsumer.java | 26 +- .../throwing/ThrowingBiFunction.java | 28 +- .../throwing/ThrowingBiPredicate.java | 28 +- .../throwing/ThrowingBooleanSupplier.java | 20 +- .../throwing/ThrowingComparator.java | 28 +- .../throwing/ThrowingConsumer.java | 22 +- .../ThrowingDoubleBinaryOperator.java | 28 +- .../throwing/ThrowingDoubleConsumer.java | 22 +- .../throwing/ThrowingDoubleFunction.java | 24 +- .../throwing/ThrowingDoublePredicate.java | 24 +- .../throwing/ThrowingDoubleSupplier.java | 20 +- .../throwing/ThrowingDoubleToIntFunction.java | 24 +- .../ThrowingDoubleToLongFunction.java | 24 +- .../throwing/ThrowingDoubleUnaryOperator.java | 24 +- .../throwing/ThrowingFunction.java | 24 +- .../throwing/ThrowingIntBinaryOperator.java | 28 +- .../throwing/ThrowingIntConsumer.java | 22 +- .../throwing/ThrowingIntFunction.java | 24 +- .../throwing/ThrowingIntPredicate.java | 24 +- .../throwing/ThrowingIntSupplier.java | 20 +- .../throwing/ThrowingIntToDoubleFunction.java | 24 +- .../throwing/ThrowingIntToLongFunction.java | 24 +- .../throwing/ThrowingIntUnaryOperator.java | 24 +- .../throwing/ThrowingLongBinaryOperator.java | 28 +- .../throwing/ThrowingLongConsumer.java | 22 +- .../throwing/ThrowingLongFunction.java | 24 +- .../throwing/ThrowingLongPredicate.java | 24 +- .../throwing/ThrowingLongSupplier.java | 20 +- .../ThrowingLongToDoubleFunction.java | 24 +- .../throwing/ThrowingLongToIntFunction.java | 24 +- .../throwing/ThrowingLongUnaryOperator.java | 24 +- .../throwing/ThrowingObjDoubleConsumer.java | 26 +- .../throwing/ThrowingObjIntConsumer.java | 26 +- .../throwing/ThrowingObjLongConsumer.java | 26 +- .../throwing/ThrowingPredicate.java | 24 +- .../throwing/ThrowingRunnable.java | 18 +- .../throwing/ThrowingSupplier.java | 20 +- .../throwing/ThrowingToDoubleBiFunction.java | 28 +- .../throwing/ThrowingToDoubleFunction.java | 24 +- .../throwing/ThrowingToIntBiFunction.java | 28 +- .../throwing/ThrowingToIntFunction.java | 24 +- .../throwing/ThrowingToLongBiFunction.java | 28 +- .../throwing/ThrowingToLongFunction.java | 24 +- .../CheckedExceptionHandlerTest.java | 2994 ++++++------- .../noexception/ExceptionFilterTest.java | 2578 +++++------ .../noexception/ExceptionHandlerTest.java | 2578 +++++------ .../optional/DefaultBiFunctionTest.java | 28 +- .../optional/DefaultBiPredicateTest.java | 28 +- .../optional/DefaultBinaryOperatorTest.java | 28 +- .../optional/DefaultBooleanSupplierTest.java | 28 +- .../optional/DefaultComparatorTest.java | 28 +- .../DefaultDoubleBinaryOperatorTest.java | 28 +- .../optional/DefaultDoubleFunctionTest.java | 28 +- .../optional/DefaultDoublePredicateTest.java | 28 +- .../optional/DefaultDoubleSupplierTest.java | 28 +- .../DefaultDoubleToIntFunctionTest.java | 28 +- .../DefaultDoubleToLongFunctionTest.java | 28 +- .../DefaultDoubleUnaryOperatorTest.java | 28 +- .../optional/DefaultFunctionTest.java | 28 +- .../DefaultIntBinaryOperatorTest.java | 28 +- .../optional/DefaultIntFunctionTest.java | 28 +- .../optional/DefaultIntPredicateTest.java | 28 +- .../optional/DefaultIntSupplierTest.java | 28 +- .../DefaultIntToDoubleFunctionTest.java | 28 +- .../DefaultIntToLongFunctionTest.java | 28 +- .../optional/DefaultIntUnaryOperatorTest.java | 28 +- .../DefaultLongBinaryOperatorTest.java | 28 +- .../optional/DefaultLongFunctionTest.java | 28 +- .../optional/DefaultLongPredicateTest.java | 28 +- .../optional/DefaultLongSupplierTest.java | 28 +- .../DefaultLongToDoubleFunctionTest.java | 28 +- .../DefaultLongToIntFunctionTest.java | 28 +- .../DefaultLongUnaryOperatorTest.java | 28 +- .../optional/DefaultPredicateTest.java | 28 +- .../optional/DefaultSupplierTest.java | 28 +- .../DefaultToDoubleBiFunctionTest.java | 28 +- .../optional/DefaultToDoubleFunctionTest.java | 28 +- .../optional/DefaultToIntBiFunctionTest.java | 28 +- .../optional/DefaultToIntFunctionTest.java | 28 +- .../optional/DefaultToLongBiFunctionTest.java | 28 +- .../optional/DefaultToLongFunctionTest.java | 28 +- .../optional/DefaultUnaryOperatorTest.java | 28 +- .../optional/FallbackBiFunctionTest.java | 40 +- .../optional/FallbackBiPredicateTest.java | 40 +- .../optional/FallbackBinaryOperatorTest.java | 40 +- .../optional/FallbackBooleanSupplierTest.java | 40 +- .../optional/FallbackComparatorTest.java | 40 +- .../FallbackDoubleBinaryOperatorTest.java | 40 +- .../optional/FallbackDoubleFunctionTest.java | 40 +- .../optional/FallbackDoublePredicateTest.java | 40 +- .../optional/FallbackDoubleSupplierTest.java | 40 +- .../FallbackDoubleToIntFunctionTest.java | 40 +- .../FallbackDoubleToLongFunctionTest.java | 40 +- .../FallbackDoubleUnaryOperatorTest.java | 40 +- .../optional/FallbackFunctionTest.java | 40 +- .../FallbackIntBinaryOperatorTest.java | 40 +- .../optional/FallbackIntFunctionTest.java | 40 +- .../optional/FallbackIntPredicateTest.java | 40 +- .../optional/FallbackIntSupplierTest.java | 40 +- .../FallbackIntToDoubleFunctionTest.java | 40 +- .../FallbackIntToLongFunctionTest.java | 40 +- .../FallbackIntUnaryOperatorTest.java | 40 +- .../FallbackLongBinaryOperatorTest.java | 40 +- .../optional/FallbackLongFunctionTest.java | 40 +- .../optional/FallbackLongPredicateTest.java | 40 +- .../optional/FallbackLongSupplierTest.java | 40 +- .../FallbackLongToDoubleFunctionTest.java | 40 +- .../FallbackLongToIntFunctionTest.java | 40 +- .../FallbackLongUnaryOperatorTest.java | 40 +- .../optional/FallbackPredicateTest.java | 40 +- .../optional/FallbackSupplierTest.java | 40 +- .../FallbackToDoubleBiFunctionTest.java | 40 +- .../FallbackToDoubleFunctionTest.java | 40 +- .../optional/FallbackToIntBiFunctionTest.java | 40 +- .../optional/FallbackToIntFunctionTest.java | 40 +- .../FallbackToLongBiFunctionTest.java | 40 +- .../optional/FallbackToLongFunctionTest.java | 40 +- .../optional/FallbackUnaryOperatorTest.java | 40 +- .../optional/OptionalBiFunctionTest.java | 24 +- .../optional/OptionalBiPredicateTest.java | 24 +- .../optional/OptionalBinaryOperatorTest.java | 24 +- .../optional/OptionalBooleanSupplierTest.java | 24 +- .../optional/OptionalComparatorTest.java | 24 +- .../OptionalDoubleBinaryOperatorTest.java | 24 +- .../optional/OptionalDoubleFunctionTest.java | 24 +- .../optional/OptionalDoublePredicateTest.java | 24 +- .../optional/OptionalDoubleSupplierTest.java | 24 +- .../OptionalDoubleToIntFunctionTest.java | 24 +- .../OptionalDoubleToLongFunctionTest.java | 24 +- .../OptionalDoubleUnaryOperatorTest.java | 24 +- .../optional/OptionalFunctionTest.java | 24 +- .../OptionalIntBinaryOperatorTest.java | 24 +- .../optional/OptionalIntFunctionTest.java | 24 +- .../optional/OptionalIntPredicateTest.java | 24 +- .../optional/OptionalIntSupplierTest.java | 24 +- .../OptionalIntToDoubleFunctionTest.java | 24 +- .../OptionalIntToLongFunctionTest.java | 24 +- .../OptionalIntUnaryOperatorTest.java | 24 +- .../OptionalLongBinaryOperatorTest.java | 24 +- .../optional/OptionalLongFunctionTest.java | 24 +- .../optional/OptionalLongPredicateTest.java | 24 +- .../optional/OptionalLongSupplierTest.java | 24 +- .../OptionalLongToDoubleFunctionTest.java | 24 +- .../OptionalLongToIntFunctionTest.java | 24 +- .../OptionalLongUnaryOperatorTest.java | 24 +- .../optional/OptionalPredicateTest.java | 24 +- .../optional/OptionalSupplierTest.java | 24 +- .../OptionalToDoubleBiFunctionTest.java | 24 +- .../OptionalToDoubleFunctionTest.java | 24 +- .../optional/OptionalToIntBiFunctionTest.java | 24 +- .../optional/OptionalToIntFunctionTest.java | 24 +- .../OptionalToLongBiFunctionTest.java | 24 +- .../optional/OptionalToLongFunctionTest.java | 24 +- .../optional/OptionalUnaryOperatorTest.java | 24 +- .../throwing/ThrowingBiConsumerTest.java | 48 +- .../throwing/ThrowingBiFunctionTest.java | 44 +- .../throwing/ThrowingBiPredicateTest.java | 44 +- .../throwing/ThrowingBinaryOperatorTest.java | 44 +- .../throwing/ThrowingBooleanSupplierTest.java | 44 +- .../throwing/ThrowingComparatorTest.java | 44 +- .../throwing/ThrowingConsumerTest.java | 48 +- .../ThrowingDoubleBinaryOperatorTest.java | 44 +- .../throwing/ThrowingDoubleConsumerTest.java | 48 +- .../throwing/ThrowingDoubleFunctionTest.java | 44 +- .../throwing/ThrowingDoublePredicateTest.java | 44 +- .../throwing/ThrowingDoubleSupplierTest.java | 44 +- .../ThrowingDoubleToIntFunctionTest.java | 44 +- .../ThrowingDoubleToLongFunctionTest.java | 44 +- .../ThrowingDoubleUnaryOperatorTest.java | 44 +- .../throwing/ThrowingFunctionTest.java | 44 +- .../ThrowingIntBinaryOperatorTest.java | 44 +- .../throwing/ThrowingIntConsumerTest.java | 48 +- .../throwing/ThrowingIntFunctionTest.java | 44 +- .../throwing/ThrowingIntPredicateTest.java | 44 +- .../throwing/ThrowingIntSupplierTest.java | 44 +- .../ThrowingIntToDoubleFunctionTest.java | 44 +- .../ThrowingIntToLongFunctionTest.java | 44 +- .../ThrowingIntUnaryOperatorTest.java | 44 +- .../ThrowingLongBinaryOperatorTest.java | 44 +- .../throwing/ThrowingLongConsumerTest.java | 48 +- .../throwing/ThrowingLongFunctionTest.java | 44 +- .../throwing/ThrowingLongPredicateTest.java | 44 +- .../throwing/ThrowingLongSupplierTest.java | 44 +- .../ThrowingLongToDoubleFunctionTest.java | 44 +- .../ThrowingLongToIntFunctionTest.java | 44 +- .../ThrowingLongUnaryOperatorTest.java | 44 +- .../ThrowingObjDoubleConsumerTest.java | 48 +- .../throwing/ThrowingObjIntConsumerTest.java | 48 +- .../throwing/ThrowingObjLongConsumerTest.java | 48 +- .../throwing/ThrowingPredicateTest.java | 44 +- .../throwing/ThrowingRunnableTest.java | 48 +- .../throwing/ThrowingSupplierTest.java | 44 +- .../ThrowingToDoubleBiFunctionTest.java | 44 +- .../ThrowingToDoubleFunctionTest.java | 44 +- .../throwing/ThrowingToIntBiFunctionTest.java | 44 +- .../throwing/ThrowingToIntFunctionTest.java | 44 +- .../ThrowingToLongBiFunctionTest.java | 44 +- .../throwing/ThrowingToLongFunctionTest.java | 44 +- .../throwing/ThrowingUnaryOperatorTest.java | 44 +- 311 files changed, 15046 insertions(+), 15047 deletions(-) diff --git a/scripts/generate.py b/scripts/generate.py index 0eab077..739582e 100644 --- a/scripts/generate.py +++ b/scripts/generate.py @@ -396,9 +396,8 @@ def output(text, indent=0): text += '\n' if re.fullmatch('(?:[*].*\n)+', text): text = textwrap.indent(text, ' ') - for i in range(0, 5): - text = re.sub('^(\t*) {4}', r'\1\t', text, flags=re.MULTILINE) - text = textwrap.indent(text, indent * '\t') + text = text.replace('\t', ' ') + text = textwrap.indent(text, indent * ' ') print(text, end='') def redirect(path, generator): diff --git a/src/main/java/com/machinezoo/noexception/CheckedExceptionHandler.java b/src/main/java/com/machinezoo/noexception/CheckedExceptionHandler.java index 662261d..d97d3cb 100644 --- a/src/main/java/com/machinezoo/noexception/CheckedExceptionHandler.java +++ b/src/main/java/com/machinezoo/noexception/CheckedExceptionHandler.java @@ -43,1911 +43,1911 @@ * @see ExceptionFilter */ public abstract class CheckedExceptionHandler { - /** - * Converts checked exception into an unchecked one. This method must be defined in a derived class. - * Several implementations are provided by methods on {@link Exceptions} class. - * All other methods of the {@code CheckedExceptionHandler} call this method, but it can be also called directly. - *

- * This method represents reusable catch block that handles all checked exceptions in the same way. - * When invoked, it must somehow convert the checked exception into an unchecked one, usually by wrapping it. - * Caller is then expected to throw the returned exception. - * There can be special cases like {@link Exceptions#sneak()}, which don't return at all. - *

- * Callers should not pass in {@link RuntimeException} or other unchecked exceptions. - * This method might erroneously wrap such exceptions as if they are checked exceptions. - * Methods of this class never pass unchecked exceptions to this method. - * - * @param exception - * checked exception to convert - * @return converted unchecked exception - * @throws NullPointerException - * if {@code exception} is {@code null} - * @see Tutorial - * @see Exceptions - */ - public abstract RuntimeException handle(Exception exception); - /** - * Initializes new {@code CheckedExceptionHandler}. - */ - protected CheckedExceptionHandler() { - } - /** - * Removes checked exceptions from method signature of {@link ThrowingRunnable}. - *

- * If {@code runnable} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code runnable} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingRunnable(Exceptions.sneak().runnable(() -> my_throwing_lambda))} - * - * @param runnable - * the {@link ThrowingRunnable} to be converted, usually a lambda - * @return converted {@link Runnable} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final Runnable runnable(ThrowingRunnable runnable) { - return new CheckedRunnable(runnable); - } - private final class CheckedRunnable implements Runnable { - private final ThrowingRunnable runnable; - CheckedRunnable(ThrowingRunnable runnable) { - this.runnable = runnable; - } - @Override - public void run() { - try { - runnable.run(); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingSupplier}. - *

- * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code supplier} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingSupplier(Exceptions.sneak().supplier(() -> my_throwing_lambda))} - * - * @param - * see {@link Supplier} - * @param supplier - * the {@link ThrowingSupplier} to be converted, usually a lambda - * @return converted {@link Supplier} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final Supplier supplier(ThrowingSupplier supplier) { - return new CheckedSupplier(supplier); - } - private final class CheckedSupplier implements Supplier { - private final ThrowingSupplier supplier; - CheckedSupplier(ThrowingSupplier supplier) { - this.supplier = supplier; - } - @Override - public T get() { - try { - return supplier.get(); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingIntSupplier}. - *

- * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code supplier} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingIntSupplier(Exceptions.sneak().fromIntSupplier(() -> my_throwing_lambda))} - * - * @param supplier - * the {@link ThrowingIntSupplier} to be converted, usually a lambda - * @return converted {@link IntSupplier} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final IntSupplier fromIntSupplier(ThrowingIntSupplier supplier) { - return new CheckedIntSupplier(supplier); - } - private final class CheckedIntSupplier implements IntSupplier { - private final ThrowingIntSupplier supplier; - CheckedIntSupplier(ThrowingIntSupplier supplier) { - this.supplier = supplier; - } - @Override - public int getAsInt() { - try { - return supplier.getAsInt(); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingLongSupplier}. - *

- * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code supplier} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingLongSupplier(Exceptions.sneak().fromLongSupplier(() -> my_throwing_lambda))} - * - * @param supplier - * the {@link ThrowingLongSupplier} to be converted, usually a lambda - * @return converted {@link LongSupplier} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final LongSupplier fromLongSupplier(ThrowingLongSupplier supplier) { - return new CheckedLongSupplier(supplier); - } - private final class CheckedLongSupplier implements LongSupplier { - private final ThrowingLongSupplier supplier; - CheckedLongSupplier(ThrowingLongSupplier supplier) { - this.supplier = supplier; - } - @Override - public long getAsLong() { - try { - return supplier.getAsLong(); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingDoubleSupplier}. - *

- * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code supplier} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingDoubleSupplier(Exceptions.sneak().fromDoubleSupplier(() -> my_throwing_lambda))} - * - * @param supplier - * the {@link ThrowingDoubleSupplier} to be converted, usually a lambda - * @return converted {@link DoubleSupplier} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final DoubleSupplier fromDoubleSupplier(ThrowingDoubleSupplier supplier) { - return new CheckedDoubleSupplier(supplier); - } - private final class CheckedDoubleSupplier implements DoubleSupplier { - private final ThrowingDoubleSupplier supplier; - CheckedDoubleSupplier(ThrowingDoubleSupplier supplier) { - this.supplier = supplier; - } - @Override - public double getAsDouble() { - try { - return supplier.getAsDouble(); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingBooleanSupplier}. - *

- * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code supplier} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingBooleanSupplier(Exceptions.sneak().fromBooleanSupplier(() -> my_throwing_lambda))} - * - * @param supplier - * the {@link ThrowingBooleanSupplier} to be converted, usually a lambda - * @return converted {@link BooleanSupplier} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final BooleanSupplier fromBooleanSupplier(ThrowingBooleanSupplier supplier) { - return new CheckedBooleanSupplier(supplier); - } - private final class CheckedBooleanSupplier implements BooleanSupplier { - private final ThrowingBooleanSupplier supplier; - CheckedBooleanSupplier(ThrowingBooleanSupplier supplier) { - this.supplier = supplier; - } - @Override - public boolean getAsBoolean() { - try { - return supplier.getAsBoolean(); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingConsumer}. - *

- * If {@code consumer} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code consumer} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingConsumer(Exceptions.sneak().consumer(t -> my_throwing_lambda))} - * - * @param - * see {@link Consumer} - * @param consumer - * the {@link ThrowingConsumer} to be converted, usually a lambda - * @return converted {@link Consumer} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final Consumer consumer(ThrowingConsumer consumer) { - return new CheckedConsumer(consumer); - } - private final class CheckedConsumer implements Consumer { - private final ThrowingConsumer consumer; - CheckedConsumer(ThrowingConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(T t) { - try { - consumer.accept(t); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingIntConsumer}. - *

- * If {@code consumer} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code consumer} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingIntConsumer(Exceptions.sneak().fromIntConsumer(v -> my_throwing_lambda))} - * - * @param consumer - * the {@link ThrowingIntConsumer} to be converted, usually a lambda - * @return converted {@link IntConsumer} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final IntConsumer fromIntConsumer(ThrowingIntConsumer consumer) { - return new CheckedIntConsumer(consumer); - } - private final class CheckedIntConsumer implements IntConsumer { - private final ThrowingIntConsumer consumer; - CheckedIntConsumer(ThrowingIntConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(int value) { - try { - consumer.accept(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingLongConsumer}. - *

- * If {@code consumer} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code consumer} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingLongConsumer(Exceptions.sneak().fromLongConsumer(v -> my_throwing_lambda))} - * - * @param consumer - * the {@link ThrowingLongConsumer} to be converted, usually a lambda - * @return converted {@link LongConsumer} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final LongConsumer fromLongConsumer(ThrowingLongConsumer consumer) { - return new CheckedLongConsumer(consumer); - } - private final class CheckedLongConsumer implements LongConsumer { - private final ThrowingLongConsumer consumer; - CheckedLongConsumer(ThrowingLongConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(long value) { - try { - consumer.accept(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingDoubleConsumer}. - *

- * If {@code consumer} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code consumer} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingDoubleConsumer(Exceptions.sneak().fromDoubleConsumer(v -> my_throwing_lambda))} - * - * @param consumer - * the {@link ThrowingDoubleConsumer} to be converted, usually a lambda - * @return converted {@link DoubleConsumer} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final DoubleConsumer fromDoubleConsumer(ThrowingDoubleConsumer consumer) { - return new CheckedDoubleConsumer(consumer); - } - private final class CheckedDoubleConsumer implements DoubleConsumer { - private final ThrowingDoubleConsumer consumer; - CheckedDoubleConsumer(ThrowingDoubleConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(double value) { - try { - consumer.accept(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingBiConsumer}. - *

- * If {@code consumer} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code consumer} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingBiConsumer(Exceptions.sneak().fromBiConsumer((t, u) -> my_throwing_lambda))} - * - * @param - * see {@link BiConsumer} - * @param - * see {@link BiConsumer} - * @param consumer - * the {@link ThrowingBiConsumer} to be converted, usually a lambda - * @return converted {@link BiConsumer} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final BiConsumer fromBiConsumer(ThrowingBiConsumer consumer) { - return new CheckedBiConsumer(consumer); - } - private final class CheckedBiConsumer implements BiConsumer { - private final ThrowingBiConsumer consumer; - CheckedBiConsumer(ThrowingBiConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(T t, U u) { - try { - consumer.accept(t, u); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingObjIntConsumer}. - *

- * If {@code consumer} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code consumer} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingObjIntConsumer(Exceptions.sneak().fromObjIntConsumer((t, v) -> my_throwing_lambda))} - * - * @param - * see {@link ObjIntConsumer} - * @param consumer - * the {@link ThrowingObjIntConsumer} to be converted, usually a lambda - * @return converted {@link ObjIntConsumer} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final ObjIntConsumer fromObjIntConsumer(ThrowingObjIntConsumer consumer) { - return new CheckedObjIntConsumer(consumer); - } - private final class CheckedObjIntConsumer implements ObjIntConsumer { - private final ThrowingObjIntConsumer consumer; - CheckedObjIntConsumer(ThrowingObjIntConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(T t, int value) { - try { - consumer.accept(t, value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingObjLongConsumer}. - *

- * If {@code consumer} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code consumer} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingObjLongConsumer(Exceptions.sneak().fromObjLongConsumer((t, v) -> my_throwing_lambda))} - * - * @param - * see {@link ObjLongConsumer} - * @param consumer - * the {@link ThrowingObjLongConsumer} to be converted, usually a lambda - * @return converted {@link ObjLongConsumer} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final ObjLongConsumer fromObjLongConsumer(ThrowingObjLongConsumer consumer) { - return new CheckedObjLongConsumer(consumer); - } - private final class CheckedObjLongConsumer implements ObjLongConsumer { - private final ThrowingObjLongConsumer consumer; - CheckedObjLongConsumer(ThrowingObjLongConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(T t, long value) { - try { - consumer.accept(t, value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingObjDoubleConsumer}. - *

- * If {@code consumer} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code consumer} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingObjDoubleConsumer(Exceptions.sneak().fromObjDoubleConsumer((t, v) -> my_throwing_lambda))} - * - * @param - * see {@link ObjDoubleConsumer} - * @param consumer - * the {@link ThrowingObjDoubleConsumer} to be converted, usually a lambda - * @return converted {@link ObjDoubleConsumer} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final ObjDoubleConsumer fromObjDoubleConsumer(ThrowingObjDoubleConsumer consumer) { - return new CheckedObjDoubleConsumer(consumer); - } - private final class CheckedObjDoubleConsumer implements ObjDoubleConsumer { - private final ThrowingObjDoubleConsumer consumer; - CheckedObjDoubleConsumer(ThrowingObjDoubleConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(T t, double value) { - try { - consumer.accept(t, value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingPredicate}. - *

- * If {@code predicate} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code predicate} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingPredicate(Exceptions.sneak().predicate(t -> my_throwing_lambda))} - * - * @param - * see {@link Predicate} - * @param predicate - * the {@link ThrowingPredicate} to be converted, usually a lambda - * @return converted {@link Predicate} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final Predicate predicate(ThrowingPredicate predicate) { - return new CheckedPredicate(predicate); - } - private final class CheckedPredicate implements Predicate { - private final ThrowingPredicate predicate; - CheckedPredicate(ThrowingPredicate predicate) { - this.predicate = predicate; - } - @Override - public boolean test(T t) { - try { - return predicate.test(t); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingIntPredicate}. - *

- * If {@code predicate} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code predicate} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingIntPredicate(Exceptions.sneak().fromIntPredicate(v -> my_throwing_lambda))} - * - * @param predicate - * the {@link ThrowingIntPredicate} to be converted, usually a lambda - * @return converted {@link IntPredicate} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final IntPredicate fromIntPredicate(ThrowingIntPredicate predicate) { - return new CheckedIntPredicate(predicate); - } - private final class CheckedIntPredicate implements IntPredicate { - private final ThrowingIntPredicate predicate; - CheckedIntPredicate(ThrowingIntPredicate predicate) { - this.predicate = predicate; - } - @Override - public boolean test(int value) { - try { - return predicate.test(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingLongPredicate}. - *

- * If {@code predicate} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code predicate} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingLongPredicate(Exceptions.sneak().fromLongPredicate(v -> my_throwing_lambda))} - * - * @param predicate - * the {@link ThrowingLongPredicate} to be converted, usually a lambda - * @return converted {@link LongPredicate} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final LongPredicate fromLongPredicate(ThrowingLongPredicate predicate) { - return new CheckedLongPredicate(predicate); - } - private final class CheckedLongPredicate implements LongPredicate { - private final ThrowingLongPredicate predicate; - CheckedLongPredicate(ThrowingLongPredicate predicate) { - this.predicate = predicate; - } - @Override - public boolean test(long value) { - try { - return predicate.test(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingDoublePredicate}. - *

- * If {@code predicate} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code predicate} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingDoublePredicate(Exceptions.sneak().fromDoublePredicate(v -> my_throwing_lambda))} - * - * @param predicate - * the {@link ThrowingDoublePredicate} to be converted, usually a lambda - * @return converted {@link DoublePredicate} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final DoublePredicate fromDoublePredicate(ThrowingDoublePredicate predicate) { - return new CheckedDoublePredicate(predicate); - } - private final class CheckedDoublePredicate implements DoublePredicate { - private final ThrowingDoublePredicate predicate; - CheckedDoublePredicate(ThrowingDoublePredicate predicate) { - this.predicate = predicate; - } - @Override - public boolean test(double value) { - try { - return predicate.test(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingBiPredicate}. - *

- * If {@code predicate} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code predicate} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingBiPredicate(Exceptions.sneak().fromBiPredicate((t, u) -> my_throwing_lambda))} - * - * @param - * see {@link BiPredicate} - * @param - * see {@link BiPredicate} - * @param predicate - * the {@link ThrowingBiPredicate} to be converted, usually a lambda - * @return converted {@link BiPredicate} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final BiPredicate fromBiPredicate(ThrowingBiPredicate predicate) { - return new CheckedBiPredicate(predicate); - } - private final class CheckedBiPredicate implements BiPredicate { - private final ThrowingBiPredicate predicate; - CheckedBiPredicate(ThrowingBiPredicate predicate) { - this.predicate = predicate; - } - @Override - public boolean test(T t, U u) { - try { - return predicate.test(t, u); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingFunction}. - *

- * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingFunction(Exceptions.sneak().function(t -> my_throwing_lambda))} - * - * @param - * see {@link Function} - * @param - * see {@link Function} - * @param function - * the {@link ThrowingFunction} to be converted, usually a lambda - * @return converted {@link Function} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final Function function(ThrowingFunction function) { - return new CheckedFunction(function); - } - private final class CheckedFunction implements Function { - private final ThrowingFunction function; - CheckedFunction(ThrowingFunction function) { - this.function = function; - } - @Override - public R apply(T t) { - try { - return function.apply(t); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingToIntFunction}. - *

- * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingToIntFunction(Exceptions.sneak().fromToIntFunction(v -> my_throwing_lambda))} - * - * @param - * see {@link ToIntFunction} - * @param function - * the {@link ThrowingToIntFunction} to be converted, usually a lambda - * @return converted {@link ToIntFunction} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final ToIntFunction fromToIntFunction(ThrowingToIntFunction function) { - return new CheckedToIntFunction(function); - } - private final class CheckedToIntFunction implements ToIntFunction { - private final ThrowingToIntFunction function; - CheckedToIntFunction(ThrowingToIntFunction function) { - this.function = function; - } - @Override - public int applyAsInt(T value) { - try { - return function.applyAsInt(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingIntFunction}. - *

- * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingIntFunction(Exceptions.sneak().fromIntFunction(v -> my_throwing_lambda))} - * - * @param - * see {@link IntFunction} - * @param function - * the {@link ThrowingIntFunction} to be converted, usually a lambda - * @return converted {@link IntFunction} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final IntFunction fromIntFunction(ThrowingIntFunction function) { - return new CheckedIntFunction(function); - } - private final class CheckedIntFunction implements IntFunction { - private final ThrowingIntFunction function; - CheckedIntFunction(ThrowingIntFunction function) { - this.function = function; - } - @Override - public R apply(int value) { - try { - return function.apply(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingIntToLongFunction}. - *

- * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingIntToLongFunction(Exceptions.sneak().fromIntToLongFunction(v -> my_throwing_lambda))} - * - * @param function - * the {@link ThrowingIntToLongFunction} to be converted, usually a lambda - * @return converted {@link IntToLongFunction} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final IntToLongFunction fromIntToLongFunction(ThrowingIntToLongFunction function) { - return new CheckedIntToLongFunction(function); - } - private final class CheckedIntToLongFunction implements IntToLongFunction { - private final ThrowingIntToLongFunction function; - CheckedIntToLongFunction(ThrowingIntToLongFunction function) { - this.function = function; - } - @Override - public long applyAsLong(int value) { - try { - return function.applyAsLong(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingIntToDoubleFunction}. - *

- * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingIntToDoubleFunction(Exceptions.sneak().fromIntToDoubleFunction(v -> my_throwing_lambda))} - * - * @param function - * the {@link ThrowingIntToDoubleFunction} to be converted, usually a lambda - * @return converted {@link IntToDoubleFunction} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final IntToDoubleFunction fromIntToDoubleFunction(ThrowingIntToDoubleFunction function) { - return new CheckedIntToDoubleFunction(function); - } - private final class CheckedIntToDoubleFunction implements IntToDoubleFunction { - private final ThrowingIntToDoubleFunction function; - CheckedIntToDoubleFunction(ThrowingIntToDoubleFunction function) { - this.function = function; - } - @Override - public double applyAsDouble(int value) { - try { - return function.applyAsDouble(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingToLongFunction}. - *

- * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingToLongFunction(Exceptions.sneak().fromToLongFunction(v -> my_throwing_lambda))} - * - * @param - * see {@link ToLongFunction} - * @param function - * the {@link ThrowingToLongFunction} to be converted, usually a lambda - * @return converted {@link ToLongFunction} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final ToLongFunction fromToLongFunction(ThrowingToLongFunction function) { - return new CheckedToLongFunction(function); - } - private final class CheckedToLongFunction implements ToLongFunction { - private final ThrowingToLongFunction function; - CheckedToLongFunction(ThrowingToLongFunction function) { - this.function = function; - } - @Override - public long applyAsLong(T value) { - try { - return function.applyAsLong(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingLongFunction}. - *

- * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingLongFunction(Exceptions.sneak().fromLongFunction(v -> my_throwing_lambda))} - * - * @param - * see {@link LongFunction} - * @param function - * the {@link ThrowingLongFunction} to be converted, usually a lambda - * @return converted {@link LongFunction} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final LongFunction fromLongFunction(ThrowingLongFunction function) { - return new CheckedLongFunction(function); - } - private final class CheckedLongFunction implements LongFunction { - private final ThrowingLongFunction function; - CheckedLongFunction(ThrowingLongFunction function) { - this.function = function; - } - @Override - public R apply(long value) { - try { - return function.apply(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingLongToIntFunction}. - *

- * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingLongToIntFunction(Exceptions.sneak().fromLongToIntFunction(v -> my_throwing_lambda))} - * - * @param function - * the {@link ThrowingLongToIntFunction} to be converted, usually a lambda - * @return converted {@link LongToIntFunction} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final LongToIntFunction fromLongToIntFunction(ThrowingLongToIntFunction function) { - return new CheckedLongToIntFunction(function); - } - private final class CheckedLongToIntFunction implements LongToIntFunction { - private final ThrowingLongToIntFunction function; - CheckedLongToIntFunction(ThrowingLongToIntFunction function) { - this.function = function; - } - @Override - public int applyAsInt(long value) { - try { - return function.applyAsInt(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingLongToDoubleFunction}. - *

- * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingLongToDoubleFunction(Exceptions.sneak().fromLongToDoubleFunction(v -> my_throwing_lambda))} - * - * @param function - * the {@link ThrowingLongToDoubleFunction} to be converted, usually a lambda - * @return converted {@link LongToDoubleFunction} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final LongToDoubleFunction fromLongToDoubleFunction(ThrowingLongToDoubleFunction function) { - return new CheckedLongToDoubleFunction(function); - } - private final class CheckedLongToDoubleFunction implements LongToDoubleFunction { - private final ThrowingLongToDoubleFunction function; - CheckedLongToDoubleFunction(ThrowingLongToDoubleFunction function) { - this.function = function; - } - @Override - public double applyAsDouble(long value) { - try { - return function.applyAsDouble(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingToDoubleFunction}. - *

- * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingToDoubleFunction(Exceptions.sneak().fromToDoubleFunction(v -> my_throwing_lambda))} - * - * @param - * see {@link ToDoubleFunction} - * @param function - * the {@link ThrowingToDoubleFunction} to be converted, usually a lambda - * @return converted {@link ToDoubleFunction} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final ToDoubleFunction fromToDoubleFunction(ThrowingToDoubleFunction function) { - return new CheckedToDoubleFunction(function); - } - private final class CheckedToDoubleFunction implements ToDoubleFunction { - private final ThrowingToDoubleFunction function; - CheckedToDoubleFunction(ThrowingToDoubleFunction function) { - this.function = function; - } - @Override - public double applyAsDouble(T value) { - try { - return function.applyAsDouble(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingDoubleFunction}. - *

- * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingDoubleFunction(Exceptions.sneak().fromDoubleFunction(v -> my_throwing_lambda))} - * - * @param - * see {@link DoubleFunction} - * @param function - * the {@link ThrowingDoubleFunction} to be converted, usually a lambda - * @return converted {@link DoubleFunction} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final DoubleFunction fromDoubleFunction(ThrowingDoubleFunction function) { - return new CheckedDoubleFunction(function); - } - private final class CheckedDoubleFunction implements DoubleFunction { - private final ThrowingDoubleFunction function; - CheckedDoubleFunction(ThrowingDoubleFunction function) { - this.function = function; - } - @Override - public R apply(double value) { - try { - return function.apply(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingDoubleToIntFunction}. - *

- * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingDoubleToIntFunction(Exceptions.sneak().fromDoubleToIntFunction(v -> my_throwing_lambda))} - * - * @param function - * the {@link ThrowingDoubleToIntFunction} to be converted, usually a lambda - * @return converted {@link DoubleToIntFunction} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final DoubleToIntFunction fromDoubleToIntFunction(ThrowingDoubleToIntFunction function) { - return new CheckedDoubleToIntFunction(function); - } - private final class CheckedDoubleToIntFunction implements DoubleToIntFunction { - private final ThrowingDoubleToIntFunction function; - CheckedDoubleToIntFunction(ThrowingDoubleToIntFunction function) { - this.function = function; - } - @Override - public int applyAsInt(double value) { - try { - return function.applyAsInt(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingDoubleToLongFunction}. - *

- * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingDoubleToLongFunction(Exceptions.sneak().fromDoubleToLongFunction(v -> my_throwing_lambda))} - * - * @param function - * the {@link ThrowingDoubleToLongFunction} to be converted, usually a lambda - * @return converted {@link DoubleToLongFunction} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final DoubleToLongFunction fromDoubleToLongFunction(ThrowingDoubleToLongFunction function) { - return new CheckedDoubleToLongFunction(function); - } - private final class CheckedDoubleToLongFunction implements DoubleToLongFunction { - private final ThrowingDoubleToLongFunction function; - CheckedDoubleToLongFunction(ThrowingDoubleToLongFunction function) { - this.function = function; - } - @Override - public long applyAsLong(double value) { - try { - return function.applyAsLong(value); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingUnaryOperator}. - *

- * If {@code operator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code operator} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingUnaryOperator(Exceptions.sneak().fromUnaryOperator(o -> my_throwing_lambda))} - * - * @param - * see {@link UnaryOperator} - * @param operator - * the {@link ThrowingUnaryOperator} to be converted, usually a lambda - * @return converted {@link UnaryOperator} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final UnaryOperator fromUnaryOperator(ThrowingUnaryOperator operator) { - return new CheckedUnaryOperator(operator); - } - private final class CheckedUnaryOperator implements UnaryOperator { - private final ThrowingUnaryOperator operator; - CheckedUnaryOperator(ThrowingUnaryOperator operator) { - this.operator = operator; - } - @Override - public T apply(T operand) { - try { - return operator.apply(operand); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingIntUnaryOperator}. - *

- * If {@code operator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code operator} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingIntUnaryOperator(Exceptions.sneak().fromIntUnaryOperator(o -> my_throwing_lambda))} - * - * @param operator - * the {@link ThrowingIntUnaryOperator} to be converted, usually a lambda - * @return converted {@link IntUnaryOperator} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final IntUnaryOperator fromIntUnaryOperator(ThrowingIntUnaryOperator operator) { - return new CheckedIntUnaryOperator(operator); - } - private final class CheckedIntUnaryOperator implements IntUnaryOperator { - private final ThrowingIntUnaryOperator operator; - CheckedIntUnaryOperator(ThrowingIntUnaryOperator operator) { - this.operator = operator; - } - @Override - public int applyAsInt(int operand) { - try { - return operator.applyAsInt(operand); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingLongUnaryOperator}. - *

- * If {@code operator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code operator} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingLongUnaryOperator(Exceptions.sneak().fromLongUnaryOperator(o -> my_throwing_lambda))} - * - * @param operator - * the {@link ThrowingLongUnaryOperator} to be converted, usually a lambda - * @return converted {@link LongUnaryOperator} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final LongUnaryOperator fromLongUnaryOperator(ThrowingLongUnaryOperator operator) { - return new CheckedLongUnaryOperator(operator); - } - private final class CheckedLongUnaryOperator implements LongUnaryOperator { - private final ThrowingLongUnaryOperator operator; - CheckedLongUnaryOperator(ThrowingLongUnaryOperator operator) { - this.operator = operator; - } - @Override - public long applyAsLong(long operand) { - try { - return operator.applyAsLong(operand); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingDoubleUnaryOperator}. - *

- * If {@code operator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code operator} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingDoubleUnaryOperator(Exceptions.sneak().fromDoubleUnaryOperator(o -> my_throwing_lambda))} - * - * @param operator - * the {@link ThrowingDoubleUnaryOperator} to be converted, usually a lambda - * @return converted {@link DoubleUnaryOperator} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final DoubleUnaryOperator fromDoubleUnaryOperator(ThrowingDoubleUnaryOperator operator) { - return new CheckedDoubleUnaryOperator(operator); - } - private final class CheckedDoubleUnaryOperator implements DoubleUnaryOperator { - private final ThrowingDoubleUnaryOperator operator; - CheckedDoubleUnaryOperator(ThrowingDoubleUnaryOperator operator) { - this.operator = operator; - } - @Override - public double applyAsDouble(double operand) { - try { - return operator.applyAsDouble(operand); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingBiFunction}. - *

- * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingBiFunction(Exceptions.sneak().fromBiFunction((t, u) -> my_throwing_lambda))} - * - * @param - * see {@link BiFunction} - * @param - * see {@link BiFunction} - * @param - * see {@link BiFunction} - * @param function - * the {@link ThrowingBiFunction} to be converted, usually a lambda - * @return converted {@link BiFunction} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final BiFunction fromBiFunction(ThrowingBiFunction function) { - return new CheckedBiFunction(function); - } - private final class CheckedBiFunction implements BiFunction { - private final ThrowingBiFunction function; - CheckedBiFunction(ThrowingBiFunction function) { - this.function = function; - } - @Override - public R apply(T t, U u) { - try { - return function.apply(t, u); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingToIntBiFunction}. - *

- * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingToIntBiFunction(Exceptions.sneak().fromToIntBiFunction((t, u) -> my_throwing_lambda))} - * - * @param - * see {@link ToIntBiFunction} - * @param - * see {@link ToIntBiFunction} - * @param function - * the {@link ThrowingToIntBiFunction} to be converted, usually a lambda - * @return converted {@link ToIntBiFunction} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final ToIntBiFunction fromToIntBiFunction(ThrowingToIntBiFunction function) { - return new CheckedToIntBiFunction(function); - } - private final class CheckedToIntBiFunction implements ToIntBiFunction { - private final ThrowingToIntBiFunction function; - CheckedToIntBiFunction(ThrowingToIntBiFunction function) { - this.function = function; - } - @Override - public int applyAsInt(T t, U u) { - try { - return function.applyAsInt(t, u); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingToLongBiFunction}. - *

- * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingToLongBiFunction(Exceptions.sneak().fromToLongBiFunction((t, u) -> my_throwing_lambda))} - * - * @param - * see {@link ToLongBiFunction} - * @param - * see {@link ToLongBiFunction} - * @param function - * the {@link ThrowingToLongBiFunction} to be converted, usually a lambda - * @return converted {@link ToLongBiFunction} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final ToLongBiFunction fromToLongBiFunction(ThrowingToLongBiFunction function) { - return new CheckedToLongBiFunction(function); - } - private final class CheckedToLongBiFunction implements ToLongBiFunction { - private final ThrowingToLongBiFunction function; - CheckedToLongBiFunction(ThrowingToLongBiFunction function) { - this.function = function; - } - @Override - public long applyAsLong(T t, U u) { - try { - return function.applyAsLong(t, u); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingToDoubleBiFunction}. - *

- * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingToDoubleBiFunction(Exceptions.sneak().fromToDoubleBiFunction((t, u) -> my_throwing_lambda))} - * - * @param - * see {@link ToDoubleBiFunction} - * @param - * see {@link ToDoubleBiFunction} - * @param function - * the {@link ThrowingToDoubleBiFunction} to be converted, usually a lambda - * @return converted {@link ToDoubleBiFunction} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final ToDoubleBiFunction fromToDoubleBiFunction(ThrowingToDoubleBiFunction function) { - return new CheckedToDoubleBiFunction(function); - } - private final class CheckedToDoubleBiFunction implements ToDoubleBiFunction { - private final ThrowingToDoubleBiFunction function; - CheckedToDoubleBiFunction(ThrowingToDoubleBiFunction function) { - this.function = function; - } - @Override - public double applyAsDouble(T t, U u) { - try { - return function.applyAsDouble(t, u); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingBinaryOperator}. - *

- * If {@code operator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code operator} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingBinaryOperator(Exceptions.sneak().fromBinaryOperator((l, r) -> my_throwing_lambda))} - * - * @param - * see {@link BinaryOperator} - * @param operator - * the {@link ThrowingBinaryOperator} to be converted, usually a lambda - * @return converted {@link BinaryOperator} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final BinaryOperator fromBinaryOperator(ThrowingBinaryOperator operator) { - return new CheckedBinaryOperator(operator); - } - private final class CheckedBinaryOperator implements BinaryOperator { - private final ThrowingBinaryOperator operator; - CheckedBinaryOperator(ThrowingBinaryOperator operator) { - this.operator = operator; - } - @Override - public T apply(T left, T right) { - try { - return operator.apply(left, right); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingIntBinaryOperator}. - *

- * If {@code operator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code operator} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingIntBinaryOperator(Exceptions.sneak().fromIntBinaryOperator((l, r) -> my_throwing_lambda))} - * - * @param operator - * the {@link ThrowingIntBinaryOperator} to be converted, usually a lambda - * @return converted {@link IntBinaryOperator} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final IntBinaryOperator fromIntBinaryOperator(ThrowingIntBinaryOperator operator) { - return new CheckedIntBinaryOperator(operator); - } - private final class CheckedIntBinaryOperator implements IntBinaryOperator { - private final ThrowingIntBinaryOperator operator; - CheckedIntBinaryOperator(ThrowingIntBinaryOperator operator) { - this.operator = operator; - } - @Override - public int applyAsInt(int left, int right) { - try { - return operator.applyAsInt(left, right); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingLongBinaryOperator}. - *

- * If {@code operator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code operator} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingLongBinaryOperator(Exceptions.sneak().fromLongBinaryOperator((l, r) -> my_throwing_lambda))} - * - * @param operator - * the {@link ThrowingLongBinaryOperator} to be converted, usually a lambda - * @return converted {@link LongBinaryOperator} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final LongBinaryOperator fromLongBinaryOperator(ThrowingLongBinaryOperator operator) { - return new CheckedLongBinaryOperator(operator); - } - private final class CheckedLongBinaryOperator implements LongBinaryOperator { - private final ThrowingLongBinaryOperator operator; - CheckedLongBinaryOperator(ThrowingLongBinaryOperator operator) { - this.operator = operator; - } - @Override - public long applyAsLong(long left, long right) { - try { - return operator.applyAsLong(left, right); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingDoubleBinaryOperator}. - *

- * If {@code operator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code operator} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingDoubleBinaryOperator(Exceptions.sneak().fromDoubleBinaryOperator((l, r) -> my_throwing_lambda))} - * - * @param operator - * the {@link ThrowingDoubleBinaryOperator} to be converted, usually a lambda - * @return converted {@link DoubleBinaryOperator} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final DoubleBinaryOperator fromDoubleBinaryOperator(ThrowingDoubleBinaryOperator operator) { - return new CheckedDoubleBinaryOperator(operator); - } - private final class CheckedDoubleBinaryOperator implements DoubleBinaryOperator { - private final ThrowingDoubleBinaryOperator operator; - CheckedDoubleBinaryOperator(ThrowingDoubleBinaryOperator operator) { - this.operator = operator; - } - @Override - public double applyAsDouble(double left, double right) { - try { - return operator.applyAsDouble(left, right); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link ThrowingComparator}. - *

- * If {@code comparator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code comparator} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code methodTakingComparator(Exceptions.sneak().comparator((l, r) -> my_throwing_lambda))} - * - * @param - * see {@link Comparator} - * @param comparator - * the {@link ThrowingComparator} to be converted, usually a lambda - * @return converted {@link Comparator} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final Comparator comparator(ThrowingComparator comparator) { - return new CheckedComparator(comparator); - } - private final class CheckedComparator implements Comparator { - private final ThrowingComparator comparator; - CheckedComparator(ThrowingComparator comparator) { - this.comparator = comparator; - } - @Override - public int compare(T left, T right) { - try { - return comparator.compare(left, right); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Removes checked exceptions from method signature of {@link AutoCloseable}. - *

- * If {@code closeable} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - * Null {@code closeable} is silently wrapped and causes {@link NullPointerException} when executed. - *

- * Typical usage: {@code try (var scope = Exceptions.sneak().closeable(openSomething()))} - * - * @param closeable - * the {@link AutoCloseable} to be converted - * @return converted {@link CloseableScope} free of checked exceptions - * @see Tutorial - * @see Exceptions - */ - public final CloseableScope closeable(AutoCloseable closeable) { - return new CheckedCloseableScope(closeable); - } - private final class CheckedCloseableScope implements CloseableScope { - private final AutoCloseable closeable; - CheckedCloseableScope(AutoCloseable closeable) { - this.closeable = closeable; - } - @Override - public void close() { - try { - closeable.close(); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - } - /** - * Filters out checked exceptions while running {@link ThrowingRunnable}. - *

- * If {@code runnable} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - *

- * Typical usage: {@code Exceptions.sneak().run(() -> my_throwing_lambda))} - * - * @param runnable - * the {@link ThrowingRunnable} to run, usually a lambda - * @throws NullPointerException - * if {@code runnable} is {@code null} - * @see Tutorial - * @see Exceptions - */ - public final void run(ThrowingRunnable runnable) { - try { - runnable.run(); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - /** - * Filters out checked exceptions while running {@link ThrowingSupplier}. - *

- * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - *

- * Typical usage: {@code Exceptions.sneak().get(() -> my_throwing_lambda))} - * - * @param - * see {@link Supplier} - * @param supplier - * the {@link ThrowingSupplier} to run, usually a lambda - * @return value returned from {@code supplier} - * @throws NullPointerException - * if {@code supplier} is {@code null} - * @see Tutorial - * @see Exceptions - */ - public final T get(ThrowingSupplier supplier) { - try { - return supplier.get(); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - /** - * Filters out checked exceptions while running {@link ThrowingIntSupplier}. - *

- * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - *

- * Typical usage: {@code Exceptions.sneak().getAsInt(() -> my_throwing_lambda))} - * - * @param supplier - * the {@link ThrowingIntSupplier} to run, usually a lambda - * @return value returned from {@code supplier} - * @throws NullPointerException - * if {@code supplier} is {@code null} - * @see Tutorial - * @see Exceptions - */ - public final int getAsInt(ThrowingIntSupplier supplier) { - try { - return supplier.getAsInt(); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - /** - * Filters out checked exceptions while running {@link ThrowingLongSupplier}. - *

- * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - *

- * Typical usage: {@code Exceptions.sneak().getAsLong(() -> my_throwing_lambda))} - * - * @param supplier - * the {@link ThrowingLongSupplier} to run, usually a lambda - * @return value returned from {@code supplier} - * @throws NullPointerException - * if {@code supplier} is {@code null} - * @see Tutorial - * @see Exceptions - */ - public final long getAsLong(ThrowingLongSupplier supplier) { - try { - return supplier.getAsLong(); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - /** - * Filters out checked exceptions while running {@link ThrowingDoubleSupplier}. - *

- * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - *

- * Typical usage: {@code Exceptions.sneak().getAsDouble(() -> my_throwing_lambda))} - * - * @param supplier - * the {@link ThrowingDoubleSupplier} to run, usually a lambda - * @return value returned from {@code supplier} - * @throws NullPointerException - * if {@code supplier} is {@code null} - * @see Tutorial - * @see Exceptions - */ - public final double getAsDouble(ThrowingDoubleSupplier supplier) { - try { - return supplier.getAsDouble(); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } - /** - * Filters out checked exceptions while running {@link ThrowingBooleanSupplier}. - *

- * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, - * which usually converts it to an unchecked exception, which is then thrown by this method. - *

- * Typical usage: {@code Exceptions.sneak().getAsBoolean(() -> my_throwing_lambda))} - * - * @param supplier - * the {@link ThrowingBooleanSupplier} to run, usually a lambda - * @return value returned from {@code supplier} - * @throws NullPointerException - * if {@code supplier} is {@code null} - * @see Tutorial - * @see Exceptions - */ - public final boolean getAsBoolean(ThrowingBooleanSupplier supplier) { - try { - return supplier.getAsBoolean(); - } catch (RuntimeException exception) { - throw exception; - } catch (Exception exception) { - throw handle(exception); - } catch (Throwable exception) { - throw SneakingHandler.sneak(exception); - } - } + /** + * Converts checked exception into an unchecked one. This method must be defined in a derived class. + * Several implementations are provided by methods on {@link Exceptions} class. + * All other methods of the {@code CheckedExceptionHandler} call this method, but it can be also called directly. + *

+ * This method represents reusable catch block that handles all checked exceptions in the same way. + * When invoked, it must somehow convert the checked exception into an unchecked one, usually by wrapping it. + * Caller is then expected to throw the returned exception. + * There can be special cases like {@link Exceptions#sneak()}, which don't return at all. + *

+ * Callers should not pass in {@link RuntimeException} or other unchecked exceptions. + * This method might erroneously wrap such exceptions as if they are checked exceptions. + * Methods of this class never pass unchecked exceptions to this method. + * + * @param exception + * checked exception to convert + * @return converted unchecked exception + * @throws NullPointerException + * if {@code exception} is {@code null} + * @see Tutorial + * @see Exceptions + */ + public abstract RuntimeException handle(Exception exception); + /** + * Initializes new {@code CheckedExceptionHandler}. + */ + protected CheckedExceptionHandler() { + } + /** + * Removes checked exceptions from method signature of {@link ThrowingRunnable}. + *

+ * If {@code runnable} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code runnable} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingRunnable(Exceptions.sneak().runnable(() -> my_throwing_lambda))} + * + * @param runnable + * the {@link ThrowingRunnable} to be converted, usually a lambda + * @return converted {@link Runnable} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final Runnable runnable(ThrowingRunnable runnable) { + return new CheckedRunnable(runnable); + } + private final class CheckedRunnable implements Runnable { + private final ThrowingRunnable runnable; + CheckedRunnable(ThrowingRunnable runnable) { + this.runnable = runnable; + } + @Override + public void run() { + try { + runnable.run(); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingSupplier}. + *

+ * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code supplier} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingSupplier(Exceptions.sneak().supplier(() -> my_throwing_lambda))} + * + * @param + * see {@link Supplier} + * @param supplier + * the {@link ThrowingSupplier} to be converted, usually a lambda + * @return converted {@link Supplier} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final Supplier supplier(ThrowingSupplier supplier) { + return new CheckedSupplier(supplier); + } + private final class CheckedSupplier implements Supplier { + private final ThrowingSupplier supplier; + CheckedSupplier(ThrowingSupplier supplier) { + this.supplier = supplier; + } + @Override + public T get() { + try { + return supplier.get(); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingIntSupplier}. + *

+ * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code supplier} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingIntSupplier(Exceptions.sneak().fromIntSupplier(() -> my_throwing_lambda))} + * + * @param supplier + * the {@link ThrowingIntSupplier} to be converted, usually a lambda + * @return converted {@link IntSupplier} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final IntSupplier fromIntSupplier(ThrowingIntSupplier supplier) { + return new CheckedIntSupplier(supplier); + } + private final class CheckedIntSupplier implements IntSupplier { + private final ThrowingIntSupplier supplier; + CheckedIntSupplier(ThrowingIntSupplier supplier) { + this.supplier = supplier; + } + @Override + public int getAsInt() { + try { + return supplier.getAsInt(); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingLongSupplier}. + *

+ * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code supplier} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingLongSupplier(Exceptions.sneak().fromLongSupplier(() -> my_throwing_lambda))} + * + * @param supplier + * the {@link ThrowingLongSupplier} to be converted, usually a lambda + * @return converted {@link LongSupplier} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final LongSupplier fromLongSupplier(ThrowingLongSupplier supplier) { + return new CheckedLongSupplier(supplier); + } + private final class CheckedLongSupplier implements LongSupplier { + private final ThrowingLongSupplier supplier; + CheckedLongSupplier(ThrowingLongSupplier supplier) { + this.supplier = supplier; + } + @Override + public long getAsLong() { + try { + return supplier.getAsLong(); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingDoubleSupplier}. + *

+ * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code supplier} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingDoubleSupplier(Exceptions.sneak().fromDoubleSupplier(() -> my_throwing_lambda))} + * + * @param supplier + * the {@link ThrowingDoubleSupplier} to be converted, usually a lambda + * @return converted {@link DoubleSupplier} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final DoubleSupplier fromDoubleSupplier(ThrowingDoubleSupplier supplier) { + return new CheckedDoubleSupplier(supplier); + } + private final class CheckedDoubleSupplier implements DoubleSupplier { + private final ThrowingDoubleSupplier supplier; + CheckedDoubleSupplier(ThrowingDoubleSupplier supplier) { + this.supplier = supplier; + } + @Override + public double getAsDouble() { + try { + return supplier.getAsDouble(); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingBooleanSupplier}. + *

+ * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code supplier} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingBooleanSupplier(Exceptions.sneak().fromBooleanSupplier(() -> my_throwing_lambda))} + * + * @param supplier + * the {@link ThrowingBooleanSupplier} to be converted, usually a lambda + * @return converted {@link BooleanSupplier} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final BooleanSupplier fromBooleanSupplier(ThrowingBooleanSupplier supplier) { + return new CheckedBooleanSupplier(supplier); + } + private final class CheckedBooleanSupplier implements BooleanSupplier { + private final ThrowingBooleanSupplier supplier; + CheckedBooleanSupplier(ThrowingBooleanSupplier supplier) { + this.supplier = supplier; + } + @Override + public boolean getAsBoolean() { + try { + return supplier.getAsBoolean(); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingConsumer}. + *

+ * If {@code consumer} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code consumer} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingConsumer(Exceptions.sneak().consumer(t -> my_throwing_lambda))} + * + * @param + * see {@link Consumer} + * @param consumer + * the {@link ThrowingConsumer} to be converted, usually a lambda + * @return converted {@link Consumer} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final Consumer consumer(ThrowingConsumer consumer) { + return new CheckedConsumer(consumer); + } + private final class CheckedConsumer implements Consumer { + private final ThrowingConsumer consumer; + CheckedConsumer(ThrowingConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(T t) { + try { + consumer.accept(t); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingIntConsumer}. + *

+ * If {@code consumer} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code consumer} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingIntConsumer(Exceptions.sneak().fromIntConsumer(v -> my_throwing_lambda))} + * + * @param consumer + * the {@link ThrowingIntConsumer} to be converted, usually a lambda + * @return converted {@link IntConsumer} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final IntConsumer fromIntConsumer(ThrowingIntConsumer consumer) { + return new CheckedIntConsumer(consumer); + } + private final class CheckedIntConsumer implements IntConsumer { + private final ThrowingIntConsumer consumer; + CheckedIntConsumer(ThrowingIntConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(int value) { + try { + consumer.accept(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingLongConsumer}. + *

+ * If {@code consumer} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code consumer} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingLongConsumer(Exceptions.sneak().fromLongConsumer(v -> my_throwing_lambda))} + * + * @param consumer + * the {@link ThrowingLongConsumer} to be converted, usually a lambda + * @return converted {@link LongConsumer} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final LongConsumer fromLongConsumer(ThrowingLongConsumer consumer) { + return new CheckedLongConsumer(consumer); + } + private final class CheckedLongConsumer implements LongConsumer { + private final ThrowingLongConsumer consumer; + CheckedLongConsumer(ThrowingLongConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(long value) { + try { + consumer.accept(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingDoubleConsumer}. + *

+ * If {@code consumer} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code consumer} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingDoubleConsumer(Exceptions.sneak().fromDoubleConsumer(v -> my_throwing_lambda))} + * + * @param consumer + * the {@link ThrowingDoubleConsumer} to be converted, usually a lambda + * @return converted {@link DoubleConsumer} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final DoubleConsumer fromDoubleConsumer(ThrowingDoubleConsumer consumer) { + return new CheckedDoubleConsumer(consumer); + } + private final class CheckedDoubleConsumer implements DoubleConsumer { + private final ThrowingDoubleConsumer consumer; + CheckedDoubleConsumer(ThrowingDoubleConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(double value) { + try { + consumer.accept(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingBiConsumer}. + *

+ * If {@code consumer} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code consumer} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingBiConsumer(Exceptions.sneak().fromBiConsumer((t, u) -> my_throwing_lambda))} + * + * @param + * see {@link BiConsumer} + * @param + * see {@link BiConsumer} + * @param consumer + * the {@link ThrowingBiConsumer} to be converted, usually a lambda + * @return converted {@link BiConsumer} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final BiConsumer fromBiConsumer(ThrowingBiConsumer consumer) { + return new CheckedBiConsumer(consumer); + } + private final class CheckedBiConsumer implements BiConsumer { + private final ThrowingBiConsumer consumer; + CheckedBiConsumer(ThrowingBiConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(T t, U u) { + try { + consumer.accept(t, u); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingObjIntConsumer}. + *

+ * If {@code consumer} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code consumer} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingObjIntConsumer(Exceptions.sneak().fromObjIntConsumer((t, v) -> my_throwing_lambda))} + * + * @param + * see {@link ObjIntConsumer} + * @param consumer + * the {@link ThrowingObjIntConsumer} to be converted, usually a lambda + * @return converted {@link ObjIntConsumer} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final ObjIntConsumer fromObjIntConsumer(ThrowingObjIntConsumer consumer) { + return new CheckedObjIntConsumer(consumer); + } + private final class CheckedObjIntConsumer implements ObjIntConsumer { + private final ThrowingObjIntConsumer consumer; + CheckedObjIntConsumer(ThrowingObjIntConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(T t, int value) { + try { + consumer.accept(t, value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingObjLongConsumer}. + *

+ * If {@code consumer} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code consumer} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingObjLongConsumer(Exceptions.sneak().fromObjLongConsumer((t, v) -> my_throwing_lambda))} + * + * @param + * see {@link ObjLongConsumer} + * @param consumer + * the {@link ThrowingObjLongConsumer} to be converted, usually a lambda + * @return converted {@link ObjLongConsumer} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final ObjLongConsumer fromObjLongConsumer(ThrowingObjLongConsumer consumer) { + return new CheckedObjLongConsumer(consumer); + } + private final class CheckedObjLongConsumer implements ObjLongConsumer { + private final ThrowingObjLongConsumer consumer; + CheckedObjLongConsumer(ThrowingObjLongConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(T t, long value) { + try { + consumer.accept(t, value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingObjDoubleConsumer}. + *

+ * If {@code consumer} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code consumer} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingObjDoubleConsumer(Exceptions.sneak().fromObjDoubleConsumer((t, v) -> my_throwing_lambda))} + * + * @param + * see {@link ObjDoubleConsumer} + * @param consumer + * the {@link ThrowingObjDoubleConsumer} to be converted, usually a lambda + * @return converted {@link ObjDoubleConsumer} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final ObjDoubleConsumer fromObjDoubleConsumer(ThrowingObjDoubleConsumer consumer) { + return new CheckedObjDoubleConsumer(consumer); + } + private final class CheckedObjDoubleConsumer implements ObjDoubleConsumer { + private final ThrowingObjDoubleConsumer consumer; + CheckedObjDoubleConsumer(ThrowingObjDoubleConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(T t, double value) { + try { + consumer.accept(t, value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingPredicate}. + *

+ * If {@code predicate} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code predicate} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingPredicate(Exceptions.sneak().predicate(t -> my_throwing_lambda))} + * + * @param + * see {@link Predicate} + * @param predicate + * the {@link ThrowingPredicate} to be converted, usually a lambda + * @return converted {@link Predicate} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final Predicate predicate(ThrowingPredicate predicate) { + return new CheckedPredicate(predicate); + } + private final class CheckedPredicate implements Predicate { + private final ThrowingPredicate predicate; + CheckedPredicate(ThrowingPredicate predicate) { + this.predicate = predicate; + } + @Override + public boolean test(T t) { + try { + return predicate.test(t); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingIntPredicate}. + *

+ * If {@code predicate} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code predicate} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingIntPredicate(Exceptions.sneak().fromIntPredicate(v -> my_throwing_lambda))} + * + * @param predicate + * the {@link ThrowingIntPredicate} to be converted, usually a lambda + * @return converted {@link IntPredicate} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final IntPredicate fromIntPredicate(ThrowingIntPredicate predicate) { + return new CheckedIntPredicate(predicate); + } + private final class CheckedIntPredicate implements IntPredicate { + private final ThrowingIntPredicate predicate; + CheckedIntPredicate(ThrowingIntPredicate predicate) { + this.predicate = predicate; + } + @Override + public boolean test(int value) { + try { + return predicate.test(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingLongPredicate}. + *

+ * If {@code predicate} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code predicate} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingLongPredicate(Exceptions.sneak().fromLongPredicate(v -> my_throwing_lambda))} + * + * @param predicate + * the {@link ThrowingLongPredicate} to be converted, usually a lambda + * @return converted {@link LongPredicate} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final LongPredicate fromLongPredicate(ThrowingLongPredicate predicate) { + return new CheckedLongPredicate(predicate); + } + private final class CheckedLongPredicate implements LongPredicate { + private final ThrowingLongPredicate predicate; + CheckedLongPredicate(ThrowingLongPredicate predicate) { + this.predicate = predicate; + } + @Override + public boolean test(long value) { + try { + return predicate.test(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingDoublePredicate}. + *

+ * If {@code predicate} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code predicate} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingDoublePredicate(Exceptions.sneak().fromDoublePredicate(v -> my_throwing_lambda))} + * + * @param predicate + * the {@link ThrowingDoublePredicate} to be converted, usually a lambda + * @return converted {@link DoublePredicate} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final DoublePredicate fromDoublePredicate(ThrowingDoublePredicate predicate) { + return new CheckedDoublePredicate(predicate); + } + private final class CheckedDoublePredicate implements DoublePredicate { + private final ThrowingDoublePredicate predicate; + CheckedDoublePredicate(ThrowingDoublePredicate predicate) { + this.predicate = predicate; + } + @Override + public boolean test(double value) { + try { + return predicate.test(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingBiPredicate}. + *

+ * If {@code predicate} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code predicate} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingBiPredicate(Exceptions.sneak().fromBiPredicate((t, u) -> my_throwing_lambda))} + * + * @param + * see {@link BiPredicate} + * @param + * see {@link BiPredicate} + * @param predicate + * the {@link ThrowingBiPredicate} to be converted, usually a lambda + * @return converted {@link BiPredicate} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final BiPredicate fromBiPredicate(ThrowingBiPredicate predicate) { + return new CheckedBiPredicate(predicate); + } + private final class CheckedBiPredicate implements BiPredicate { + private final ThrowingBiPredicate predicate; + CheckedBiPredicate(ThrowingBiPredicate predicate) { + this.predicate = predicate; + } + @Override + public boolean test(T t, U u) { + try { + return predicate.test(t, u); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingFunction}. + *

+ * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingFunction(Exceptions.sneak().function(t -> my_throwing_lambda))} + * + * @param + * see {@link Function} + * @param + * see {@link Function} + * @param function + * the {@link ThrowingFunction} to be converted, usually a lambda + * @return converted {@link Function} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final Function function(ThrowingFunction function) { + return new CheckedFunction(function); + } + private final class CheckedFunction implements Function { + private final ThrowingFunction function; + CheckedFunction(ThrowingFunction function) { + this.function = function; + } + @Override + public R apply(T t) { + try { + return function.apply(t); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingToIntFunction}. + *

+ * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingToIntFunction(Exceptions.sneak().fromToIntFunction(v -> my_throwing_lambda))} + * + * @param + * see {@link ToIntFunction} + * @param function + * the {@link ThrowingToIntFunction} to be converted, usually a lambda + * @return converted {@link ToIntFunction} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final ToIntFunction fromToIntFunction(ThrowingToIntFunction function) { + return new CheckedToIntFunction(function); + } + private final class CheckedToIntFunction implements ToIntFunction { + private final ThrowingToIntFunction function; + CheckedToIntFunction(ThrowingToIntFunction function) { + this.function = function; + } + @Override + public int applyAsInt(T value) { + try { + return function.applyAsInt(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingIntFunction}. + *

+ * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingIntFunction(Exceptions.sneak().fromIntFunction(v -> my_throwing_lambda))} + * + * @param + * see {@link IntFunction} + * @param function + * the {@link ThrowingIntFunction} to be converted, usually a lambda + * @return converted {@link IntFunction} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final IntFunction fromIntFunction(ThrowingIntFunction function) { + return new CheckedIntFunction(function); + } + private final class CheckedIntFunction implements IntFunction { + private final ThrowingIntFunction function; + CheckedIntFunction(ThrowingIntFunction function) { + this.function = function; + } + @Override + public R apply(int value) { + try { + return function.apply(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingIntToLongFunction}. + *

+ * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingIntToLongFunction(Exceptions.sneak().fromIntToLongFunction(v -> my_throwing_lambda))} + * + * @param function + * the {@link ThrowingIntToLongFunction} to be converted, usually a lambda + * @return converted {@link IntToLongFunction} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final IntToLongFunction fromIntToLongFunction(ThrowingIntToLongFunction function) { + return new CheckedIntToLongFunction(function); + } + private final class CheckedIntToLongFunction implements IntToLongFunction { + private final ThrowingIntToLongFunction function; + CheckedIntToLongFunction(ThrowingIntToLongFunction function) { + this.function = function; + } + @Override + public long applyAsLong(int value) { + try { + return function.applyAsLong(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingIntToDoubleFunction}. + *

+ * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingIntToDoubleFunction(Exceptions.sneak().fromIntToDoubleFunction(v -> my_throwing_lambda))} + * + * @param function + * the {@link ThrowingIntToDoubleFunction} to be converted, usually a lambda + * @return converted {@link IntToDoubleFunction} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final IntToDoubleFunction fromIntToDoubleFunction(ThrowingIntToDoubleFunction function) { + return new CheckedIntToDoubleFunction(function); + } + private final class CheckedIntToDoubleFunction implements IntToDoubleFunction { + private final ThrowingIntToDoubleFunction function; + CheckedIntToDoubleFunction(ThrowingIntToDoubleFunction function) { + this.function = function; + } + @Override + public double applyAsDouble(int value) { + try { + return function.applyAsDouble(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingToLongFunction}. + *

+ * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingToLongFunction(Exceptions.sneak().fromToLongFunction(v -> my_throwing_lambda))} + * + * @param + * see {@link ToLongFunction} + * @param function + * the {@link ThrowingToLongFunction} to be converted, usually a lambda + * @return converted {@link ToLongFunction} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final ToLongFunction fromToLongFunction(ThrowingToLongFunction function) { + return new CheckedToLongFunction(function); + } + private final class CheckedToLongFunction implements ToLongFunction { + private final ThrowingToLongFunction function; + CheckedToLongFunction(ThrowingToLongFunction function) { + this.function = function; + } + @Override + public long applyAsLong(T value) { + try { + return function.applyAsLong(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingLongFunction}. + *

+ * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingLongFunction(Exceptions.sneak().fromLongFunction(v -> my_throwing_lambda))} + * + * @param + * see {@link LongFunction} + * @param function + * the {@link ThrowingLongFunction} to be converted, usually a lambda + * @return converted {@link LongFunction} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final LongFunction fromLongFunction(ThrowingLongFunction function) { + return new CheckedLongFunction(function); + } + private final class CheckedLongFunction implements LongFunction { + private final ThrowingLongFunction function; + CheckedLongFunction(ThrowingLongFunction function) { + this.function = function; + } + @Override + public R apply(long value) { + try { + return function.apply(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingLongToIntFunction}. + *

+ * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingLongToIntFunction(Exceptions.sneak().fromLongToIntFunction(v -> my_throwing_lambda))} + * + * @param function + * the {@link ThrowingLongToIntFunction} to be converted, usually a lambda + * @return converted {@link LongToIntFunction} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final LongToIntFunction fromLongToIntFunction(ThrowingLongToIntFunction function) { + return new CheckedLongToIntFunction(function); + } + private final class CheckedLongToIntFunction implements LongToIntFunction { + private final ThrowingLongToIntFunction function; + CheckedLongToIntFunction(ThrowingLongToIntFunction function) { + this.function = function; + } + @Override + public int applyAsInt(long value) { + try { + return function.applyAsInt(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingLongToDoubleFunction}. + *

+ * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingLongToDoubleFunction(Exceptions.sneak().fromLongToDoubleFunction(v -> my_throwing_lambda))} + * + * @param function + * the {@link ThrowingLongToDoubleFunction} to be converted, usually a lambda + * @return converted {@link LongToDoubleFunction} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final LongToDoubleFunction fromLongToDoubleFunction(ThrowingLongToDoubleFunction function) { + return new CheckedLongToDoubleFunction(function); + } + private final class CheckedLongToDoubleFunction implements LongToDoubleFunction { + private final ThrowingLongToDoubleFunction function; + CheckedLongToDoubleFunction(ThrowingLongToDoubleFunction function) { + this.function = function; + } + @Override + public double applyAsDouble(long value) { + try { + return function.applyAsDouble(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingToDoubleFunction}. + *

+ * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingToDoubleFunction(Exceptions.sneak().fromToDoubleFunction(v -> my_throwing_lambda))} + * + * @param + * see {@link ToDoubleFunction} + * @param function + * the {@link ThrowingToDoubleFunction} to be converted, usually a lambda + * @return converted {@link ToDoubleFunction} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final ToDoubleFunction fromToDoubleFunction(ThrowingToDoubleFunction function) { + return new CheckedToDoubleFunction(function); + } + private final class CheckedToDoubleFunction implements ToDoubleFunction { + private final ThrowingToDoubleFunction function; + CheckedToDoubleFunction(ThrowingToDoubleFunction function) { + this.function = function; + } + @Override + public double applyAsDouble(T value) { + try { + return function.applyAsDouble(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingDoubleFunction}. + *

+ * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingDoubleFunction(Exceptions.sneak().fromDoubleFunction(v -> my_throwing_lambda))} + * + * @param + * see {@link DoubleFunction} + * @param function + * the {@link ThrowingDoubleFunction} to be converted, usually a lambda + * @return converted {@link DoubleFunction} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final DoubleFunction fromDoubleFunction(ThrowingDoubleFunction function) { + return new CheckedDoubleFunction(function); + } + private final class CheckedDoubleFunction implements DoubleFunction { + private final ThrowingDoubleFunction function; + CheckedDoubleFunction(ThrowingDoubleFunction function) { + this.function = function; + } + @Override + public R apply(double value) { + try { + return function.apply(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingDoubleToIntFunction}. + *

+ * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingDoubleToIntFunction(Exceptions.sneak().fromDoubleToIntFunction(v -> my_throwing_lambda))} + * + * @param function + * the {@link ThrowingDoubleToIntFunction} to be converted, usually a lambda + * @return converted {@link DoubleToIntFunction} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final DoubleToIntFunction fromDoubleToIntFunction(ThrowingDoubleToIntFunction function) { + return new CheckedDoubleToIntFunction(function); + } + private final class CheckedDoubleToIntFunction implements DoubleToIntFunction { + private final ThrowingDoubleToIntFunction function; + CheckedDoubleToIntFunction(ThrowingDoubleToIntFunction function) { + this.function = function; + } + @Override + public int applyAsInt(double value) { + try { + return function.applyAsInt(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingDoubleToLongFunction}. + *

+ * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingDoubleToLongFunction(Exceptions.sneak().fromDoubleToLongFunction(v -> my_throwing_lambda))} + * + * @param function + * the {@link ThrowingDoubleToLongFunction} to be converted, usually a lambda + * @return converted {@link DoubleToLongFunction} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final DoubleToLongFunction fromDoubleToLongFunction(ThrowingDoubleToLongFunction function) { + return new CheckedDoubleToLongFunction(function); + } + private final class CheckedDoubleToLongFunction implements DoubleToLongFunction { + private final ThrowingDoubleToLongFunction function; + CheckedDoubleToLongFunction(ThrowingDoubleToLongFunction function) { + this.function = function; + } + @Override + public long applyAsLong(double value) { + try { + return function.applyAsLong(value); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingUnaryOperator}. + *

+ * If {@code operator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code operator} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingUnaryOperator(Exceptions.sneak().fromUnaryOperator(o -> my_throwing_lambda))} + * + * @param + * see {@link UnaryOperator} + * @param operator + * the {@link ThrowingUnaryOperator} to be converted, usually a lambda + * @return converted {@link UnaryOperator} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final UnaryOperator fromUnaryOperator(ThrowingUnaryOperator operator) { + return new CheckedUnaryOperator(operator); + } + private final class CheckedUnaryOperator implements UnaryOperator { + private final ThrowingUnaryOperator operator; + CheckedUnaryOperator(ThrowingUnaryOperator operator) { + this.operator = operator; + } + @Override + public T apply(T operand) { + try { + return operator.apply(operand); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingIntUnaryOperator}. + *

+ * If {@code operator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code operator} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingIntUnaryOperator(Exceptions.sneak().fromIntUnaryOperator(o -> my_throwing_lambda))} + * + * @param operator + * the {@link ThrowingIntUnaryOperator} to be converted, usually a lambda + * @return converted {@link IntUnaryOperator} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final IntUnaryOperator fromIntUnaryOperator(ThrowingIntUnaryOperator operator) { + return new CheckedIntUnaryOperator(operator); + } + private final class CheckedIntUnaryOperator implements IntUnaryOperator { + private final ThrowingIntUnaryOperator operator; + CheckedIntUnaryOperator(ThrowingIntUnaryOperator operator) { + this.operator = operator; + } + @Override + public int applyAsInt(int operand) { + try { + return operator.applyAsInt(operand); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingLongUnaryOperator}. + *

+ * If {@code operator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code operator} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingLongUnaryOperator(Exceptions.sneak().fromLongUnaryOperator(o -> my_throwing_lambda))} + * + * @param operator + * the {@link ThrowingLongUnaryOperator} to be converted, usually a lambda + * @return converted {@link LongUnaryOperator} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final LongUnaryOperator fromLongUnaryOperator(ThrowingLongUnaryOperator operator) { + return new CheckedLongUnaryOperator(operator); + } + private final class CheckedLongUnaryOperator implements LongUnaryOperator { + private final ThrowingLongUnaryOperator operator; + CheckedLongUnaryOperator(ThrowingLongUnaryOperator operator) { + this.operator = operator; + } + @Override + public long applyAsLong(long operand) { + try { + return operator.applyAsLong(operand); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingDoubleUnaryOperator}. + *

+ * If {@code operator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code operator} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingDoubleUnaryOperator(Exceptions.sneak().fromDoubleUnaryOperator(o -> my_throwing_lambda))} + * + * @param operator + * the {@link ThrowingDoubleUnaryOperator} to be converted, usually a lambda + * @return converted {@link DoubleUnaryOperator} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final DoubleUnaryOperator fromDoubleUnaryOperator(ThrowingDoubleUnaryOperator operator) { + return new CheckedDoubleUnaryOperator(operator); + } + private final class CheckedDoubleUnaryOperator implements DoubleUnaryOperator { + private final ThrowingDoubleUnaryOperator operator; + CheckedDoubleUnaryOperator(ThrowingDoubleUnaryOperator operator) { + this.operator = operator; + } + @Override + public double applyAsDouble(double operand) { + try { + return operator.applyAsDouble(operand); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingBiFunction}. + *

+ * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingBiFunction(Exceptions.sneak().fromBiFunction((t, u) -> my_throwing_lambda))} + * + * @param + * see {@link BiFunction} + * @param + * see {@link BiFunction} + * @param + * see {@link BiFunction} + * @param function + * the {@link ThrowingBiFunction} to be converted, usually a lambda + * @return converted {@link BiFunction} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final BiFunction fromBiFunction(ThrowingBiFunction function) { + return new CheckedBiFunction(function); + } + private final class CheckedBiFunction implements BiFunction { + private final ThrowingBiFunction function; + CheckedBiFunction(ThrowingBiFunction function) { + this.function = function; + } + @Override + public R apply(T t, U u) { + try { + return function.apply(t, u); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingToIntBiFunction}. + *

+ * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingToIntBiFunction(Exceptions.sneak().fromToIntBiFunction((t, u) -> my_throwing_lambda))} + * + * @param + * see {@link ToIntBiFunction} + * @param + * see {@link ToIntBiFunction} + * @param function + * the {@link ThrowingToIntBiFunction} to be converted, usually a lambda + * @return converted {@link ToIntBiFunction} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final ToIntBiFunction fromToIntBiFunction(ThrowingToIntBiFunction function) { + return new CheckedToIntBiFunction(function); + } + private final class CheckedToIntBiFunction implements ToIntBiFunction { + private final ThrowingToIntBiFunction function; + CheckedToIntBiFunction(ThrowingToIntBiFunction function) { + this.function = function; + } + @Override + public int applyAsInt(T t, U u) { + try { + return function.applyAsInt(t, u); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingToLongBiFunction}. + *

+ * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingToLongBiFunction(Exceptions.sneak().fromToLongBiFunction((t, u) -> my_throwing_lambda))} + * + * @param + * see {@link ToLongBiFunction} + * @param + * see {@link ToLongBiFunction} + * @param function + * the {@link ThrowingToLongBiFunction} to be converted, usually a lambda + * @return converted {@link ToLongBiFunction} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final ToLongBiFunction fromToLongBiFunction(ThrowingToLongBiFunction function) { + return new CheckedToLongBiFunction(function); + } + private final class CheckedToLongBiFunction implements ToLongBiFunction { + private final ThrowingToLongBiFunction function; + CheckedToLongBiFunction(ThrowingToLongBiFunction function) { + this.function = function; + } + @Override + public long applyAsLong(T t, U u) { + try { + return function.applyAsLong(t, u); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingToDoubleBiFunction}. + *

+ * If {@code function} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code function} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingToDoubleBiFunction(Exceptions.sneak().fromToDoubleBiFunction((t, u) -> my_throwing_lambda))} + * + * @param + * see {@link ToDoubleBiFunction} + * @param + * see {@link ToDoubleBiFunction} + * @param function + * the {@link ThrowingToDoubleBiFunction} to be converted, usually a lambda + * @return converted {@link ToDoubleBiFunction} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final ToDoubleBiFunction fromToDoubleBiFunction(ThrowingToDoubleBiFunction function) { + return new CheckedToDoubleBiFunction(function); + } + private final class CheckedToDoubleBiFunction implements ToDoubleBiFunction { + private final ThrowingToDoubleBiFunction function; + CheckedToDoubleBiFunction(ThrowingToDoubleBiFunction function) { + this.function = function; + } + @Override + public double applyAsDouble(T t, U u) { + try { + return function.applyAsDouble(t, u); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingBinaryOperator}. + *

+ * If {@code operator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code operator} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingBinaryOperator(Exceptions.sneak().fromBinaryOperator((l, r) -> my_throwing_lambda))} + * + * @param + * see {@link BinaryOperator} + * @param operator + * the {@link ThrowingBinaryOperator} to be converted, usually a lambda + * @return converted {@link BinaryOperator} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final BinaryOperator fromBinaryOperator(ThrowingBinaryOperator operator) { + return new CheckedBinaryOperator(operator); + } + private final class CheckedBinaryOperator implements BinaryOperator { + private final ThrowingBinaryOperator operator; + CheckedBinaryOperator(ThrowingBinaryOperator operator) { + this.operator = operator; + } + @Override + public T apply(T left, T right) { + try { + return operator.apply(left, right); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingIntBinaryOperator}. + *

+ * If {@code operator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code operator} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingIntBinaryOperator(Exceptions.sneak().fromIntBinaryOperator((l, r) -> my_throwing_lambda))} + * + * @param operator + * the {@link ThrowingIntBinaryOperator} to be converted, usually a lambda + * @return converted {@link IntBinaryOperator} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final IntBinaryOperator fromIntBinaryOperator(ThrowingIntBinaryOperator operator) { + return new CheckedIntBinaryOperator(operator); + } + private final class CheckedIntBinaryOperator implements IntBinaryOperator { + private final ThrowingIntBinaryOperator operator; + CheckedIntBinaryOperator(ThrowingIntBinaryOperator operator) { + this.operator = operator; + } + @Override + public int applyAsInt(int left, int right) { + try { + return operator.applyAsInt(left, right); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingLongBinaryOperator}. + *

+ * If {@code operator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code operator} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingLongBinaryOperator(Exceptions.sneak().fromLongBinaryOperator((l, r) -> my_throwing_lambda))} + * + * @param operator + * the {@link ThrowingLongBinaryOperator} to be converted, usually a lambda + * @return converted {@link LongBinaryOperator} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final LongBinaryOperator fromLongBinaryOperator(ThrowingLongBinaryOperator operator) { + return new CheckedLongBinaryOperator(operator); + } + private final class CheckedLongBinaryOperator implements LongBinaryOperator { + private final ThrowingLongBinaryOperator operator; + CheckedLongBinaryOperator(ThrowingLongBinaryOperator operator) { + this.operator = operator; + } + @Override + public long applyAsLong(long left, long right) { + try { + return operator.applyAsLong(left, right); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingDoubleBinaryOperator}. + *

+ * If {@code operator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code operator} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingDoubleBinaryOperator(Exceptions.sneak().fromDoubleBinaryOperator((l, r) -> my_throwing_lambda))} + * + * @param operator + * the {@link ThrowingDoubleBinaryOperator} to be converted, usually a lambda + * @return converted {@link DoubleBinaryOperator} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final DoubleBinaryOperator fromDoubleBinaryOperator(ThrowingDoubleBinaryOperator operator) { + return new CheckedDoubleBinaryOperator(operator); + } + private final class CheckedDoubleBinaryOperator implements DoubleBinaryOperator { + private final ThrowingDoubleBinaryOperator operator; + CheckedDoubleBinaryOperator(ThrowingDoubleBinaryOperator operator) { + this.operator = operator; + } + @Override + public double applyAsDouble(double left, double right) { + try { + return operator.applyAsDouble(left, right); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link ThrowingComparator}. + *

+ * If {@code comparator} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code comparator} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code methodTakingComparator(Exceptions.sneak().comparator((l, r) -> my_throwing_lambda))} + * + * @param + * see {@link Comparator} + * @param comparator + * the {@link ThrowingComparator} to be converted, usually a lambda + * @return converted {@link Comparator} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final Comparator comparator(ThrowingComparator comparator) { + return new CheckedComparator(comparator); + } + private final class CheckedComparator implements Comparator { + private final ThrowingComparator comparator; + CheckedComparator(ThrowingComparator comparator) { + this.comparator = comparator; + } + @Override + public int compare(T left, T right) { + try { + return comparator.compare(left, right); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Removes checked exceptions from method signature of {@link AutoCloseable}. + *

+ * If {@code closeable} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + * Null {@code closeable} is silently wrapped and causes {@link NullPointerException} when executed. + *

+ * Typical usage: {@code try (var scope = Exceptions.sneak().closeable(openSomething()))} + * + * @param closeable + * the {@link AutoCloseable} to be converted + * @return converted {@link CloseableScope} free of checked exceptions + * @see Tutorial + * @see Exceptions + */ + public final CloseableScope closeable(AutoCloseable closeable) { + return new CheckedCloseableScope(closeable); + } + private final class CheckedCloseableScope implements CloseableScope { + private final AutoCloseable closeable; + CheckedCloseableScope(AutoCloseable closeable) { + this.closeable = closeable; + } + @Override + public void close() { + try { + closeable.close(); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + } + /** + * Filters out checked exceptions while running {@link ThrowingRunnable}. + *

+ * If {@code runnable} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + *

+ * Typical usage: {@code Exceptions.sneak().run(() -> my_throwing_lambda))} + * + * @param runnable + * the {@link ThrowingRunnable} to run, usually a lambda + * @throws NullPointerException + * if {@code runnable} is {@code null} + * @see Tutorial + * @see Exceptions + */ + public final void run(ThrowingRunnable runnable) { + try { + runnable.run(); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + /** + * Filters out checked exceptions while running {@link ThrowingSupplier}. + *

+ * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + *

+ * Typical usage: {@code Exceptions.sneak().get(() -> my_throwing_lambda))} + * + * @param + * see {@link Supplier} + * @param supplier + * the {@link ThrowingSupplier} to run, usually a lambda + * @return value returned from {@code supplier} + * @throws NullPointerException + * if {@code supplier} is {@code null} + * @see Tutorial + * @see Exceptions + */ + public final T get(ThrowingSupplier supplier) { + try { + return supplier.get(); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + /** + * Filters out checked exceptions while running {@link ThrowingIntSupplier}. + *

+ * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + *

+ * Typical usage: {@code Exceptions.sneak().getAsInt(() -> my_throwing_lambda))} + * + * @param supplier + * the {@link ThrowingIntSupplier} to run, usually a lambda + * @return value returned from {@code supplier} + * @throws NullPointerException + * if {@code supplier} is {@code null} + * @see Tutorial + * @see Exceptions + */ + public final int getAsInt(ThrowingIntSupplier supplier) { + try { + return supplier.getAsInt(); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + /** + * Filters out checked exceptions while running {@link ThrowingLongSupplier}. + *

+ * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + *

+ * Typical usage: {@code Exceptions.sneak().getAsLong(() -> my_throwing_lambda))} + * + * @param supplier + * the {@link ThrowingLongSupplier} to run, usually a lambda + * @return value returned from {@code supplier} + * @throws NullPointerException + * if {@code supplier} is {@code null} + * @see Tutorial + * @see Exceptions + */ + public final long getAsLong(ThrowingLongSupplier supplier) { + try { + return supplier.getAsLong(); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + /** + * Filters out checked exceptions while running {@link ThrowingDoubleSupplier}. + *

+ * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + *

+ * Typical usage: {@code Exceptions.sneak().getAsDouble(() -> my_throwing_lambda))} + * + * @param supplier + * the {@link ThrowingDoubleSupplier} to run, usually a lambda + * @return value returned from {@code supplier} + * @throws NullPointerException + * if {@code supplier} is {@code null} + * @see Tutorial + * @see Exceptions + */ + public final double getAsDouble(ThrowingDoubleSupplier supplier) { + try { + return supplier.getAsDouble(); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } + /** + * Filters out checked exceptions while running {@link ThrowingBooleanSupplier}. + *

+ * If {@code supplier} throws a checked exception, the exception is caught and passed to {@link #handle(Exception)}, + * which usually converts it to an unchecked exception, which is then thrown by this method. + *

+ * Typical usage: {@code Exceptions.sneak().getAsBoolean(() -> my_throwing_lambda))} + * + * @param supplier + * the {@link ThrowingBooleanSupplier} to run, usually a lambda + * @return value returned from {@code supplier} + * @throws NullPointerException + * if {@code supplier} is {@code null} + * @see Tutorial + * @see Exceptions + */ + public final boolean getAsBoolean(ThrowingBooleanSupplier supplier) { + try { + return supplier.getAsBoolean(); + } catch (RuntimeException exception) { + throw exception; + } catch (Exception exception) { + throw handle(exception); + } catch (Throwable exception) { + throw SneakingHandler.sneak(exception); + } + } } diff --git a/src/main/java/com/machinezoo/noexception/ExceptionFilter.java b/src/main/java/com/machinezoo/noexception/ExceptionFilter.java index ac204c6..310ed5a 100644 --- a/src/main/java/com/machinezoo/noexception/ExceptionFilter.java +++ b/src/main/java/com/machinezoo/noexception/ExceptionFilter.java @@ -34,1757 +34,1757 @@ * @see CheckedExceptionHandler */ public abstract class ExceptionFilter { - /** - * Handles exception in a generic way. This method must be defined in a derived class. - * One built-in implementation is provided by {@link ExceptionHandler#passing()}. - * All other methods of the {@code ExceptionFilter} call this method, but it can be also called directly. - *

- * This method represents reusable catch block that handles all exceptions in the same way. - * When invoked, it must somehow handle the provided exception, for example by logging it. - * It can also replace or wrap the exception by throwing a new exception. - * If this method returns without throwing, it is a signal that the original exception should be rethrown. - * All other methods of this class will rethrow in that case. - * - * @param exception - * the exception to handle - * @throws NullPointerException - * if {@code exception} is {@code null} - * @see Tutorial - * @see Exceptions - */ - public abstract void handle(Throwable exception); - /** - * Initializes new {@code ExceptionFilter}. - */ - protected ExceptionFilter() { - } - /** - * Applies exception filter to {@link Runnable}. - *

- * If {@code runnable} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code runnable} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingRunnable(ExceptionLogging.log().passing().runnable(() -> my_throwing_lambda))} - * - * @param runnable - * the {@link Runnable} to wrap, usually a lambda - * @return wrapper that runs {@link Runnable} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final Runnable runnable(Runnable runnable) { - return new FilteredRunnable(runnable); - } - private final class FilteredRunnable implements Runnable { - private final Runnable runnable; - FilteredRunnable(Runnable runnable) { - this.runnable = runnable; - } - @Override - public void run() { - try { - runnable.run(); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link Supplier}. - *

- * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingSupplier(ExceptionLogging.log().passing().supplier(() -> my_throwing_lambda))} - * - * @param - * see {@link Supplier} - * @param supplier - * the {@link Supplier} to wrap, usually a lambda - * @return wrapper that runs {@link Supplier} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final Supplier supplier(Supplier supplier) { - return new FilteredSupplier(supplier); - } - private final class FilteredSupplier implements Supplier { - private final Supplier supplier; - FilteredSupplier(Supplier supplier) { - this.supplier = supplier; - } - @Override - public T get() { - try { - return supplier.get(); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link IntSupplier}. - *

- * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingIntSupplier(ExceptionLogging.log().passing().fromIntSupplier(() -> my_throwing_lambda))} - * - * @param supplier - * the {@link IntSupplier} to wrap, usually a lambda - * @return wrapper that runs {@link IntSupplier} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final IntSupplier fromIntSupplier(IntSupplier supplier) { - return new FilteredIntSupplier(supplier); - } - private final class FilteredIntSupplier implements IntSupplier { - private final IntSupplier supplier; - FilteredIntSupplier(IntSupplier supplier) { - this.supplier = supplier; - } - @Override - public int getAsInt() { - try { - return supplier.getAsInt(); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link LongSupplier}. - *

- * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingLongSupplier(ExceptionLogging.log().passing().fromLongSupplier(() -> my_throwing_lambda))} - * - * @param supplier - * the {@link LongSupplier} to wrap, usually a lambda - * @return wrapper that runs {@link LongSupplier} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final LongSupplier fromLongSupplier(LongSupplier supplier) { - return new FilteredLongSupplier(supplier); - } - private final class FilteredLongSupplier implements LongSupplier { - private final LongSupplier supplier; - FilteredLongSupplier(LongSupplier supplier) { - this.supplier = supplier; - } - @Override - public long getAsLong() { - try { - return supplier.getAsLong(); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link DoubleSupplier}. - *

- * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingDoubleSupplier(ExceptionLogging.log().passing().fromDoubleSupplier(() -> my_throwing_lambda))} - * - * @param supplier - * the {@link DoubleSupplier} to wrap, usually a lambda - * @return wrapper that runs {@link DoubleSupplier} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final DoubleSupplier fromDoubleSupplier(DoubleSupplier supplier) { - return new FilteredDoubleSupplier(supplier); - } - private final class FilteredDoubleSupplier implements DoubleSupplier { - private final DoubleSupplier supplier; - FilteredDoubleSupplier(DoubleSupplier supplier) { - this.supplier = supplier; - } - @Override - public double getAsDouble() { - try { - return supplier.getAsDouble(); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link BooleanSupplier}. - *

- * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingBooleanSupplier(ExceptionLogging.log().passing().fromBooleanSupplier(() -> my_throwing_lambda))} - * - * @param supplier - * the {@link BooleanSupplier} to wrap, usually a lambda - * @return wrapper that runs {@link BooleanSupplier} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final BooleanSupplier fromBooleanSupplier(BooleanSupplier supplier) { - return new FilteredBooleanSupplier(supplier); - } - private final class FilteredBooleanSupplier implements BooleanSupplier { - private final BooleanSupplier supplier; - FilteredBooleanSupplier(BooleanSupplier supplier) { - this.supplier = supplier; - } - @Override - public boolean getAsBoolean() { - try { - return supplier.getAsBoolean(); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link Consumer}. - *

- * If {@code consumer} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code consumer} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingConsumer(ExceptionLogging.log().passing().consumer(t -> my_throwing_lambda))} - * - * @param - * see {@link Consumer} - * @param consumer - * the {@link Consumer} to wrap, usually a lambda - * @return wrapper that runs {@link Consumer} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final Consumer consumer(Consumer consumer) { - return new FilteredConsumer(consumer); - } - private final class FilteredConsumer implements Consumer { - private final Consumer consumer; - FilteredConsumer(Consumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(T t) { - try { - consumer.accept(t); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link IntConsumer}. - *

- * If {@code consumer} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code consumer} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingIntConsumer(ExceptionLogging.log().passing().fromIntConsumer(v -> my_throwing_lambda))} - * - * @param consumer - * the {@link IntConsumer} to wrap, usually a lambda - * @return wrapper that runs {@link IntConsumer} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final IntConsumer fromIntConsumer(IntConsumer consumer) { - return new FilteredIntConsumer(consumer); - } - private final class FilteredIntConsumer implements IntConsumer { - private final IntConsumer consumer; - FilteredIntConsumer(IntConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(int value) { - try { - consumer.accept(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link LongConsumer}. - *

- * If {@code consumer} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code consumer} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingLongConsumer(ExceptionLogging.log().passing().fromLongConsumer(v -> my_throwing_lambda))} - * - * @param consumer - * the {@link LongConsumer} to wrap, usually a lambda - * @return wrapper that runs {@link LongConsumer} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final LongConsumer fromLongConsumer(LongConsumer consumer) { - return new FilteredLongConsumer(consumer); - } - private final class FilteredLongConsumer implements LongConsumer { - private final LongConsumer consumer; - FilteredLongConsumer(LongConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(long value) { - try { - consumer.accept(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link DoubleConsumer}. - *

- * If {@code consumer} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code consumer} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingDoubleConsumer(ExceptionLogging.log().passing().fromDoubleConsumer(v -> my_throwing_lambda))} - * - * @param consumer - * the {@link DoubleConsumer} to wrap, usually a lambda - * @return wrapper that runs {@link DoubleConsumer} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final DoubleConsumer fromDoubleConsumer(DoubleConsumer consumer) { - return new FilteredDoubleConsumer(consumer); - } - private final class FilteredDoubleConsumer implements DoubleConsumer { - private final DoubleConsumer consumer; - FilteredDoubleConsumer(DoubleConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(double value) { - try { - consumer.accept(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link BiConsumer}. - *

- * If {@code consumer} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code consumer} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingBiConsumer(ExceptionLogging.log().passing().fromBiConsumer((t, u) -> my_throwing_lambda))} - * - * @param - * see {@link BiConsumer} - * @param - * see {@link BiConsumer} - * @param consumer - * the {@link BiConsumer} to wrap, usually a lambda - * @return wrapper that runs {@link BiConsumer} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final BiConsumer fromBiConsumer(BiConsumer consumer) { - return new FilteredBiConsumer(consumer); - } - private final class FilteredBiConsumer implements BiConsumer { - private final BiConsumer consumer; - FilteredBiConsumer(BiConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(T t, U u) { - try { - consumer.accept(t, u); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link ObjIntConsumer}. - *

- * If {@code consumer} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code consumer} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingObjIntConsumer(ExceptionLogging.log().passing().fromObjIntConsumer((t, v) -> my_throwing_lambda))} - * - * @param - * see {@link ObjIntConsumer} - * @param consumer - * the {@link ObjIntConsumer} to wrap, usually a lambda - * @return wrapper that runs {@link ObjIntConsumer} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final ObjIntConsumer fromObjIntConsumer(ObjIntConsumer consumer) { - return new FilteredObjIntConsumer(consumer); - } - private final class FilteredObjIntConsumer implements ObjIntConsumer { - private final ObjIntConsumer consumer; - FilteredObjIntConsumer(ObjIntConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(T t, int value) { - try { - consumer.accept(t, value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link ObjLongConsumer}. - *

- * If {@code consumer} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code consumer} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingObjLongConsumer(ExceptionLogging.log().passing().fromObjLongConsumer((t, v) -> my_throwing_lambda))} - * - * @param - * see {@link ObjLongConsumer} - * @param consumer - * the {@link ObjLongConsumer} to wrap, usually a lambda - * @return wrapper that runs {@link ObjLongConsumer} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final ObjLongConsumer fromObjLongConsumer(ObjLongConsumer consumer) { - return new FilteredObjLongConsumer(consumer); - } - private final class FilteredObjLongConsumer implements ObjLongConsumer { - private final ObjLongConsumer consumer; - FilteredObjLongConsumer(ObjLongConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(T t, long value) { - try { - consumer.accept(t, value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link ObjDoubleConsumer}. - *

- * If {@code consumer} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code consumer} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingObjDoubleConsumer(ExceptionLogging.log().passing().fromObjDoubleConsumer((t, v) -> my_throwing_lambda))} - * - * @param - * see {@link ObjDoubleConsumer} - * @param consumer - * the {@link ObjDoubleConsumer} to wrap, usually a lambda - * @return wrapper that runs {@link ObjDoubleConsumer} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final ObjDoubleConsumer fromObjDoubleConsumer(ObjDoubleConsumer consumer) { - return new FilteredObjDoubleConsumer(consumer); - } - private final class FilteredObjDoubleConsumer implements ObjDoubleConsumer { - private final ObjDoubleConsumer consumer; - FilteredObjDoubleConsumer(ObjDoubleConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(T t, double value) { - try { - consumer.accept(t, value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link Predicate}. - *

- * If {@code predicate} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code predicate} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingPredicate(ExceptionLogging.log().passing().predicate(t -> my_throwing_lambda))} - * - * @param - * see {@link Predicate} - * @param predicate - * the {@link Predicate} to wrap, usually a lambda - * @return wrapper that runs {@link Predicate} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final Predicate predicate(Predicate predicate) { - return new FilteredPredicate(predicate); - } - private final class FilteredPredicate implements Predicate { - private final Predicate predicate; - FilteredPredicate(Predicate predicate) { - this.predicate = predicate; - } - @Override - public boolean test(T t) { - try { - return predicate.test(t); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link IntPredicate}. - *

- * If {@code predicate} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code predicate} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingIntPredicate(ExceptionLogging.log().passing().fromIntPredicate(v -> my_throwing_lambda))} - * - * @param predicate - * the {@link IntPredicate} to wrap, usually a lambda - * @return wrapper that runs {@link IntPredicate} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final IntPredicate fromIntPredicate(IntPredicate predicate) { - return new FilteredIntPredicate(predicate); - } - private final class FilteredIntPredicate implements IntPredicate { - private final IntPredicate predicate; - FilteredIntPredicate(IntPredicate predicate) { - this.predicate = predicate; - } - @Override - public boolean test(int value) { - try { - return predicate.test(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link LongPredicate}. - *

- * If {@code predicate} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code predicate} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingLongPredicate(ExceptionLogging.log().passing().fromLongPredicate(v -> my_throwing_lambda))} - * - * @param predicate - * the {@link LongPredicate} to wrap, usually a lambda - * @return wrapper that runs {@link LongPredicate} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final LongPredicate fromLongPredicate(LongPredicate predicate) { - return new FilteredLongPredicate(predicate); - } - private final class FilteredLongPredicate implements LongPredicate { - private final LongPredicate predicate; - FilteredLongPredicate(LongPredicate predicate) { - this.predicate = predicate; - } - @Override - public boolean test(long value) { - try { - return predicate.test(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link DoublePredicate}. - *

- * If {@code predicate} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code predicate} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingDoublePredicate(ExceptionLogging.log().passing().fromDoublePredicate(v -> my_throwing_lambda))} - * - * @param predicate - * the {@link DoublePredicate} to wrap, usually a lambda - * @return wrapper that runs {@link DoublePredicate} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final DoublePredicate fromDoublePredicate(DoublePredicate predicate) { - return new FilteredDoublePredicate(predicate); - } - private final class FilteredDoublePredicate implements DoublePredicate { - private final DoublePredicate predicate; - FilteredDoublePredicate(DoublePredicate predicate) { - this.predicate = predicate; - } - @Override - public boolean test(double value) { - try { - return predicate.test(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link BiPredicate}. - *

- * If {@code predicate} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code predicate} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingBiPredicate(ExceptionLogging.log().passing().fromBiPredicate((t, u) -> my_throwing_lambda))} - * - * @param - * see {@link BiPredicate} - * @param - * see {@link BiPredicate} - * @param predicate - * the {@link BiPredicate} to wrap, usually a lambda - * @return wrapper that runs {@link BiPredicate} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final BiPredicate fromBiPredicate(BiPredicate predicate) { - return new FilteredBiPredicate(predicate); - } - private final class FilteredBiPredicate implements BiPredicate { - private final BiPredicate predicate; - FilteredBiPredicate(BiPredicate predicate) { - this.predicate = predicate; - } - @Override - public boolean test(T t, U u) { - try { - return predicate.test(t, u); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link Function}. - *

- * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingFunction(ExceptionLogging.log().passing().function(t -> my_throwing_lambda))} - * - * @param - * see {@link Function} - * @param - * see {@link Function} - * @param function - * the {@link Function} to wrap, usually a lambda - * @return wrapper that runs {@link Function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final Function function(Function function) { - return new FilteredFunction(function); - } - private final class FilteredFunction implements Function { - private final Function function; - FilteredFunction(Function function) { - this.function = function; - } - @Override - public R apply(T t) { - try { - return function.apply(t); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link ToIntFunction}. - *

- * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingToIntFunction(ExceptionLogging.log().passing().fromToIntFunction(v -> my_throwing_lambda))} - * - * @param - * see {@link ToIntFunction} - * @param function - * the {@link ToIntFunction} to wrap, usually a lambda - * @return wrapper that runs {@link ToIntFunction} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final ToIntFunction fromToIntFunction(ToIntFunction function) { - return new FilteredToIntFunction(function); - } - private final class FilteredToIntFunction implements ToIntFunction { - private final ToIntFunction function; - FilteredToIntFunction(ToIntFunction function) { - this.function = function; - } - @Override - public int applyAsInt(T value) { - try { - return function.applyAsInt(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link IntFunction}. - *

- * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingIntFunction(ExceptionLogging.log().passing().fromIntFunction(v -> my_throwing_lambda))} - * - * @param - * see {@link IntFunction} - * @param function - * the {@link IntFunction} to wrap, usually a lambda - * @return wrapper that runs {@link IntFunction} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final IntFunction fromIntFunction(IntFunction function) { - return new FilteredIntFunction(function); - } - private final class FilteredIntFunction implements IntFunction { - private final IntFunction function; - FilteredIntFunction(IntFunction function) { - this.function = function; - } - @Override - public R apply(int value) { - try { - return function.apply(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link IntToLongFunction}. - *

- * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingIntToLongFunction(ExceptionLogging.log().passing().fromIntToLongFunction(v -> my_throwing_lambda))} - * - * @param function - * the {@link IntToLongFunction} to wrap, usually a lambda - * @return wrapper that runs {@link IntToLongFunction} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final IntToLongFunction fromIntToLongFunction(IntToLongFunction function) { - return new FilteredIntToLongFunction(function); - } - private final class FilteredIntToLongFunction implements IntToLongFunction { - private final IntToLongFunction function; - FilteredIntToLongFunction(IntToLongFunction function) { - this.function = function; - } - @Override - public long applyAsLong(int value) { - try { - return function.applyAsLong(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link IntToDoubleFunction}. - *

- * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingIntToDoubleFunction(ExceptionLogging.log().passing().fromIntToDoubleFunction(v -> my_throwing_lambda))} - * - * @param function - * the {@link IntToDoubleFunction} to wrap, usually a lambda - * @return wrapper that runs {@link IntToDoubleFunction} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final IntToDoubleFunction fromIntToDoubleFunction(IntToDoubleFunction function) { - return new FilteredIntToDoubleFunction(function); - } - private final class FilteredIntToDoubleFunction implements IntToDoubleFunction { - private final IntToDoubleFunction function; - FilteredIntToDoubleFunction(IntToDoubleFunction function) { - this.function = function; - } - @Override - public double applyAsDouble(int value) { - try { - return function.applyAsDouble(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link ToLongFunction}. - *

- * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingToLongFunction(ExceptionLogging.log().passing().fromToLongFunction(v -> my_throwing_lambda))} - * - * @param - * see {@link ToLongFunction} - * @param function - * the {@link ToLongFunction} to wrap, usually a lambda - * @return wrapper that runs {@link ToLongFunction} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final ToLongFunction fromToLongFunction(ToLongFunction function) { - return new FilteredToLongFunction(function); - } - private final class FilteredToLongFunction implements ToLongFunction { - private final ToLongFunction function; - FilteredToLongFunction(ToLongFunction function) { - this.function = function; - } - @Override - public long applyAsLong(T value) { - try { - return function.applyAsLong(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link LongFunction}. - *

- * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingLongFunction(ExceptionLogging.log().passing().fromLongFunction(v -> my_throwing_lambda))} - * - * @param - * see {@link LongFunction} - * @param function - * the {@link LongFunction} to wrap, usually a lambda - * @return wrapper that runs {@link LongFunction} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final LongFunction fromLongFunction(LongFunction function) { - return new FilteredLongFunction(function); - } - private final class FilteredLongFunction implements LongFunction { - private final LongFunction function; - FilteredLongFunction(LongFunction function) { - this.function = function; - } - @Override - public R apply(long value) { - try { - return function.apply(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link LongToIntFunction}. - *

- * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingLongToIntFunction(ExceptionLogging.log().passing().fromLongToIntFunction(v -> my_throwing_lambda))} - * - * @param function - * the {@link LongToIntFunction} to wrap, usually a lambda - * @return wrapper that runs {@link LongToIntFunction} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final LongToIntFunction fromLongToIntFunction(LongToIntFunction function) { - return new FilteredLongToIntFunction(function); - } - private final class FilteredLongToIntFunction implements LongToIntFunction { - private final LongToIntFunction function; - FilteredLongToIntFunction(LongToIntFunction function) { - this.function = function; - } - @Override - public int applyAsInt(long value) { - try { - return function.applyAsInt(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link LongToDoubleFunction}. - *

- * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingLongToDoubleFunction(ExceptionLogging.log().passing().fromLongToDoubleFunction(v -> my_throwing_lambda))} - * - * @param function - * the {@link LongToDoubleFunction} to wrap, usually a lambda - * @return wrapper that runs {@link LongToDoubleFunction} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final LongToDoubleFunction fromLongToDoubleFunction(LongToDoubleFunction function) { - return new FilteredLongToDoubleFunction(function); - } - private final class FilteredLongToDoubleFunction implements LongToDoubleFunction { - private final LongToDoubleFunction function; - FilteredLongToDoubleFunction(LongToDoubleFunction function) { - this.function = function; - } - @Override - public double applyAsDouble(long value) { - try { - return function.applyAsDouble(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link ToDoubleFunction}. - *

- * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingToDoubleFunction(ExceptionLogging.log().passing().fromToDoubleFunction(v -> my_throwing_lambda))} - * - * @param - * see {@link ToDoubleFunction} - * @param function - * the {@link ToDoubleFunction} to wrap, usually a lambda - * @return wrapper that runs {@link ToDoubleFunction} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final ToDoubleFunction fromToDoubleFunction(ToDoubleFunction function) { - return new FilteredToDoubleFunction(function); - } - private final class FilteredToDoubleFunction implements ToDoubleFunction { - private final ToDoubleFunction function; - FilteredToDoubleFunction(ToDoubleFunction function) { - this.function = function; - } - @Override - public double applyAsDouble(T value) { - try { - return function.applyAsDouble(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link DoubleFunction}. - *

- * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingDoubleFunction(ExceptionLogging.log().passing().fromDoubleFunction(v -> my_throwing_lambda))} - * - * @param - * see {@link DoubleFunction} - * @param function - * the {@link DoubleFunction} to wrap, usually a lambda - * @return wrapper that runs {@link DoubleFunction} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final DoubleFunction fromDoubleFunction(DoubleFunction function) { - return new FilteredDoubleFunction(function); - } - private final class FilteredDoubleFunction implements DoubleFunction { - private final DoubleFunction function; - FilteredDoubleFunction(DoubleFunction function) { - this.function = function; - } - @Override - public R apply(double value) { - try { - return function.apply(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link DoubleToIntFunction}. - *

- * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingDoubleToIntFunction(ExceptionLogging.log().passing().fromDoubleToIntFunction(v -> my_throwing_lambda))} - * - * @param function - * the {@link DoubleToIntFunction} to wrap, usually a lambda - * @return wrapper that runs {@link DoubleToIntFunction} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final DoubleToIntFunction fromDoubleToIntFunction(DoubleToIntFunction function) { - return new FilteredDoubleToIntFunction(function); - } - private final class FilteredDoubleToIntFunction implements DoubleToIntFunction { - private final DoubleToIntFunction function; - FilteredDoubleToIntFunction(DoubleToIntFunction function) { - this.function = function; - } - @Override - public int applyAsInt(double value) { - try { - return function.applyAsInt(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link DoubleToLongFunction}. - *

- * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingDoubleToLongFunction(ExceptionLogging.log().passing().fromDoubleToLongFunction(v -> my_throwing_lambda))} - * - * @param function - * the {@link DoubleToLongFunction} to wrap, usually a lambda - * @return wrapper that runs {@link DoubleToLongFunction} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final DoubleToLongFunction fromDoubleToLongFunction(DoubleToLongFunction function) { - return new FilteredDoubleToLongFunction(function); - } - private final class FilteredDoubleToLongFunction implements DoubleToLongFunction { - private final DoubleToLongFunction function; - FilteredDoubleToLongFunction(DoubleToLongFunction function) { - this.function = function; - } - @Override - public long applyAsLong(double value) { - try { - return function.applyAsLong(value); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link UnaryOperator}. - *

- * If {@code operator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code operator} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingUnaryOperator(ExceptionLogging.log().passing().fromUnaryOperator(o -> my_throwing_lambda))} - * - * @param - * see {@link UnaryOperator} - * @param operator - * the {@link UnaryOperator} to wrap, usually a lambda - * @return wrapper that runs {@link UnaryOperator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final UnaryOperator fromUnaryOperator(UnaryOperator operator) { - return new FilteredUnaryOperator(operator); - } - private final class FilteredUnaryOperator implements UnaryOperator { - private final UnaryOperator operator; - FilteredUnaryOperator(UnaryOperator operator) { - this.operator = operator; - } - @Override - public T apply(T operand) { - try { - return operator.apply(operand); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link IntUnaryOperator}. - *

- * If {@code operator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code operator} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingIntUnaryOperator(ExceptionLogging.log().passing().fromIntUnaryOperator(o -> my_throwing_lambda))} - * - * @param operator - * the {@link IntUnaryOperator} to wrap, usually a lambda - * @return wrapper that runs {@link IntUnaryOperator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final IntUnaryOperator fromIntUnaryOperator(IntUnaryOperator operator) { - return new FilteredIntUnaryOperator(operator); - } - private final class FilteredIntUnaryOperator implements IntUnaryOperator { - private final IntUnaryOperator operator; - FilteredIntUnaryOperator(IntUnaryOperator operator) { - this.operator = operator; - } - @Override - public int applyAsInt(int operand) { - try { - return operator.applyAsInt(operand); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link LongUnaryOperator}. - *

- * If {@code operator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code operator} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingLongUnaryOperator(ExceptionLogging.log().passing().fromLongUnaryOperator(o -> my_throwing_lambda))} - * - * @param operator - * the {@link LongUnaryOperator} to wrap, usually a lambda - * @return wrapper that runs {@link LongUnaryOperator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final LongUnaryOperator fromLongUnaryOperator(LongUnaryOperator operator) { - return new FilteredLongUnaryOperator(operator); - } - private final class FilteredLongUnaryOperator implements LongUnaryOperator { - private final LongUnaryOperator operator; - FilteredLongUnaryOperator(LongUnaryOperator operator) { - this.operator = operator; - } - @Override - public long applyAsLong(long operand) { - try { - return operator.applyAsLong(operand); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link DoubleUnaryOperator}. - *

- * If {@code operator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code operator} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingDoubleUnaryOperator(ExceptionLogging.log().passing().fromDoubleUnaryOperator(o -> my_throwing_lambda))} - * - * @param operator - * the {@link DoubleUnaryOperator} to wrap, usually a lambda - * @return wrapper that runs {@link DoubleUnaryOperator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final DoubleUnaryOperator fromDoubleUnaryOperator(DoubleUnaryOperator operator) { - return new FilteredDoubleUnaryOperator(operator); - } - private final class FilteredDoubleUnaryOperator implements DoubleUnaryOperator { - private final DoubleUnaryOperator operator; - FilteredDoubleUnaryOperator(DoubleUnaryOperator operator) { - this.operator = operator; - } - @Override - public double applyAsDouble(double operand) { - try { - return operator.applyAsDouble(operand); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link BiFunction}. - *

- * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingBiFunction(ExceptionLogging.log().passing().fromBiFunction((t, u) -> my_throwing_lambda))} - * - * @param - * see {@link BiFunction} - * @param - * see {@link BiFunction} - * @param - * see {@link BiFunction} - * @param function - * the {@link BiFunction} to wrap, usually a lambda - * @return wrapper that runs {@link BiFunction} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final BiFunction fromBiFunction(BiFunction function) { - return new FilteredBiFunction(function); - } - private final class FilteredBiFunction implements BiFunction { - private final BiFunction function; - FilteredBiFunction(BiFunction function) { - this.function = function; - } - @Override - public R apply(T t, U u) { - try { - return function.apply(t, u); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link ToIntBiFunction}. - *

- * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingToIntBiFunction(ExceptionLogging.log().passing().fromToIntBiFunction((t, u) -> my_throwing_lambda))} - * - * @param - * see {@link ToIntBiFunction} - * @param - * see {@link ToIntBiFunction} - * @param function - * the {@link ToIntBiFunction} to wrap, usually a lambda - * @return wrapper that runs {@link ToIntBiFunction} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final ToIntBiFunction fromToIntBiFunction(ToIntBiFunction function) { - return new FilteredToIntBiFunction(function); - } - private final class FilteredToIntBiFunction implements ToIntBiFunction { - private final ToIntBiFunction function; - FilteredToIntBiFunction(ToIntBiFunction function) { - this.function = function; - } - @Override - public int applyAsInt(T t, U u) { - try { - return function.applyAsInt(t, u); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link ToLongBiFunction}. - *

- * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingToLongBiFunction(ExceptionLogging.log().passing().fromToLongBiFunction((t, u) -> my_throwing_lambda))} - * - * @param - * see {@link ToLongBiFunction} - * @param - * see {@link ToLongBiFunction} - * @param function - * the {@link ToLongBiFunction} to wrap, usually a lambda - * @return wrapper that runs {@link ToLongBiFunction} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final ToLongBiFunction fromToLongBiFunction(ToLongBiFunction function) { - return new FilteredToLongBiFunction(function); - } - private final class FilteredToLongBiFunction implements ToLongBiFunction { - private final ToLongBiFunction function; - FilteredToLongBiFunction(ToLongBiFunction function) { - this.function = function; - } - @Override - public long applyAsLong(T t, U u) { - try { - return function.applyAsLong(t, u); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link ToDoubleBiFunction}. - *

- * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingToDoubleBiFunction(ExceptionLogging.log().passing().fromToDoubleBiFunction((t, u) -> my_throwing_lambda))} - * - * @param - * see {@link ToDoubleBiFunction} - * @param - * see {@link ToDoubleBiFunction} - * @param function - * the {@link ToDoubleBiFunction} to wrap, usually a lambda - * @return wrapper that runs {@link ToDoubleBiFunction} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final ToDoubleBiFunction fromToDoubleBiFunction(ToDoubleBiFunction function) { - return new FilteredToDoubleBiFunction(function); - } - private final class FilteredToDoubleBiFunction implements ToDoubleBiFunction { - private final ToDoubleBiFunction function; - FilteredToDoubleBiFunction(ToDoubleBiFunction function) { - this.function = function; - } - @Override - public double applyAsDouble(T t, U u) { - try { - return function.applyAsDouble(t, u); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link BinaryOperator}. - *

- * If {@code operator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code operator} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingBinaryOperator(ExceptionLogging.log().passing().fromBinaryOperator((l, r) -> my_throwing_lambda))} - * - * @param - * see {@link BinaryOperator} - * @param operator - * the {@link BinaryOperator} to wrap, usually a lambda - * @return wrapper that runs {@link BinaryOperator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final BinaryOperator fromBinaryOperator(BinaryOperator operator) { - return new FilteredBinaryOperator(operator); - } - private final class FilteredBinaryOperator implements BinaryOperator { - private final BinaryOperator operator; - FilteredBinaryOperator(BinaryOperator operator) { - this.operator = operator; - } - @Override - public T apply(T left, T right) { - try { - return operator.apply(left, right); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link IntBinaryOperator}. - *

- * If {@code operator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code operator} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingIntBinaryOperator(ExceptionLogging.log().passing().fromIntBinaryOperator((l, r) -> my_throwing_lambda))} - * - * @param operator - * the {@link IntBinaryOperator} to wrap, usually a lambda - * @return wrapper that runs {@link IntBinaryOperator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final IntBinaryOperator fromIntBinaryOperator(IntBinaryOperator operator) { - return new FilteredIntBinaryOperator(operator); - } - private final class FilteredIntBinaryOperator implements IntBinaryOperator { - private final IntBinaryOperator operator; - FilteredIntBinaryOperator(IntBinaryOperator operator) { - this.operator = operator; - } - @Override - public int applyAsInt(int left, int right) { - try { - return operator.applyAsInt(left, right); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link LongBinaryOperator}. - *

- * If {@code operator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code operator} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingLongBinaryOperator(ExceptionLogging.log().passing().fromLongBinaryOperator((l, r) -> my_throwing_lambda))} - * - * @param operator - * the {@link LongBinaryOperator} to wrap, usually a lambda - * @return wrapper that runs {@link LongBinaryOperator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final LongBinaryOperator fromLongBinaryOperator(LongBinaryOperator operator) { - return new FilteredLongBinaryOperator(operator); - } - private final class FilteredLongBinaryOperator implements LongBinaryOperator { - private final LongBinaryOperator operator; - FilteredLongBinaryOperator(LongBinaryOperator operator) { - this.operator = operator; - } - @Override - public long applyAsLong(long left, long right) { - try { - return operator.applyAsLong(left, right); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link DoubleBinaryOperator}. - *

- * If {@code operator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code operator} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingDoubleBinaryOperator(ExceptionLogging.log().passing().fromDoubleBinaryOperator((l, r) -> my_throwing_lambda))} - * - * @param operator - * the {@link DoubleBinaryOperator} to wrap, usually a lambda - * @return wrapper that runs {@link DoubleBinaryOperator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final DoubleBinaryOperator fromDoubleBinaryOperator(DoubleBinaryOperator operator) { - return new FilteredDoubleBinaryOperator(operator); - } - private final class FilteredDoubleBinaryOperator implements DoubleBinaryOperator { - private final DoubleBinaryOperator operator; - FilteredDoubleBinaryOperator(DoubleBinaryOperator operator) { - this.operator = operator; - } - @Override - public double applyAsDouble(double left, double right) { - try { - return operator.applyAsDouble(left, right); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link Comparator}. - *

- * If {@code comparator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code comparator} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code methodTakingComparator(ExceptionLogging.log().passing().comparator((l, r) -> my_throwing_lambda))} - * - * @param - * see {@link Comparator} - * @param comparator - * the {@link Comparator} to wrap, usually a lambda - * @return wrapper that runs {@link Comparator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final Comparator comparator(Comparator comparator) { - return new FilteredComparator(comparator); - } - private final class FilteredComparator implements Comparator { - private final Comparator comparator; - FilteredComparator(Comparator comparator) { - this.comparator = comparator; - } - @Override - public int compare(T left, T right) { - try { - return comparator.compare(left, right); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Applies exception filter to {@link CloseableScope}. - *

- * If {@code closeable} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code closeable} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code try (var scope = ExceptionLogging.log().passing().closeable(openSomething()))} - * - * @param closeable - * the {@link CloseableScope} to wrap - * @return wrapper that runs {@link CloseableScope} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final CloseableScope closeable(CloseableScope closeable) { - return new FilteredCloseableScope(closeable); - } - private final class FilteredCloseableScope implements CloseableScope { - private final CloseableScope closeable; - FilteredCloseableScope(CloseableScope closeable) { - this.closeable = closeable; - } - @Override - public void close() { - try { - closeable.close(); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - } - /** - * Filters exceptions while running {@link Runnable}. - *

- * If {@code runnable} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code runnable} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code ExceptionLogging.log().passing().run(() -> my_throwing_lambda))} - * - * @param runnable - * the {@link Runnable} to run, usually a lambda - * @throws NullPointerException - * if {@code runnable} is {@code null} - * @see Tutorial - * @see Exceptions - */ - public final void run(Runnable runnable) { - try { - runnable.run(); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - /** - * Filters exceptions while running {@link Supplier}. - *

- * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code ExceptionLogging.log().passing().get(() -> my_throwing_lambda))} - * - * @param - * see {@link Supplier} - * @param supplier - * the {@link Supplier} to run, usually a lambda - * @return value returned from {@code supplier} - * @throws NullPointerException - * if {@code supplier} is {@code null} - * @see Tutorial - * @see Exceptions - */ - public final T get(Supplier supplier) { - try { - return supplier.get(); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - /** - * Filters exceptions while running {@link IntSupplier}. - *

- * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code ExceptionLogging.log().passing().getAsInt(() -> my_throwing_lambda))} - * - * @param supplier - * the {@link IntSupplier} to run, usually a lambda - * @return value returned from {@code supplier} - * @throws NullPointerException - * if {@code supplier} is {@code null} - * @see Tutorial - * @see Exceptions - */ - public final int getAsInt(IntSupplier supplier) { - try { - return supplier.getAsInt(); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - /** - * Filters exceptions while running {@link LongSupplier}. - *

- * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code ExceptionLogging.log().passing().getAsLong(() -> my_throwing_lambda))} - * - * @param supplier - * the {@link LongSupplier} to run, usually a lambda - * @return value returned from {@code supplier} - * @throws NullPointerException - * if {@code supplier} is {@code null} - * @see Tutorial - * @see Exceptions - */ - public final long getAsLong(LongSupplier supplier) { - try { - return supplier.getAsLong(); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - /** - * Filters exceptions while running {@link DoubleSupplier}. - *

- * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code ExceptionLogging.log().passing().getAsDouble(() -> my_throwing_lambda))} - * - * @param supplier - * the {@link DoubleSupplier} to run, usually a lambda - * @return value returned from {@code supplier} - * @throws NullPointerException - * if {@code supplier} is {@code null} - * @see Tutorial - * @see Exceptions - */ - public final double getAsDouble(DoubleSupplier supplier) { - try { - return supplier.getAsDouble(); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } - /** - * Filters exceptions while running {@link BooleanSupplier}. - *

- * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. - *

- * Typical usage: {@code ExceptionLogging.log().passing().getAsBoolean(() -> my_throwing_lambda))} - * - * @param supplier - * the {@link BooleanSupplier} to run, usually a lambda - * @return value returned from {@code supplier} - * @throws NullPointerException - * if {@code supplier} is {@code null} - * @see Tutorial - * @see Exceptions - */ - public final boolean getAsBoolean(BooleanSupplier supplier) { - try { - return supplier.getAsBoolean(); - } catch (Throwable exception) { - handle(exception); - throw exception; - } - } + /** + * Handles exception in a generic way. This method must be defined in a derived class. + * One built-in implementation is provided by {@link ExceptionHandler#passing()}. + * All other methods of the {@code ExceptionFilter} call this method, but it can be also called directly. + *

+ * This method represents reusable catch block that handles all exceptions in the same way. + * When invoked, it must somehow handle the provided exception, for example by logging it. + * It can also replace or wrap the exception by throwing a new exception. + * If this method returns without throwing, it is a signal that the original exception should be rethrown. + * All other methods of this class will rethrow in that case. + * + * @param exception + * the exception to handle + * @throws NullPointerException + * if {@code exception} is {@code null} + * @see Tutorial + * @see Exceptions + */ + public abstract void handle(Throwable exception); + /** + * Initializes new {@code ExceptionFilter}. + */ + protected ExceptionFilter() { + } + /** + * Applies exception filter to {@link Runnable}. + *

+ * If {@code runnable} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code runnable} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingRunnable(ExceptionLogging.log().passing().runnable(() -> my_throwing_lambda))} + * + * @param runnable + * the {@link Runnable} to wrap, usually a lambda + * @return wrapper that runs {@link Runnable} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final Runnable runnable(Runnable runnable) { + return new FilteredRunnable(runnable); + } + private final class FilteredRunnable implements Runnable { + private final Runnable runnable; + FilteredRunnable(Runnable runnable) { + this.runnable = runnable; + } + @Override + public void run() { + try { + runnable.run(); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link Supplier}. + *

+ * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingSupplier(ExceptionLogging.log().passing().supplier(() -> my_throwing_lambda))} + * + * @param + * see {@link Supplier} + * @param supplier + * the {@link Supplier} to wrap, usually a lambda + * @return wrapper that runs {@link Supplier} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final Supplier supplier(Supplier supplier) { + return new FilteredSupplier(supplier); + } + private final class FilteredSupplier implements Supplier { + private final Supplier supplier; + FilteredSupplier(Supplier supplier) { + this.supplier = supplier; + } + @Override + public T get() { + try { + return supplier.get(); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link IntSupplier}. + *

+ * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingIntSupplier(ExceptionLogging.log().passing().fromIntSupplier(() -> my_throwing_lambda))} + * + * @param supplier + * the {@link IntSupplier} to wrap, usually a lambda + * @return wrapper that runs {@link IntSupplier} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final IntSupplier fromIntSupplier(IntSupplier supplier) { + return new FilteredIntSupplier(supplier); + } + private final class FilteredIntSupplier implements IntSupplier { + private final IntSupplier supplier; + FilteredIntSupplier(IntSupplier supplier) { + this.supplier = supplier; + } + @Override + public int getAsInt() { + try { + return supplier.getAsInt(); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link LongSupplier}. + *

+ * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingLongSupplier(ExceptionLogging.log().passing().fromLongSupplier(() -> my_throwing_lambda))} + * + * @param supplier + * the {@link LongSupplier} to wrap, usually a lambda + * @return wrapper that runs {@link LongSupplier} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final LongSupplier fromLongSupplier(LongSupplier supplier) { + return new FilteredLongSupplier(supplier); + } + private final class FilteredLongSupplier implements LongSupplier { + private final LongSupplier supplier; + FilteredLongSupplier(LongSupplier supplier) { + this.supplier = supplier; + } + @Override + public long getAsLong() { + try { + return supplier.getAsLong(); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link DoubleSupplier}. + *

+ * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingDoubleSupplier(ExceptionLogging.log().passing().fromDoubleSupplier(() -> my_throwing_lambda))} + * + * @param supplier + * the {@link DoubleSupplier} to wrap, usually a lambda + * @return wrapper that runs {@link DoubleSupplier} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final DoubleSupplier fromDoubleSupplier(DoubleSupplier supplier) { + return new FilteredDoubleSupplier(supplier); + } + private final class FilteredDoubleSupplier implements DoubleSupplier { + private final DoubleSupplier supplier; + FilteredDoubleSupplier(DoubleSupplier supplier) { + this.supplier = supplier; + } + @Override + public double getAsDouble() { + try { + return supplier.getAsDouble(); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link BooleanSupplier}. + *

+ * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingBooleanSupplier(ExceptionLogging.log().passing().fromBooleanSupplier(() -> my_throwing_lambda))} + * + * @param supplier + * the {@link BooleanSupplier} to wrap, usually a lambda + * @return wrapper that runs {@link BooleanSupplier} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final BooleanSupplier fromBooleanSupplier(BooleanSupplier supplier) { + return new FilteredBooleanSupplier(supplier); + } + private final class FilteredBooleanSupplier implements BooleanSupplier { + private final BooleanSupplier supplier; + FilteredBooleanSupplier(BooleanSupplier supplier) { + this.supplier = supplier; + } + @Override + public boolean getAsBoolean() { + try { + return supplier.getAsBoolean(); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link Consumer}. + *

+ * If {@code consumer} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code consumer} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingConsumer(ExceptionLogging.log().passing().consumer(t -> my_throwing_lambda))} + * + * @param + * see {@link Consumer} + * @param consumer + * the {@link Consumer} to wrap, usually a lambda + * @return wrapper that runs {@link Consumer} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final Consumer consumer(Consumer consumer) { + return new FilteredConsumer(consumer); + } + private final class FilteredConsumer implements Consumer { + private final Consumer consumer; + FilteredConsumer(Consumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(T t) { + try { + consumer.accept(t); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link IntConsumer}. + *

+ * If {@code consumer} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code consumer} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingIntConsumer(ExceptionLogging.log().passing().fromIntConsumer(v -> my_throwing_lambda))} + * + * @param consumer + * the {@link IntConsumer} to wrap, usually a lambda + * @return wrapper that runs {@link IntConsumer} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final IntConsumer fromIntConsumer(IntConsumer consumer) { + return new FilteredIntConsumer(consumer); + } + private final class FilteredIntConsumer implements IntConsumer { + private final IntConsumer consumer; + FilteredIntConsumer(IntConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(int value) { + try { + consumer.accept(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link LongConsumer}. + *

+ * If {@code consumer} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code consumer} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingLongConsumer(ExceptionLogging.log().passing().fromLongConsumer(v -> my_throwing_lambda))} + * + * @param consumer + * the {@link LongConsumer} to wrap, usually a lambda + * @return wrapper that runs {@link LongConsumer} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final LongConsumer fromLongConsumer(LongConsumer consumer) { + return new FilteredLongConsumer(consumer); + } + private final class FilteredLongConsumer implements LongConsumer { + private final LongConsumer consumer; + FilteredLongConsumer(LongConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(long value) { + try { + consumer.accept(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link DoubleConsumer}. + *

+ * If {@code consumer} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code consumer} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingDoubleConsumer(ExceptionLogging.log().passing().fromDoubleConsumer(v -> my_throwing_lambda))} + * + * @param consumer + * the {@link DoubleConsumer} to wrap, usually a lambda + * @return wrapper that runs {@link DoubleConsumer} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final DoubleConsumer fromDoubleConsumer(DoubleConsumer consumer) { + return new FilteredDoubleConsumer(consumer); + } + private final class FilteredDoubleConsumer implements DoubleConsumer { + private final DoubleConsumer consumer; + FilteredDoubleConsumer(DoubleConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(double value) { + try { + consumer.accept(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link BiConsumer}. + *

+ * If {@code consumer} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code consumer} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingBiConsumer(ExceptionLogging.log().passing().fromBiConsumer((t, u) -> my_throwing_lambda))} + * + * @param + * see {@link BiConsumer} + * @param + * see {@link BiConsumer} + * @param consumer + * the {@link BiConsumer} to wrap, usually a lambda + * @return wrapper that runs {@link BiConsumer} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final BiConsumer fromBiConsumer(BiConsumer consumer) { + return new FilteredBiConsumer(consumer); + } + private final class FilteredBiConsumer implements BiConsumer { + private final BiConsumer consumer; + FilteredBiConsumer(BiConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(T t, U u) { + try { + consumer.accept(t, u); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link ObjIntConsumer}. + *

+ * If {@code consumer} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code consumer} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingObjIntConsumer(ExceptionLogging.log().passing().fromObjIntConsumer((t, v) -> my_throwing_lambda))} + * + * @param + * see {@link ObjIntConsumer} + * @param consumer + * the {@link ObjIntConsumer} to wrap, usually a lambda + * @return wrapper that runs {@link ObjIntConsumer} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final ObjIntConsumer fromObjIntConsumer(ObjIntConsumer consumer) { + return new FilteredObjIntConsumer(consumer); + } + private final class FilteredObjIntConsumer implements ObjIntConsumer { + private final ObjIntConsumer consumer; + FilteredObjIntConsumer(ObjIntConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(T t, int value) { + try { + consumer.accept(t, value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link ObjLongConsumer}. + *

+ * If {@code consumer} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code consumer} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingObjLongConsumer(ExceptionLogging.log().passing().fromObjLongConsumer((t, v) -> my_throwing_lambda))} + * + * @param + * see {@link ObjLongConsumer} + * @param consumer + * the {@link ObjLongConsumer} to wrap, usually a lambda + * @return wrapper that runs {@link ObjLongConsumer} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final ObjLongConsumer fromObjLongConsumer(ObjLongConsumer consumer) { + return new FilteredObjLongConsumer(consumer); + } + private final class FilteredObjLongConsumer implements ObjLongConsumer { + private final ObjLongConsumer consumer; + FilteredObjLongConsumer(ObjLongConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(T t, long value) { + try { + consumer.accept(t, value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link ObjDoubleConsumer}. + *

+ * If {@code consumer} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code consumer} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingObjDoubleConsumer(ExceptionLogging.log().passing().fromObjDoubleConsumer((t, v) -> my_throwing_lambda))} + * + * @param + * see {@link ObjDoubleConsumer} + * @param consumer + * the {@link ObjDoubleConsumer} to wrap, usually a lambda + * @return wrapper that runs {@link ObjDoubleConsumer} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final ObjDoubleConsumer fromObjDoubleConsumer(ObjDoubleConsumer consumer) { + return new FilteredObjDoubleConsumer(consumer); + } + private final class FilteredObjDoubleConsumer implements ObjDoubleConsumer { + private final ObjDoubleConsumer consumer; + FilteredObjDoubleConsumer(ObjDoubleConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(T t, double value) { + try { + consumer.accept(t, value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link Predicate}. + *

+ * If {@code predicate} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code predicate} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingPredicate(ExceptionLogging.log().passing().predicate(t -> my_throwing_lambda))} + * + * @param + * see {@link Predicate} + * @param predicate + * the {@link Predicate} to wrap, usually a lambda + * @return wrapper that runs {@link Predicate} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final Predicate predicate(Predicate predicate) { + return new FilteredPredicate(predicate); + } + private final class FilteredPredicate implements Predicate { + private final Predicate predicate; + FilteredPredicate(Predicate predicate) { + this.predicate = predicate; + } + @Override + public boolean test(T t) { + try { + return predicate.test(t); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link IntPredicate}. + *

+ * If {@code predicate} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code predicate} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingIntPredicate(ExceptionLogging.log().passing().fromIntPredicate(v -> my_throwing_lambda))} + * + * @param predicate + * the {@link IntPredicate} to wrap, usually a lambda + * @return wrapper that runs {@link IntPredicate} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final IntPredicate fromIntPredicate(IntPredicate predicate) { + return new FilteredIntPredicate(predicate); + } + private final class FilteredIntPredicate implements IntPredicate { + private final IntPredicate predicate; + FilteredIntPredicate(IntPredicate predicate) { + this.predicate = predicate; + } + @Override + public boolean test(int value) { + try { + return predicate.test(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link LongPredicate}. + *

+ * If {@code predicate} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code predicate} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingLongPredicate(ExceptionLogging.log().passing().fromLongPredicate(v -> my_throwing_lambda))} + * + * @param predicate + * the {@link LongPredicate} to wrap, usually a lambda + * @return wrapper that runs {@link LongPredicate} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final LongPredicate fromLongPredicate(LongPredicate predicate) { + return new FilteredLongPredicate(predicate); + } + private final class FilteredLongPredicate implements LongPredicate { + private final LongPredicate predicate; + FilteredLongPredicate(LongPredicate predicate) { + this.predicate = predicate; + } + @Override + public boolean test(long value) { + try { + return predicate.test(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link DoublePredicate}. + *

+ * If {@code predicate} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code predicate} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingDoublePredicate(ExceptionLogging.log().passing().fromDoublePredicate(v -> my_throwing_lambda))} + * + * @param predicate + * the {@link DoublePredicate} to wrap, usually a lambda + * @return wrapper that runs {@link DoublePredicate} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final DoublePredicate fromDoublePredicate(DoublePredicate predicate) { + return new FilteredDoublePredicate(predicate); + } + private final class FilteredDoublePredicate implements DoublePredicate { + private final DoublePredicate predicate; + FilteredDoublePredicate(DoublePredicate predicate) { + this.predicate = predicate; + } + @Override + public boolean test(double value) { + try { + return predicate.test(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link BiPredicate}. + *

+ * If {@code predicate} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code predicate} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingBiPredicate(ExceptionLogging.log().passing().fromBiPredicate((t, u) -> my_throwing_lambda))} + * + * @param + * see {@link BiPredicate} + * @param + * see {@link BiPredicate} + * @param predicate + * the {@link BiPredicate} to wrap, usually a lambda + * @return wrapper that runs {@link BiPredicate} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final BiPredicate fromBiPredicate(BiPredicate predicate) { + return new FilteredBiPredicate(predicate); + } + private final class FilteredBiPredicate implements BiPredicate { + private final BiPredicate predicate; + FilteredBiPredicate(BiPredicate predicate) { + this.predicate = predicate; + } + @Override + public boolean test(T t, U u) { + try { + return predicate.test(t, u); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link Function}. + *

+ * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingFunction(ExceptionLogging.log().passing().function(t -> my_throwing_lambda))} + * + * @param + * see {@link Function} + * @param + * see {@link Function} + * @param function + * the {@link Function} to wrap, usually a lambda + * @return wrapper that runs {@link Function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final Function function(Function function) { + return new FilteredFunction(function); + } + private final class FilteredFunction implements Function { + private final Function function; + FilteredFunction(Function function) { + this.function = function; + } + @Override + public R apply(T t) { + try { + return function.apply(t); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link ToIntFunction}. + *

+ * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingToIntFunction(ExceptionLogging.log().passing().fromToIntFunction(v -> my_throwing_lambda))} + * + * @param + * see {@link ToIntFunction} + * @param function + * the {@link ToIntFunction} to wrap, usually a lambda + * @return wrapper that runs {@link ToIntFunction} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final ToIntFunction fromToIntFunction(ToIntFunction function) { + return new FilteredToIntFunction(function); + } + private final class FilteredToIntFunction implements ToIntFunction { + private final ToIntFunction function; + FilteredToIntFunction(ToIntFunction function) { + this.function = function; + } + @Override + public int applyAsInt(T value) { + try { + return function.applyAsInt(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link IntFunction}. + *

+ * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingIntFunction(ExceptionLogging.log().passing().fromIntFunction(v -> my_throwing_lambda))} + * + * @param + * see {@link IntFunction} + * @param function + * the {@link IntFunction} to wrap, usually a lambda + * @return wrapper that runs {@link IntFunction} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final IntFunction fromIntFunction(IntFunction function) { + return new FilteredIntFunction(function); + } + private final class FilteredIntFunction implements IntFunction { + private final IntFunction function; + FilteredIntFunction(IntFunction function) { + this.function = function; + } + @Override + public R apply(int value) { + try { + return function.apply(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link IntToLongFunction}. + *

+ * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingIntToLongFunction(ExceptionLogging.log().passing().fromIntToLongFunction(v -> my_throwing_lambda))} + * + * @param function + * the {@link IntToLongFunction} to wrap, usually a lambda + * @return wrapper that runs {@link IntToLongFunction} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final IntToLongFunction fromIntToLongFunction(IntToLongFunction function) { + return new FilteredIntToLongFunction(function); + } + private final class FilteredIntToLongFunction implements IntToLongFunction { + private final IntToLongFunction function; + FilteredIntToLongFunction(IntToLongFunction function) { + this.function = function; + } + @Override + public long applyAsLong(int value) { + try { + return function.applyAsLong(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link IntToDoubleFunction}. + *

+ * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingIntToDoubleFunction(ExceptionLogging.log().passing().fromIntToDoubleFunction(v -> my_throwing_lambda))} + * + * @param function + * the {@link IntToDoubleFunction} to wrap, usually a lambda + * @return wrapper that runs {@link IntToDoubleFunction} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final IntToDoubleFunction fromIntToDoubleFunction(IntToDoubleFunction function) { + return new FilteredIntToDoubleFunction(function); + } + private final class FilteredIntToDoubleFunction implements IntToDoubleFunction { + private final IntToDoubleFunction function; + FilteredIntToDoubleFunction(IntToDoubleFunction function) { + this.function = function; + } + @Override + public double applyAsDouble(int value) { + try { + return function.applyAsDouble(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link ToLongFunction}. + *

+ * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingToLongFunction(ExceptionLogging.log().passing().fromToLongFunction(v -> my_throwing_lambda))} + * + * @param + * see {@link ToLongFunction} + * @param function + * the {@link ToLongFunction} to wrap, usually a lambda + * @return wrapper that runs {@link ToLongFunction} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final ToLongFunction fromToLongFunction(ToLongFunction function) { + return new FilteredToLongFunction(function); + } + private final class FilteredToLongFunction implements ToLongFunction { + private final ToLongFunction function; + FilteredToLongFunction(ToLongFunction function) { + this.function = function; + } + @Override + public long applyAsLong(T value) { + try { + return function.applyAsLong(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link LongFunction}. + *

+ * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingLongFunction(ExceptionLogging.log().passing().fromLongFunction(v -> my_throwing_lambda))} + * + * @param + * see {@link LongFunction} + * @param function + * the {@link LongFunction} to wrap, usually a lambda + * @return wrapper that runs {@link LongFunction} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final LongFunction fromLongFunction(LongFunction function) { + return new FilteredLongFunction(function); + } + private final class FilteredLongFunction implements LongFunction { + private final LongFunction function; + FilteredLongFunction(LongFunction function) { + this.function = function; + } + @Override + public R apply(long value) { + try { + return function.apply(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link LongToIntFunction}. + *

+ * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingLongToIntFunction(ExceptionLogging.log().passing().fromLongToIntFunction(v -> my_throwing_lambda))} + * + * @param function + * the {@link LongToIntFunction} to wrap, usually a lambda + * @return wrapper that runs {@link LongToIntFunction} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final LongToIntFunction fromLongToIntFunction(LongToIntFunction function) { + return new FilteredLongToIntFunction(function); + } + private final class FilteredLongToIntFunction implements LongToIntFunction { + private final LongToIntFunction function; + FilteredLongToIntFunction(LongToIntFunction function) { + this.function = function; + } + @Override + public int applyAsInt(long value) { + try { + return function.applyAsInt(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link LongToDoubleFunction}. + *

+ * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingLongToDoubleFunction(ExceptionLogging.log().passing().fromLongToDoubleFunction(v -> my_throwing_lambda))} + * + * @param function + * the {@link LongToDoubleFunction} to wrap, usually a lambda + * @return wrapper that runs {@link LongToDoubleFunction} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final LongToDoubleFunction fromLongToDoubleFunction(LongToDoubleFunction function) { + return new FilteredLongToDoubleFunction(function); + } + private final class FilteredLongToDoubleFunction implements LongToDoubleFunction { + private final LongToDoubleFunction function; + FilteredLongToDoubleFunction(LongToDoubleFunction function) { + this.function = function; + } + @Override + public double applyAsDouble(long value) { + try { + return function.applyAsDouble(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link ToDoubleFunction}. + *

+ * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingToDoubleFunction(ExceptionLogging.log().passing().fromToDoubleFunction(v -> my_throwing_lambda))} + * + * @param + * see {@link ToDoubleFunction} + * @param function + * the {@link ToDoubleFunction} to wrap, usually a lambda + * @return wrapper that runs {@link ToDoubleFunction} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final ToDoubleFunction fromToDoubleFunction(ToDoubleFunction function) { + return new FilteredToDoubleFunction(function); + } + private final class FilteredToDoubleFunction implements ToDoubleFunction { + private final ToDoubleFunction function; + FilteredToDoubleFunction(ToDoubleFunction function) { + this.function = function; + } + @Override + public double applyAsDouble(T value) { + try { + return function.applyAsDouble(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link DoubleFunction}. + *

+ * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingDoubleFunction(ExceptionLogging.log().passing().fromDoubleFunction(v -> my_throwing_lambda))} + * + * @param + * see {@link DoubleFunction} + * @param function + * the {@link DoubleFunction} to wrap, usually a lambda + * @return wrapper that runs {@link DoubleFunction} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final DoubleFunction fromDoubleFunction(DoubleFunction function) { + return new FilteredDoubleFunction(function); + } + private final class FilteredDoubleFunction implements DoubleFunction { + private final DoubleFunction function; + FilteredDoubleFunction(DoubleFunction function) { + this.function = function; + } + @Override + public R apply(double value) { + try { + return function.apply(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link DoubleToIntFunction}. + *

+ * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingDoubleToIntFunction(ExceptionLogging.log().passing().fromDoubleToIntFunction(v -> my_throwing_lambda))} + * + * @param function + * the {@link DoubleToIntFunction} to wrap, usually a lambda + * @return wrapper that runs {@link DoubleToIntFunction} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final DoubleToIntFunction fromDoubleToIntFunction(DoubleToIntFunction function) { + return new FilteredDoubleToIntFunction(function); + } + private final class FilteredDoubleToIntFunction implements DoubleToIntFunction { + private final DoubleToIntFunction function; + FilteredDoubleToIntFunction(DoubleToIntFunction function) { + this.function = function; + } + @Override + public int applyAsInt(double value) { + try { + return function.applyAsInt(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link DoubleToLongFunction}. + *

+ * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingDoubleToLongFunction(ExceptionLogging.log().passing().fromDoubleToLongFunction(v -> my_throwing_lambda))} + * + * @param function + * the {@link DoubleToLongFunction} to wrap, usually a lambda + * @return wrapper that runs {@link DoubleToLongFunction} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final DoubleToLongFunction fromDoubleToLongFunction(DoubleToLongFunction function) { + return new FilteredDoubleToLongFunction(function); + } + private final class FilteredDoubleToLongFunction implements DoubleToLongFunction { + private final DoubleToLongFunction function; + FilteredDoubleToLongFunction(DoubleToLongFunction function) { + this.function = function; + } + @Override + public long applyAsLong(double value) { + try { + return function.applyAsLong(value); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link UnaryOperator}. + *

+ * If {@code operator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code operator} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingUnaryOperator(ExceptionLogging.log().passing().fromUnaryOperator(o -> my_throwing_lambda))} + * + * @param + * see {@link UnaryOperator} + * @param operator + * the {@link UnaryOperator} to wrap, usually a lambda + * @return wrapper that runs {@link UnaryOperator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final UnaryOperator fromUnaryOperator(UnaryOperator operator) { + return new FilteredUnaryOperator(operator); + } + private final class FilteredUnaryOperator implements UnaryOperator { + private final UnaryOperator operator; + FilteredUnaryOperator(UnaryOperator operator) { + this.operator = operator; + } + @Override + public T apply(T operand) { + try { + return operator.apply(operand); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link IntUnaryOperator}. + *

+ * If {@code operator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code operator} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingIntUnaryOperator(ExceptionLogging.log().passing().fromIntUnaryOperator(o -> my_throwing_lambda))} + * + * @param operator + * the {@link IntUnaryOperator} to wrap, usually a lambda + * @return wrapper that runs {@link IntUnaryOperator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final IntUnaryOperator fromIntUnaryOperator(IntUnaryOperator operator) { + return new FilteredIntUnaryOperator(operator); + } + private final class FilteredIntUnaryOperator implements IntUnaryOperator { + private final IntUnaryOperator operator; + FilteredIntUnaryOperator(IntUnaryOperator operator) { + this.operator = operator; + } + @Override + public int applyAsInt(int operand) { + try { + return operator.applyAsInt(operand); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link LongUnaryOperator}. + *

+ * If {@code operator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code operator} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingLongUnaryOperator(ExceptionLogging.log().passing().fromLongUnaryOperator(o -> my_throwing_lambda))} + * + * @param operator + * the {@link LongUnaryOperator} to wrap, usually a lambda + * @return wrapper that runs {@link LongUnaryOperator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final LongUnaryOperator fromLongUnaryOperator(LongUnaryOperator operator) { + return new FilteredLongUnaryOperator(operator); + } + private final class FilteredLongUnaryOperator implements LongUnaryOperator { + private final LongUnaryOperator operator; + FilteredLongUnaryOperator(LongUnaryOperator operator) { + this.operator = operator; + } + @Override + public long applyAsLong(long operand) { + try { + return operator.applyAsLong(operand); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link DoubleUnaryOperator}. + *

+ * If {@code operator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code operator} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingDoubleUnaryOperator(ExceptionLogging.log().passing().fromDoubleUnaryOperator(o -> my_throwing_lambda))} + * + * @param operator + * the {@link DoubleUnaryOperator} to wrap, usually a lambda + * @return wrapper that runs {@link DoubleUnaryOperator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final DoubleUnaryOperator fromDoubleUnaryOperator(DoubleUnaryOperator operator) { + return new FilteredDoubleUnaryOperator(operator); + } + private final class FilteredDoubleUnaryOperator implements DoubleUnaryOperator { + private final DoubleUnaryOperator operator; + FilteredDoubleUnaryOperator(DoubleUnaryOperator operator) { + this.operator = operator; + } + @Override + public double applyAsDouble(double operand) { + try { + return operator.applyAsDouble(operand); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link BiFunction}. + *

+ * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingBiFunction(ExceptionLogging.log().passing().fromBiFunction((t, u) -> my_throwing_lambda))} + * + * @param + * see {@link BiFunction} + * @param + * see {@link BiFunction} + * @param + * see {@link BiFunction} + * @param function + * the {@link BiFunction} to wrap, usually a lambda + * @return wrapper that runs {@link BiFunction} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final BiFunction fromBiFunction(BiFunction function) { + return new FilteredBiFunction(function); + } + private final class FilteredBiFunction implements BiFunction { + private final BiFunction function; + FilteredBiFunction(BiFunction function) { + this.function = function; + } + @Override + public R apply(T t, U u) { + try { + return function.apply(t, u); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link ToIntBiFunction}. + *

+ * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingToIntBiFunction(ExceptionLogging.log().passing().fromToIntBiFunction((t, u) -> my_throwing_lambda))} + * + * @param + * see {@link ToIntBiFunction} + * @param + * see {@link ToIntBiFunction} + * @param function + * the {@link ToIntBiFunction} to wrap, usually a lambda + * @return wrapper that runs {@link ToIntBiFunction} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final ToIntBiFunction fromToIntBiFunction(ToIntBiFunction function) { + return new FilteredToIntBiFunction(function); + } + private final class FilteredToIntBiFunction implements ToIntBiFunction { + private final ToIntBiFunction function; + FilteredToIntBiFunction(ToIntBiFunction function) { + this.function = function; + } + @Override + public int applyAsInt(T t, U u) { + try { + return function.applyAsInt(t, u); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link ToLongBiFunction}. + *

+ * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingToLongBiFunction(ExceptionLogging.log().passing().fromToLongBiFunction((t, u) -> my_throwing_lambda))} + * + * @param + * see {@link ToLongBiFunction} + * @param + * see {@link ToLongBiFunction} + * @param function + * the {@link ToLongBiFunction} to wrap, usually a lambda + * @return wrapper that runs {@link ToLongBiFunction} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final ToLongBiFunction fromToLongBiFunction(ToLongBiFunction function) { + return new FilteredToLongBiFunction(function); + } + private final class FilteredToLongBiFunction implements ToLongBiFunction { + private final ToLongBiFunction function; + FilteredToLongBiFunction(ToLongBiFunction function) { + this.function = function; + } + @Override + public long applyAsLong(T t, U u) { + try { + return function.applyAsLong(t, u); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link ToDoubleBiFunction}. + *

+ * If {@code function} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingToDoubleBiFunction(ExceptionLogging.log().passing().fromToDoubleBiFunction((t, u) -> my_throwing_lambda))} + * + * @param + * see {@link ToDoubleBiFunction} + * @param + * see {@link ToDoubleBiFunction} + * @param function + * the {@link ToDoubleBiFunction} to wrap, usually a lambda + * @return wrapper that runs {@link ToDoubleBiFunction} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final ToDoubleBiFunction fromToDoubleBiFunction(ToDoubleBiFunction function) { + return new FilteredToDoubleBiFunction(function); + } + private final class FilteredToDoubleBiFunction implements ToDoubleBiFunction { + private final ToDoubleBiFunction function; + FilteredToDoubleBiFunction(ToDoubleBiFunction function) { + this.function = function; + } + @Override + public double applyAsDouble(T t, U u) { + try { + return function.applyAsDouble(t, u); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link BinaryOperator}. + *

+ * If {@code operator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code operator} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingBinaryOperator(ExceptionLogging.log().passing().fromBinaryOperator((l, r) -> my_throwing_lambda))} + * + * @param + * see {@link BinaryOperator} + * @param operator + * the {@link BinaryOperator} to wrap, usually a lambda + * @return wrapper that runs {@link BinaryOperator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final BinaryOperator fromBinaryOperator(BinaryOperator operator) { + return new FilteredBinaryOperator(operator); + } + private final class FilteredBinaryOperator implements BinaryOperator { + private final BinaryOperator operator; + FilteredBinaryOperator(BinaryOperator operator) { + this.operator = operator; + } + @Override + public T apply(T left, T right) { + try { + return operator.apply(left, right); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link IntBinaryOperator}. + *

+ * If {@code operator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code operator} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingIntBinaryOperator(ExceptionLogging.log().passing().fromIntBinaryOperator((l, r) -> my_throwing_lambda))} + * + * @param operator + * the {@link IntBinaryOperator} to wrap, usually a lambda + * @return wrapper that runs {@link IntBinaryOperator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final IntBinaryOperator fromIntBinaryOperator(IntBinaryOperator operator) { + return new FilteredIntBinaryOperator(operator); + } + private final class FilteredIntBinaryOperator implements IntBinaryOperator { + private final IntBinaryOperator operator; + FilteredIntBinaryOperator(IntBinaryOperator operator) { + this.operator = operator; + } + @Override + public int applyAsInt(int left, int right) { + try { + return operator.applyAsInt(left, right); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link LongBinaryOperator}. + *

+ * If {@code operator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code operator} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingLongBinaryOperator(ExceptionLogging.log().passing().fromLongBinaryOperator((l, r) -> my_throwing_lambda))} + * + * @param operator + * the {@link LongBinaryOperator} to wrap, usually a lambda + * @return wrapper that runs {@link LongBinaryOperator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final LongBinaryOperator fromLongBinaryOperator(LongBinaryOperator operator) { + return new FilteredLongBinaryOperator(operator); + } + private final class FilteredLongBinaryOperator implements LongBinaryOperator { + private final LongBinaryOperator operator; + FilteredLongBinaryOperator(LongBinaryOperator operator) { + this.operator = operator; + } + @Override + public long applyAsLong(long left, long right) { + try { + return operator.applyAsLong(left, right); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link DoubleBinaryOperator}. + *

+ * If {@code operator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code operator} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingDoubleBinaryOperator(ExceptionLogging.log().passing().fromDoubleBinaryOperator((l, r) -> my_throwing_lambda))} + * + * @param operator + * the {@link DoubleBinaryOperator} to wrap, usually a lambda + * @return wrapper that runs {@link DoubleBinaryOperator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final DoubleBinaryOperator fromDoubleBinaryOperator(DoubleBinaryOperator operator) { + return new FilteredDoubleBinaryOperator(operator); + } + private final class FilteredDoubleBinaryOperator implements DoubleBinaryOperator { + private final DoubleBinaryOperator operator; + FilteredDoubleBinaryOperator(DoubleBinaryOperator operator) { + this.operator = operator; + } + @Override + public double applyAsDouble(double left, double right) { + try { + return operator.applyAsDouble(left, right); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link Comparator}. + *

+ * If {@code comparator} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code comparator} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code methodTakingComparator(ExceptionLogging.log().passing().comparator((l, r) -> my_throwing_lambda))} + * + * @param + * see {@link Comparator} + * @param comparator + * the {@link Comparator} to wrap, usually a lambda + * @return wrapper that runs {@link Comparator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final Comparator comparator(Comparator comparator) { + return new FilteredComparator(comparator); + } + private final class FilteredComparator implements Comparator { + private final Comparator comparator; + FilteredComparator(Comparator comparator) { + this.comparator = comparator; + } + @Override + public int compare(T left, T right) { + try { + return comparator.compare(left, right); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Applies exception filter to {@link CloseableScope}. + *

+ * If {@code closeable} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code closeable} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code try (var scope = ExceptionLogging.log().passing().closeable(openSomething()))} + * + * @param closeable + * the {@link CloseableScope} to wrap + * @return wrapper that runs {@link CloseableScope} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final CloseableScope closeable(CloseableScope closeable) { + return new FilteredCloseableScope(closeable); + } + private final class FilteredCloseableScope implements CloseableScope { + private final CloseableScope closeable; + FilteredCloseableScope(CloseableScope closeable) { + this.closeable = closeable; + } + @Override + public void close() { + try { + closeable.close(); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + } + /** + * Filters exceptions while running {@link Runnable}. + *

+ * If {@code runnable} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code runnable} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code ExceptionLogging.log().passing().run(() -> my_throwing_lambda))} + * + * @param runnable + * the {@link Runnable} to run, usually a lambda + * @throws NullPointerException + * if {@code runnable} is {@code null} + * @see Tutorial + * @see Exceptions + */ + public final void run(Runnable runnable) { + try { + runnable.run(); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + /** + * Filters exceptions while running {@link Supplier}. + *

+ * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code ExceptionLogging.log().passing().get(() -> my_throwing_lambda))} + * + * @param + * see {@link Supplier} + * @param supplier + * the {@link Supplier} to run, usually a lambda + * @return value returned from {@code supplier} + * @throws NullPointerException + * if {@code supplier} is {@code null} + * @see Tutorial + * @see Exceptions + */ + public final T get(Supplier supplier) { + try { + return supplier.get(); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + /** + * Filters exceptions while running {@link IntSupplier}. + *

+ * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code ExceptionLogging.log().passing().getAsInt(() -> my_throwing_lambda))} + * + * @param supplier + * the {@link IntSupplier} to run, usually a lambda + * @return value returned from {@code supplier} + * @throws NullPointerException + * if {@code supplier} is {@code null} + * @see Tutorial + * @see Exceptions + */ + public final int getAsInt(IntSupplier supplier) { + try { + return supplier.getAsInt(); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + /** + * Filters exceptions while running {@link LongSupplier}. + *

+ * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code ExceptionLogging.log().passing().getAsLong(() -> my_throwing_lambda))} + * + * @param supplier + * the {@link LongSupplier} to run, usually a lambda + * @return value returned from {@code supplier} + * @throws NullPointerException + * if {@code supplier} is {@code null} + * @see Tutorial + * @see Exceptions + */ + public final long getAsLong(LongSupplier supplier) { + try { + return supplier.getAsLong(); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + /** + * Filters exceptions while running {@link DoubleSupplier}. + *

+ * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code ExceptionLogging.log().passing().getAsDouble(() -> my_throwing_lambda))} + * + * @param supplier + * the {@link DoubleSupplier} to run, usually a lambda + * @return value returned from {@code supplier} + * @throws NullPointerException + * if {@code supplier} is {@code null} + * @see Tutorial + * @see Exceptions + */ + public final double getAsDouble(DoubleSupplier supplier) { + try { + return supplier.getAsDouble(); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } + /** + * Filters exceptions while running {@link BooleanSupplier}. + *

+ * If {@code supplier} throws an exception, the exception is caught and passed to {@link #handle(Throwable)}. + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * Method {@link #handle(Throwable)} is free to throw any replacement exception. If it returns, the original exception is rethrown. + *

+ * Typical usage: {@code ExceptionLogging.log().passing().getAsBoolean(() -> my_throwing_lambda))} + * + * @param supplier + * the {@link BooleanSupplier} to run, usually a lambda + * @return value returned from {@code supplier} + * @throws NullPointerException + * if {@code supplier} is {@code null} + * @see Tutorial + * @see Exceptions + */ + public final boolean getAsBoolean(BooleanSupplier supplier) { + try { + return supplier.getAsBoolean(); + } catch (Throwable exception) { + handle(exception); + throw exception; + } + } } diff --git a/src/main/java/com/machinezoo/noexception/ExceptionHandler.java b/src/main/java/com/machinezoo/noexception/ExceptionHandler.java index 9c732d8..1ce285a 100644 --- a/src/main/java/com/machinezoo/noexception/ExceptionHandler.java +++ b/src/main/java/com/machinezoo/noexception/ExceptionHandler.java @@ -53,1859 +53,1859 @@ */ @ApiIssue("Add only/except(Predicate), which return handler that rethrows selected exceptions without passing them to handle().") public abstract class ExceptionHandler { - /** - * Handles exception in a generic way. This method must be defined in a derived class. - * Several implementations are provided by methods on {@link Exceptions} class. - * All other methods of the {@code ExceptionHandler} call this method, but it can be also called directly. - *

- * This method represents reusable catch block that handles all exceptions in the same way. - * When invoked, it must somehow handle the provided exception, for example by logging it. - *

- * This method does not have to handle all exceptions. - * It can indicate through return value whether it has accepted or rejected the exception. - * When an exception is rejected, caller of this method is expected to rethrow the exception. - * All other methods of this class fulfill this requirement. - * - * @param exception - * the exception to handle - * @return {@code true} when exception is handled, {@code false} if the exception should be rethrown - * @throws NullPointerException - * if {@code exception} is {@code null} - * @see Tutorial - * @see Exceptions - */ - public abstract boolean handle(Throwable exception); - /** - * Initialize new {@code ExceptionHandler}. - */ - protected ExceptionHandler() { - } - /** - * Adds a pass-through modifier to this exception handler. - * If this exception handler performs an action (like logging) and then stops exception propagation, - * this method will return {@link ExceptionFilter} that performs the same action but additionally rethrows the exception. - *

- * Reusable exception handlers can be defined once as {@code ExceptionHandler} instances - * and then transformed into {@link ExceptionFilter} by this method when needed. - *

- * If method {@link #handle(Throwable)} throws, the returned {@link ExceptionFilter} will pass through that exception. - * It only rethrows the original exception if {@link #handle(Throwable)} returns normally (regardless of return value). - *

- * Typical usage: {@code ExceptionLogging.log().passing().get(() -> my_throwing_lambda)} - * - * @return pass-through modification of this exception handler - */ - public ExceptionFilter passing() { - return new PassingFilter(this); - } - /** - * Wraps {@link Runnable} in a try-catch block. - *

- * If {@code runnable} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code runnable} is caught too. - * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().runnable(() -> my_throwing_lambda)} - * - * @param runnable - * the {@link Runnable} to wrap, usually a lambda - * @return wrapper that runs {@code runnable} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final Runnable runnable(Runnable runnable) { - return new CatchingRunnable(runnable); - } - private final class CatchingRunnable implements Runnable { - private final Runnable runnable; - CatchingRunnable(Runnable runnable) { - this.runnable = runnable; - } - @Override - public void run() { - try { - runnable.run(); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - } - } - } - /** - * Wraps {@link Supplier} in a try-catch block. - *

- * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * Wrapper then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().supplier(() -> my_throwing_lambda).orElse(fallback)} - * - * @param - * see {@link Supplier} - * @param supplier - * the {@link Supplier} to wrap, usually a lambda - * @return wrapper that runs {@code supplier} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalSupplier supplier(Supplier supplier) { - return new CatchingSupplier(supplier); - } - private final class CatchingSupplier implements OptionalSupplier { - private final Supplier supplier; - CatchingSupplier(Supplier supplier) { - this.supplier = supplier; - } - @Override - public Optional get() { - try { - return Optional.ofNullable(supplier.get()); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return Optional.empty(); - } - } - } - /** - * Wraps {@link IntSupplier} in a try-catch block. - *

- * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * Wrapper then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromIntSupplier(() -> my_throwing_lambda).orElse(fallback)} - * - * @param supplier - * the {@link IntSupplier} to wrap, usually a lambda - * @return wrapper that runs {@code supplier} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalIntSupplier fromIntSupplier(IntSupplier supplier) { - return new CatchingIntSupplier(supplier); - } - private final class CatchingIntSupplier implements OptionalIntSupplier { - private final IntSupplier supplier; - CatchingIntSupplier(IntSupplier supplier) { - this.supplier = supplier; - } - @Override - public OptionalInt get() { - try { - return OptionalInt.of(supplier.getAsInt()); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalInt.empty(); - } - } - } - /** - * Wraps {@link LongSupplier} in a try-catch block. - *

- * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * Wrapper then returns empty {@link OptionalLong} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromLongSupplier(() -> my_throwing_lambda).orElse(fallback)} - * - * @param supplier - * the {@link LongSupplier} to wrap, usually a lambda - * @return wrapper that runs {@code supplier} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalLongSupplier fromLongSupplier(LongSupplier supplier) { - return new CatchingLongSupplier(supplier); - } - private final class CatchingLongSupplier implements OptionalLongSupplier { - private final LongSupplier supplier; - CatchingLongSupplier(LongSupplier supplier) { - this.supplier = supplier; - } - @Override - public OptionalLong get() { - try { - return OptionalLong.of(supplier.getAsLong()); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalLong.empty(); - } - } - } - /** - * Wraps {@link DoubleSupplier} in a try-catch block. - *

- * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * Wrapper then returns empty {@link OptionalDouble} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromDoubleSupplier(() -> my_throwing_lambda).orElse(fallback)} - * - * @param supplier - * the {@link DoubleSupplier} to wrap, usually a lambda - * @return wrapper that runs {@code supplier} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalDoubleSupplier fromDoubleSupplier(DoubleSupplier supplier) { - return new CatchingDoubleSupplier(supplier); - } - private final class CatchingDoubleSupplier implements OptionalDoubleSupplier { - private final DoubleSupplier supplier; - CatchingDoubleSupplier(DoubleSupplier supplier) { - this.supplier = supplier; - } - @Override - public OptionalDouble get() { - try { - return OptionalDouble.of(supplier.getAsDouble()); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalDouble.empty(); - } - } - } - /** - * Wraps {@link BooleanSupplier} in a try-catch block. - *

- * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * Wrapper then returns empty {@link OptionalBoolean} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromBooleanSupplier(() -> my_throwing_lambda).orElse(fallback)} - * - * @param supplier - * the {@link BooleanSupplier} to wrap, usually a lambda - * @return wrapper that runs {@code supplier} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalBooleanSupplier fromBooleanSupplier(BooleanSupplier supplier) { - return new CatchingBooleanSupplier(supplier); - } - private final class CatchingBooleanSupplier implements OptionalBooleanSupplier { - private final BooleanSupplier supplier; - CatchingBooleanSupplier(BooleanSupplier supplier) { - this.supplier = supplier; - } - @Override - public OptionalBoolean get() { - try { - return OptionalBoolean.of(supplier.getAsBoolean()); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalBoolean.empty(); - } - } - } - /** - * Wraps {@link Consumer} in a try-catch block. - *

- * If {@code consumer} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code consumer} is caught too. - * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().consumer(t -> my_throwing_lambda)} - * - * @param - * see {@link Consumer} - * @param consumer - * the {@link Consumer} to wrap, usually a lambda - * @return wrapper that runs {@code consumer} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final Consumer consumer(Consumer consumer) { - return new CatchingConsumer(consumer); - } - private final class CatchingConsumer implements Consumer { - private final Consumer consumer; - CatchingConsumer(Consumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(T t) { - try { - consumer.accept(t); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - } - } - } - /** - * Wraps {@link IntConsumer} in a try-catch block. - *

- * If {@code consumer} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code consumer} is caught too. - * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromIntConsumer(v -> my_throwing_lambda)} - * - * @param consumer - * the {@link IntConsumer} to wrap, usually a lambda - * @return wrapper that runs {@code consumer} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final IntConsumer fromIntConsumer(IntConsumer consumer) { - return new CatchingIntConsumer(consumer); - } - private final class CatchingIntConsumer implements IntConsumer { - private final IntConsumer consumer; - CatchingIntConsumer(IntConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(int value) { - try { - consumer.accept(value); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - } - } - } - /** - * Wraps {@link LongConsumer} in a try-catch block. - *

- * If {@code consumer} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code consumer} is caught too. - * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromLongConsumer(v -> my_throwing_lambda)} - * - * @param consumer - * the {@link LongConsumer} to wrap, usually a lambda - * @return wrapper that runs {@code consumer} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final LongConsumer fromLongConsumer(LongConsumer consumer) { - return new CatchingLongConsumer(consumer); - } - private final class CatchingLongConsumer implements LongConsumer { - private final LongConsumer consumer; - CatchingLongConsumer(LongConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(long value) { - try { - consumer.accept(value); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - } - } - } - /** - * Wraps {@link DoubleConsumer} in a try-catch block. - *

- * If {@code consumer} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code consumer} is caught too. - * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromDoubleConsumer(v -> my_throwing_lambda)} - * - * @param consumer - * the {@link DoubleConsumer} to wrap, usually a lambda - * @return wrapper that runs {@code consumer} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final DoubleConsumer fromDoubleConsumer(DoubleConsumer consumer) { - return new CatchingDoubleConsumer(consumer); - } - private final class CatchingDoubleConsumer implements DoubleConsumer { - private final DoubleConsumer consumer; - CatchingDoubleConsumer(DoubleConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(double value) { - try { - consumer.accept(value); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - } - } - } - /** - * Wraps {@link BiConsumer} in a try-catch block. - *

- * If {@code consumer} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code consumer} is caught too. - * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromBiConsumer((t, u) -> my_throwing_lambda)} - * - * @param - * see {@link BiConsumer} - * @param - * see {@link BiConsumer} - * @param consumer - * the {@link BiConsumer} to wrap, usually a lambda - * @return wrapper that runs {@code consumer} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final BiConsumer fromBiConsumer(BiConsumer consumer) { - return new CatchingBiConsumer(consumer); - } - private final class CatchingBiConsumer implements BiConsumer { - private final BiConsumer consumer; - CatchingBiConsumer(BiConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(T t, U u) { - try { - consumer.accept(t, u); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - } - } - } - /** - * Wraps {@link ObjIntConsumer} in a try-catch block. - *

- * If {@code consumer} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code consumer} is caught too. - * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromObjIntConsumer((t, v) -> my_throwing_lambda)} - * - * @param - * see {@link ObjIntConsumer} - * @param consumer - * the {@link ObjIntConsumer} to wrap, usually a lambda - * @return wrapper that runs {@code consumer} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final ObjIntConsumer fromObjIntConsumer(ObjIntConsumer consumer) { - return new CatchingObjIntConsumer(consumer); - } - private final class CatchingObjIntConsumer implements ObjIntConsumer { - private final ObjIntConsumer consumer; - CatchingObjIntConsumer(ObjIntConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(T t, int value) { - try { - consumer.accept(t, value); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - } - } - } - /** - * Wraps {@link ObjLongConsumer} in a try-catch block. - *

- * If {@code consumer} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code consumer} is caught too. - * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromObjLongConsumer((t, v) -> my_throwing_lambda)} - * - * @param - * see {@link ObjLongConsumer} - * @param consumer - * the {@link ObjLongConsumer} to wrap, usually a lambda - * @return wrapper that runs {@code consumer} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final ObjLongConsumer fromObjLongConsumer(ObjLongConsumer consumer) { - return new CatchingObjLongConsumer(consumer); - } - private final class CatchingObjLongConsumer implements ObjLongConsumer { - private final ObjLongConsumer consumer; - CatchingObjLongConsumer(ObjLongConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(T t, long value) { - try { - consumer.accept(t, value); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - } - } - } - /** - * Wraps {@link ObjDoubleConsumer} in a try-catch block. - *

- * If {@code consumer} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code consumer} is caught too. - * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromObjDoubleConsumer((t, v) -> my_throwing_lambda)} - * - * @param - * see {@link ObjDoubleConsumer} - * @param consumer - * the {@link ObjDoubleConsumer} to wrap, usually a lambda - * @return wrapper that runs {@code consumer} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final ObjDoubleConsumer fromObjDoubleConsumer(ObjDoubleConsumer consumer) { - return new CatchingObjDoubleConsumer(consumer); - } - private final class CatchingObjDoubleConsumer implements ObjDoubleConsumer { - private final ObjDoubleConsumer consumer; - CatchingObjDoubleConsumer(ObjDoubleConsumer consumer) { - this.consumer = consumer; - } - @Override - public void accept(T t, double value) { - try { - consumer.accept(t, value); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - } - } - } - /** - * Wraps {@link Predicate} in a try-catch block. - *

- * If {@code predicate} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code predicate} is caught too. - * Wrapper then returns empty {@link OptionalBoolean} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().predicate(t -> my_throwing_lambda).orElse(fallback)} - * - * @param - * see {@link Predicate} - * @param predicate - * the {@link Predicate} to wrap, usually a lambda - * @return wrapper that runs {@code predicate} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalPredicate predicate(Predicate predicate) { - return new CatchingPredicate(predicate); - } - private final class CatchingPredicate implements OptionalPredicate { - private final Predicate predicate; - CatchingPredicate(Predicate predicate) { - this.predicate = predicate; - } - @Override - public OptionalBoolean test(T t) { - try { - return OptionalBoolean.of(predicate.test(t)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalBoolean.empty(); - } - } - } - /** - * Wraps {@link IntPredicate} in a try-catch block. - *

- * If {@code predicate} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code predicate} is caught too. - * Wrapper then returns empty {@link OptionalBoolean} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromIntPredicate(v -> my_throwing_lambda).orElse(fallback)} - * - * @param predicate - * the {@link IntPredicate} to wrap, usually a lambda - * @return wrapper that runs {@code predicate} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalIntPredicate fromIntPredicate(IntPredicate predicate) { - return new CatchingIntPredicate(predicate); - } - private final class CatchingIntPredicate implements OptionalIntPredicate { - private final IntPredicate predicate; - CatchingIntPredicate(IntPredicate predicate) { - this.predicate = predicate; - } - @Override - public OptionalBoolean test(int value) { - try { - return OptionalBoolean.of(predicate.test(value)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalBoolean.empty(); - } - } - } - /** - * Wraps {@link LongPredicate} in a try-catch block. - *

- * If {@code predicate} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code predicate} is caught too. - * Wrapper then returns empty {@link OptionalBoolean} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromLongPredicate(v -> my_throwing_lambda).orElse(fallback)} - * - * @param predicate - * the {@link LongPredicate} to wrap, usually a lambda - * @return wrapper that runs {@code predicate} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalLongPredicate fromLongPredicate(LongPredicate predicate) { - return new CatchingLongPredicate(predicate); - } - private final class CatchingLongPredicate implements OptionalLongPredicate { - private final LongPredicate predicate; - CatchingLongPredicate(LongPredicate predicate) { - this.predicate = predicate; - } - @Override - public OptionalBoolean test(long value) { - try { - return OptionalBoolean.of(predicate.test(value)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalBoolean.empty(); - } - } - } - /** - * Wraps {@link DoublePredicate} in a try-catch block. - *

- * If {@code predicate} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code predicate} is caught too. - * Wrapper then returns empty {@link OptionalBoolean} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromDoublePredicate(v -> my_throwing_lambda).orElse(fallback)} - * - * @param predicate - * the {@link DoublePredicate} to wrap, usually a lambda - * @return wrapper that runs {@code predicate} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalDoublePredicate fromDoublePredicate(DoublePredicate predicate) { - return new CatchingDoublePredicate(predicate); - } - private final class CatchingDoublePredicate implements OptionalDoublePredicate { - private final DoublePredicate predicate; - CatchingDoublePredicate(DoublePredicate predicate) { - this.predicate = predicate; - } - @Override - public OptionalBoolean test(double value) { - try { - return OptionalBoolean.of(predicate.test(value)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalBoolean.empty(); - } - } - } - /** - * Wraps {@link BiPredicate} in a try-catch block. - *

- * If {@code predicate} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code predicate} is caught too. - * Wrapper then returns empty {@link OptionalBoolean} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromBiPredicate((t, u) -> my_throwing_lambda).orElse(fallback)} - * - * @param - * see {@link BiPredicate} - * @param - * see {@link BiPredicate} - * @param predicate - * the {@link BiPredicate} to wrap, usually a lambda - * @return wrapper that runs {@code predicate} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalBiPredicate fromBiPredicate(BiPredicate predicate) { - return new CatchingBiPredicate(predicate); - } - private final class CatchingBiPredicate implements OptionalBiPredicate { - private final BiPredicate predicate; - CatchingBiPredicate(BiPredicate predicate) { - this.predicate = predicate; - } - @Override - public OptionalBoolean test(T t, U u) { - try { - return OptionalBoolean.of(predicate.test(t, u)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalBoolean.empty(); - } - } - } - /** - * Wraps {@link Function} in a try-catch block. - *

- * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Wrapper then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().function(t -> my_throwing_lambda).orElse(fallback)} - * - * @param - * see {@link Function} - * @param - * see {@link Function} - * @param function - * the {@link Function} to wrap, usually a lambda - * @return wrapper that runs {@code function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalFunction function(Function function) { - return new CatchingFunction(function); - } - private final class CatchingFunction implements OptionalFunction { - private final Function function; - CatchingFunction(Function function) { - this.function = function; - } - @Override - public Optional apply(T t) { - try { - return Optional.ofNullable(function.apply(t)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return Optional.empty(); - } - } - } - /** - * Wraps {@link ToIntFunction} in a try-catch block. - *

- * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Wrapper then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromToIntFunction(v -> my_throwing_lambda).orElse(fallback)} - * - * @param - * see {@link ToIntFunction} - * @param function - * the {@link ToIntFunction} to wrap, usually a lambda - * @return wrapper that runs {@code function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalToIntFunction fromToIntFunction(ToIntFunction function) { - return new CatchingToIntFunction(function); - } - private final class CatchingToIntFunction implements OptionalToIntFunction { - private final ToIntFunction function; - CatchingToIntFunction(ToIntFunction function) { - this.function = function; - } - @Override - public OptionalInt apply(T value) { - try { - return OptionalInt.of(function.applyAsInt(value)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalInt.empty(); - } - } - } - /** - * Wraps {@link IntFunction} in a try-catch block. - *

- * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Wrapper then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromIntFunction(v -> my_throwing_lambda).orElse(fallback)} - * - * @param - * see {@link IntFunction} - * @param function - * the {@link IntFunction} to wrap, usually a lambda - * @return wrapper that runs {@code function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalIntFunction fromIntFunction(IntFunction function) { - return new CatchingIntFunction(function); - } - private final class CatchingIntFunction implements OptionalIntFunction { - private final IntFunction function; - CatchingIntFunction(IntFunction function) { - this.function = function; - } - @Override - public Optional apply(int value) { - try { - return Optional.ofNullable(function.apply(value)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return Optional.empty(); - } - } - } - /** - * Wraps {@link IntToLongFunction} in a try-catch block. - *

- * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Wrapper then returns empty {@link OptionalLong} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromIntToLongFunction(v -> my_throwing_lambda).orElse(fallback)} - * - * @param function - * the {@link IntToLongFunction} to wrap, usually a lambda - * @return wrapper that runs {@code function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalIntToLongFunction fromIntToLongFunction(IntToLongFunction function) { - return new CatchingIntToLongFunction(function); - } - private final class CatchingIntToLongFunction implements OptionalIntToLongFunction { - private final IntToLongFunction function; - CatchingIntToLongFunction(IntToLongFunction function) { - this.function = function; - } - @Override - public OptionalLong apply(int value) { - try { - return OptionalLong.of(function.applyAsLong(value)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalLong.empty(); - } - } - } - /** - * Wraps {@link IntToDoubleFunction} in a try-catch block. - *

- * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Wrapper then returns empty {@link OptionalDouble} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromIntToDoubleFunction(v -> my_throwing_lambda).orElse(fallback)} - * - * @param function - * the {@link IntToDoubleFunction} to wrap, usually a lambda - * @return wrapper that runs {@code function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalIntToDoubleFunction fromIntToDoubleFunction(IntToDoubleFunction function) { - return new CatchingIntToDoubleFunction(function); - } - private final class CatchingIntToDoubleFunction implements OptionalIntToDoubleFunction { - private final IntToDoubleFunction function; - CatchingIntToDoubleFunction(IntToDoubleFunction function) { - this.function = function; - } - @Override - public OptionalDouble apply(int value) { - try { - return OptionalDouble.of(function.applyAsDouble(value)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalDouble.empty(); - } - } - } - /** - * Wraps {@link ToLongFunction} in a try-catch block. - *

- * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Wrapper then returns empty {@link OptionalLong} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromToLongFunction(v -> my_throwing_lambda).orElse(fallback)} - * - * @param - * see {@link ToLongFunction} - * @param function - * the {@link ToLongFunction} to wrap, usually a lambda - * @return wrapper that runs {@code function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalToLongFunction fromToLongFunction(ToLongFunction function) { - return new CatchingToLongFunction(function); - } - private final class CatchingToLongFunction implements OptionalToLongFunction { - private final ToLongFunction function; - CatchingToLongFunction(ToLongFunction function) { - this.function = function; - } - @Override - public OptionalLong apply(T value) { - try { - return OptionalLong.of(function.applyAsLong(value)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalLong.empty(); - } - } - } - /** - * Wraps {@link LongFunction} in a try-catch block. - *

- * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Wrapper then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromLongFunction(v -> my_throwing_lambda).orElse(fallback)} - * - * @param - * see {@link LongFunction} - * @param function - * the {@link LongFunction} to wrap, usually a lambda - * @return wrapper that runs {@code function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalLongFunction fromLongFunction(LongFunction function) { - return new CatchingLongFunction(function); - } - private final class CatchingLongFunction implements OptionalLongFunction { - private final LongFunction function; - CatchingLongFunction(LongFunction function) { - this.function = function; - } - @Override - public Optional apply(long value) { - try { - return Optional.ofNullable(function.apply(value)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return Optional.empty(); - } - } - } - /** - * Wraps {@link LongToIntFunction} in a try-catch block. - *

- * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Wrapper then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromLongToIntFunction(v -> my_throwing_lambda).orElse(fallback)} - * - * @param function - * the {@link LongToIntFunction} to wrap, usually a lambda - * @return wrapper that runs {@code function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalLongToIntFunction fromLongToIntFunction(LongToIntFunction function) { - return new CatchingLongToIntFunction(function); - } - private final class CatchingLongToIntFunction implements OptionalLongToIntFunction { - private final LongToIntFunction function; - CatchingLongToIntFunction(LongToIntFunction function) { - this.function = function; - } - @Override - public OptionalInt apply(long value) { - try { - return OptionalInt.of(function.applyAsInt(value)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalInt.empty(); - } - } - } - /** - * Wraps {@link LongToDoubleFunction} in a try-catch block. - *

- * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Wrapper then returns empty {@link OptionalDouble} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromLongToDoubleFunction(v -> my_throwing_lambda).orElse(fallback)} - * - * @param function - * the {@link LongToDoubleFunction} to wrap, usually a lambda - * @return wrapper that runs {@code function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalLongToDoubleFunction fromLongToDoubleFunction(LongToDoubleFunction function) { - return new CatchingLongToDoubleFunction(function); - } - private final class CatchingLongToDoubleFunction implements OptionalLongToDoubleFunction { - private final LongToDoubleFunction function; - CatchingLongToDoubleFunction(LongToDoubleFunction function) { - this.function = function; - } - @Override - public OptionalDouble apply(long value) { - try { - return OptionalDouble.of(function.applyAsDouble(value)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalDouble.empty(); - } - } - } - /** - * Wraps {@link ToDoubleFunction} in a try-catch block. - *

- * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Wrapper then returns empty {@link OptionalDouble} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromToDoubleFunction(v -> my_throwing_lambda).orElse(fallback)} - * - * @param - * see {@link ToDoubleFunction} - * @param function - * the {@link ToDoubleFunction} to wrap, usually a lambda - * @return wrapper that runs {@code function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalToDoubleFunction fromToDoubleFunction(ToDoubleFunction function) { - return new CatchingToDoubleFunction(function); - } - private final class CatchingToDoubleFunction implements OptionalToDoubleFunction { - private final ToDoubleFunction function; - CatchingToDoubleFunction(ToDoubleFunction function) { - this.function = function; - } - @Override - public OptionalDouble apply(T value) { - try { - return OptionalDouble.of(function.applyAsDouble(value)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalDouble.empty(); - } - } - } - /** - * Wraps {@link DoubleFunction} in a try-catch block. - *

- * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Wrapper then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromDoubleFunction(v -> my_throwing_lambda).orElse(fallback)} - * - * @param - * see {@link DoubleFunction} - * @param function - * the {@link DoubleFunction} to wrap, usually a lambda - * @return wrapper that runs {@code function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalDoubleFunction fromDoubleFunction(DoubleFunction function) { - return new CatchingDoubleFunction(function); - } - private final class CatchingDoubleFunction implements OptionalDoubleFunction { - private final DoubleFunction function; - CatchingDoubleFunction(DoubleFunction function) { - this.function = function; - } - @Override - public Optional apply(double value) { - try { - return Optional.ofNullable(function.apply(value)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return Optional.empty(); - } - } - } - /** - * Wraps {@link DoubleToIntFunction} in a try-catch block. - *

- * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Wrapper then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromDoubleToIntFunction(v -> my_throwing_lambda).orElse(fallback)} - * - * @param function - * the {@link DoubleToIntFunction} to wrap, usually a lambda - * @return wrapper that runs {@code function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalDoubleToIntFunction fromDoubleToIntFunction(DoubleToIntFunction function) { - return new CatchingDoubleToIntFunction(function); - } - private final class CatchingDoubleToIntFunction implements OptionalDoubleToIntFunction { - private final DoubleToIntFunction function; - CatchingDoubleToIntFunction(DoubleToIntFunction function) { - this.function = function; - } - @Override - public OptionalInt apply(double value) { - try { - return OptionalInt.of(function.applyAsInt(value)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalInt.empty(); - } - } - } - /** - * Wraps {@link DoubleToLongFunction} in a try-catch block. - *

- * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Wrapper then returns empty {@link OptionalLong} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromDoubleToLongFunction(v -> my_throwing_lambda).orElse(fallback)} - * - * @param function - * the {@link DoubleToLongFunction} to wrap, usually a lambda - * @return wrapper that runs {@code function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalDoubleToLongFunction fromDoubleToLongFunction(DoubleToLongFunction function) { - return new CatchingDoubleToLongFunction(function); - } - private final class CatchingDoubleToLongFunction implements OptionalDoubleToLongFunction { - private final DoubleToLongFunction function; - CatchingDoubleToLongFunction(DoubleToLongFunction function) { - this.function = function; - } - @Override - public OptionalLong apply(double value) { - try { - return OptionalLong.of(function.applyAsLong(value)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalLong.empty(); - } - } - } - /** - * Wraps {@link UnaryOperator} in a try-catch block. - *

- * If {@code operator} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code operator} is caught too. - * Wrapper then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromUnaryOperator(o -> my_throwing_lambda).orElse(fallback)} - * - * @param - * see {@link UnaryOperator} - * @param operator - * the {@link UnaryOperator} to wrap, usually a lambda - * @return wrapper that runs {@code operator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalUnaryOperator fromUnaryOperator(UnaryOperator operator) { - return new CatchingUnaryOperator(operator); - } - private final class CatchingUnaryOperator implements OptionalUnaryOperator { - private final UnaryOperator operator; - CatchingUnaryOperator(UnaryOperator operator) { - this.operator = operator; - } - @Override - public Optional apply(T operand) { - try { - return Optional.ofNullable(operator.apply(operand)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return Optional.empty(); - } - } - } - /** - * Wraps {@link IntUnaryOperator} in a try-catch block. - *

- * If {@code operator} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code operator} is caught too. - * Wrapper then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromIntUnaryOperator(o -> my_throwing_lambda).orElse(fallback)} - * - * @param operator - * the {@link IntUnaryOperator} to wrap, usually a lambda - * @return wrapper that runs {@code operator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalIntUnaryOperator fromIntUnaryOperator(IntUnaryOperator operator) { - return new CatchingIntUnaryOperator(operator); - } - private final class CatchingIntUnaryOperator implements OptionalIntUnaryOperator { - private final IntUnaryOperator operator; - CatchingIntUnaryOperator(IntUnaryOperator operator) { - this.operator = operator; - } - @Override - public OptionalInt apply(int operand) { - try { - return OptionalInt.of(operator.applyAsInt(operand)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalInt.empty(); - } - } - } - /** - * Wraps {@link LongUnaryOperator} in a try-catch block. - *

- * If {@code operator} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code operator} is caught too. - * Wrapper then returns empty {@link OptionalLong} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromLongUnaryOperator(o -> my_throwing_lambda).orElse(fallback)} - * - * @param operator - * the {@link LongUnaryOperator} to wrap, usually a lambda - * @return wrapper that runs {@code operator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalLongUnaryOperator fromLongUnaryOperator(LongUnaryOperator operator) { - return new CatchingLongUnaryOperator(operator); - } - private final class CatchingLongUnaryOperator implements OptionalLongUnaryOperator { - private final LongUnaryOperator operator; - CatchingLongUnaryOperator(LongUnaryOperator operator) { - this.operator = operator; - } - @Override - public OptionalLong apply(long operand) { - try { - return OptionalLong.of(operator.applyAsLong(operand)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalLong.empty(); - } - } - } - /** - * Wraps {@link DoubleUnaryOperator} in a try-catch block. - *

- * If {@code operator} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code operator} is caught too. - * Wrapper then returns empty {@link OptionalDouble} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromDoubleUnaryOperator(o -> my_throwing_lambda).orElse(fallback)} - * - * @param operator - * the {@link DoubleUnaryOperator} to wrap, usually a lambda - * @return wrapper that runs {@code operator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalDoubleUnaryOperator fromDoubleUnaryOperator(DoubleUnaryOperator operator) { - return new CatchingDoubleUnaryOperator(operator); - } - private final class CatchingDoubleUnaryOperator implements OptionalDoubleUnaryOperator { - private final DoubleUnaryOperator operator; - CatchingDoubleUnaryOperator(DoubleUnaryOperator operator) { - this.operator = operator; - } - @Override - public OptionalDouble apply(double operand) { - try { - return OptionalDouble.of(operator.applyAsDouble(operand)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalDouble.empty(); - } - } - } - /** - * Wraps {@link BiFunction} in a try-catch block. - *

- * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Wrapper then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)} - * - * @param - * see {@link BiFunction} - * @param - * see {@link BiFunction} - * @param - * see {@link BiFunction} - * @param function - * the {@link BiFunction} to wrap, usually a lambda - * @return wrapper that runs {@code function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalBiFunction fromBiFunction(BiFunction function) { - return new CatchingBiFunction(function); - } - private final class CatchingBiFunction implements OptionalBiFunction { - private final BiFunction function; - CatchingBiFunction(BiFunction function) { - this.function = function; - } - @Override - public Optional apply(T t, U u) { - try { - return Optional.ofNullable(function.apply(t, u)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return Optional.empty(); - } - } - } - /** - * Wraps {@link ToIntBiFunction} in a try-catch block. - *

- * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Wrapper then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromToIntBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)} - * - * @param - * see {@link ToIntBiFunction} - * @param - * see {@link ToIntBiFunction} - * @param function - * the {@link ToIntBiFunction} to wrap, usually a lambda - * @return wrapper that runs {@code function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalToIntBiFunction fromToIntBiFunction(ToIntBiFunction function) { - return new CatchingToIntBiFunction(function); - } - private final class CatchingToIntBiFunction implements OptionalToIntBiFunction { - private final ToIntBiFunction function; - CatchingToIntBiFunction(ToIntBiFunction function) { - this.function = function; - } - @Override - public OptionalInt apply(T t, U u) { - try { - return OptionalInt.of(function.applyAsInt(t, u)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalInt.empty(); - } - } - } - /** - * Wraps {@link ToLongBiFunction} in a try-catch block. - *

- * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Wrapper then returns empty {@link OptionalLong} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromToLongBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)} - * - * @param - * see {@link ToLongBiFunction} - * @param - * see {@link ToLongBiFunction} - * @param function - * the {@link ToLongBiFunction} to wrap, usually a lambda - * @return wrapper that runs {@code function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalToLongBiFunction fromToLongBiFunction(ToLongBiFunction function) { - return new CatchingToLongBiFunction(function); - } - private final class CatchingToLongBiFunction implements OptionalToLongBiFunction { - private final ToLongBiFunction function; - CatchingToLongBiFunction(ToLongBiFunction function) { - this.function = function; - } - @Override - public OptionalLong apply(T t, U u) { - try { - return OptionalLong.of(function.applyAsLong(t, u)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalLong.empty(); - } - } - } - /** - * Wraps {@link ToDoubleBiFunction} in a try-catch block. - *

- * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code function} is caught too. - * Wrapper then returns empty {@link OptionalDouble} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromToDoubleBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)} - * - * @param - * see {@link ToDoubleBiFunction} - * @param - * see {@link ToDoubleBiFunction} - * @param function - * the {@link ToDoubleBiFunction} to wrap, usually a lambda - * @return wrapper that runs {@code function} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalToDoubleBiFunction fromToDoubleBiFunction(ToDoubleBiFunction function) { - return new CatchingToDoubleBiFunction(function); - } - private final class CatchingToDoubleBiFunction implements OptionalToDoubleBiFunction { - private final ToDoubleBiFunction function; - CatchingToDoubleBiFunction(ToDoubleBiFunction function) { - this.function = function; - } - @Override - public OptionalDouble apply(T t, U u) { - try { - return OptionalDouble.of(function.applyAsDouble(t, u)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalDouble.empty(); - } - } - } - /** - * Wraps {@link BinaryOperator} in a try-catch block. - *

- * If {@code operator} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code operator} is caught too. - * Wrapper then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)} - * - * @param - * see {@link BinaryOperator} - * @param operator - * the {@link BinaryOperator} to wrap, usually a lambda - * @return wrapper that runs {@code operator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalBinaryOperator fromBinaryOperator(BinaryOperator operator) { - return new CatchingBinaryOperator(operator); - } - private final class CatchingBinaryOperator implements OptionalBinaryOperator { - private final BinaryOperator operator; - CatchingBinaryOperator(BinaryOperator operator) { - this.operator = operator; - } - @Override - public Optional apply(T left, T right) { - try { - return Optional.ofNullable(operator.apply(left, right)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return Optional.empty(); - } - } - } - /** - * Wraps {@link IntBinaryOperator} in a try-catch block. - *

- * If {@code operator} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code operator} is caught too. - * Wrapper then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromIntBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)} - * - * @param operator - * the {@link IntBinaryOperator} to wrap, usually a lambda - * @return wrapper that runs {@code operator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalIntBinaryOperator fromIntBinaryOperator(IntBinaryOperator operator) { - return new CatchingIntBinaryOperator(operator); - } - private final class CatchingIntBinaryOperator implements OptionalIntBinaryOperator { - private final IntBinaryOperator operator; - CatchingIntBinaryOperator(IntBinaryOperator operator) { - this.operator = operator; - } - @Override - public OptionalInt apply(int left, int right) { - try { - return OptionalInt.of(operator.applyAsInt(left, right)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalInt.empty(); - } - } - } - /** - * Wraps {@link LongBinaryOperator} in a try-catch block. - *

- * If {@code operator} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code operator} is caught too. - * Wrapper then returns empty {@link OptionalLong} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromLongBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)} - * - * @param operator - * the {@link LongBinaryOperator} to wrap, usually a lambda - * @return wrapper that runs {@code operator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalLongBinaryOperator fromLongBinaryOperator(LongBinaryOperator operator) { - return new CatchingLongBinaryOperator(operator); - } - private final class CatchingLongBinaryOperator implements OptionalLongBinaryOperator { - private final LongBinaryOperator operator; - CatchingLongBinaryOperator(LongBinaryOperator operator) { - this.operator = operator; - } - @Override - public OptionalLong apply(long left, long right) { - try { - return OptionalLong.of(operator.applyAsLong(left, right)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalLong.empty(); - } - } - } - /** - * Wraps {@link DoubleBinaryOperator} in a try-catch block. - *

- * If {@code operator} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code operator} is caught too. - * Wrapper then returns empty {@link OptionalDouble} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().fromDoubleBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)} - * - * @param operator - * the {@link DoubleBinaryOperator} to wrap, usually a lambda - * @return wrapper that runs {@code operator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalDoubleBinaryOperator fromDoubleBinaryOperator(DoubleBinaryOperator operator) { - return new CatchingDoubleBinaryOperator(operator); - } - private final class CatchingDoubleBinaryOperator implements OptionalDoubleBinaryOperator { - private final DoubleBinaryOperator operator; - CatchingDoubleBinaryOperator(DoubleBinaryOperator operator) { - this.operator = operator; - } - @Override - public OptionalDouble apply(double left, double right) { - try { - return OptionalDouble.of(operator.applyAsDouble(left, right)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalDouble.empty(); - } - } - } - /** - * Wraps {@link Comparator} in a try-catch block. - *

- * If {@code comparator} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code comparator} is caught too. - * Wrapper then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().comparator((l, r) -> my_throwing_lambda).orElse(fallback)} - * - * @param - * see {@link Comparator} - * @param comparator - * the {@link Comparator} to wrap, usually a lambda - * @return wrapper that runs {@code comparator} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final OptionalComparator comparator(Comparator comparator) { - return new CatchingComparator(comparator); - } - private final class CatchingComparator implements OptionalComparator { - private final Comparator comparator; - CatchingComparator(Comparator comparator) { - this.comparator = comparator; - } - @Override - public OptionalInt compare(T left, T right) { - try { - return OptionalInt.of(comparator.compare(left, right)); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalInt.empty(); - } - } - } - /** - * Wraps {@link CloseableScope} in a try-catch block. - *

- * If {@code closeable} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code closeable} is caught too. - * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code try (var scope = Exceptions.silence().closeable(openSomething()))} - * - * @param closeable - * the {@link CloseableScope} to wrap - * @return wrapper that runs {@code closeable} in a try-catch block - * @see Tutorial - * @see Exceptions - */ - public final CloseableScope closeable(CloseableScope closeable) { - return new CatchingCloseableScope(closeable); - } - private final class CatchingCloseableScope implements CloseableScope { - private final CloseableScope closeable; - CatchingCloseableScope(CloseableScope closeable) { - this.closeable = closeable; - } - @Override - public void close() { - try { - closeable.close(); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - } - } - } - /** - * Runs {@link Runnable} in a try-catch block. - *

- * If {@code runnable} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code runnable} is caught too. - * This method then completes normally unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().run(() -> my_throwing_lambda)} - * - * @param runnable - * the {@link Runnable} to run, usually a lambda - * @see Tutorial - * @see Exceptions - */ - public final void run(Runnable runnable) { - try { - runnable.run(); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - } - } - /** - * Runs {@link Supplier} in a try-catch block. - *

- * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * This method then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().get(() -> my_throwing_lambda)} - * - * @param - * see {@link Supplier} - * @param supplier - * the {@link Supplier} to run, usually a lambda - * @return an {@link Optional} carrying {@code supplier} result or an empty {@link Optional} if exception was caught - * @see Tutorial - * @see Exceptions - */ - public final Optional get(Supplier supplier) { - try { - return Optional.ofNullable(supplier.get()); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return Optional.empty(); - } - } - /** - * Runs {@link IntSupplier} in a try-catch block. - *

- * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * This method then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().getAsInt(() -> my_throwing_lambda)} - * - * @param supplier - * the {@link IntSupplier} to run, usually a lambda - * @return an {@link OptionalInt} carrying {@code supplier} result or an empty {@link OptionalInt} if exception was caught - * @see Tutorial - * @see Exceptions - */ - public final OptionalInt getAsInt(IntSupplier supplier) { - try { - return OptionalInt.of(supplier.getAsInt()); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalInt.empty(); - } - } - /** - * Runs {@link LongSupplier} in a try-catch block. - *

- * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * This method then returns empty {@link OptionalLong} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().getAsLong(() -> my_throwing_lambda)} - * - * @param supplier - * the {@link LongSupplier} to run, usually a lambda - * @return an {@link OptionalLong} carrying {@code supplier} result or an empty {@link OptionalLong} if exception was caught - * @see Tutorial - * @see Exceptions - */ - public final OptionalLong getAsLong(LongSupplier supplier) { - try { - return OptionalLong.of(supplier.getAsLong()); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalLong.empty(); - } - } - /** - * Runs {@link DoubleSupplier} in a try-catch block. - *

- * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * This method then returns empty {@link OptionalDouble} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().getAsDouble(() -> my_throwing_lambda)} - * - * @param supplier - * the {@link DoubleSupplier} to run, usually a lambda - * @return an {@link OptionalDouble} carrying {@code supplier} result or an empty {@link OptionalDouble} if exception was caught - * @see Tutorial - * @see Exceptions - */ - public final OptionalDouble getAsDouble(DoubleSupplier supplier) { - try { - return OptionalDouble.of(supplier.getAsDouble()); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalDouble.empty(); - } - } - /** - * Runs {@link BooleanSupplier} in a try-catch block. - *

- * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, - * which applies exception handling policy (silence, propagate, log, custom). - * {@link NullPointerException} from {@code null} {@code supplier} is caught too. - * This method then returns empty {@link OptionalBoolean} unless {@link #handle(Throwable)} requests a rethrow. - *

- * Typical usage: {@code Exceptions.silence().getAsBoolean(() -> my_throwing_lambda)} - * - * @param supplier - * the {@link BooleanSupplier} to run, usually a lambda - * @return an {@link OptionalBoolean} carrying {@code supplier} result or an empty {@link OptionalBoolean} if exception was caught - * @see Tutorial - * @see Exceptions - */ - public final OptionalBoolean getAsBoolean(BooleanSupplier supplier) { - try { - return OptionalBoolean.of(supplier.getAsBoolean()); - } catch (Throwable exception) { - if (!handle(exception)) - throw exception; - return OptionalBoolean.empty(); - } - } + /** + * Handles exception in a generic way. This method must be defined in a derived class. + * Several implementations are provided by methods on {@link Exceptions} class. + * All other methods of the {@code ExceptionHandler} call this method, but it can be also called directly. + *

+ * This method represents reusable catch block that handles all exceptions in the same way. + * When invoked, it must somehow handle the provided exception, for example by logging it. + *

+ * This method does not have to handle all exceptions. + * It can indicate through return value whether it has accepted or rejected the exception. + * When an exception is rejected, caller of this method is expected to rethrow the exception. + * All other methods of this class fulfill this requirement. + * + * @param exception + * the exception to handle + * @return {@code true} when exception is handled, {@code false} if the exception should be rethrown + * @throws NullPointerException + * if {@code exception} is {@code null} + * @see Tutorial + * @see Exceptions + */ + public abstract boolean handle(Throwable exception); + /** + * Initialize new {@code ExceptionHandler}. + */ + protected ExceptionHandler() { + } + /** + * Adds a pass-through modifier to this exception handler. + * If this exception handler performs an action (like logging) and then stops exception propagation, + * this method will return {@link ExceptionFilter} that performs the same action but additionally rethrows the exception. + *

+ * Reusable exception handlers can be defined once as {@code ExceptionHandler} instances + * and then transformed into {@link ExceptionFilter} by this method when needed. + *

+ * If method {@link #handle(Throwable)} throws, the returned {@link ExceptionFilter} will pass through that exception. + * It only rethrows the original exception if {@link #handle(Throwable)} returns normally (regardless of return value). + *

+ * Typical usage: {@code ExceptionLogging.log().passing().get(() -> my_throwing_lambda)} + * + * @return pass-through modification of this exception handler + */ + public ExceptionFilter passing() { + return new PassingFilter(this); + } + /** + * Wraps {@link Runnable} in a try-catch block. + *

+ * If {@code runnable} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code runnable} is caught too. + * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().runnable(() -> my_throwing_lambda)} + * + * @param runnable + * the {@link Runnable} to wrap, usually a lambda + * @return wrapper that runs {@code runnable} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final Runnable runnable(Runnable runnable) { + return new CatchingRunnable(runnable); + } + private final class CatchingRunnable implements Runnable { + private final Runnable runnable; + CatchingRunnable(Runnable runnable) { + this.runnable = runnable; + } + @Override + public void run() { + try { + runnable.run(); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + } + } + } + /** + * Wraps {@link Supplier} in a try-catch block. + *

+ * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * Wrapper then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().supplier(() -> my_throwing_lambda).orElse(fallback)} + * + * @param + * see {@link Supplier} + * @param supplier + * the {@link Supplier} to wrap, usually a lambda + * @return wrapper that runs {@code supplier} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalSupplier supplier(Supplier supplier) { + return new CatchingSupplier(supplier); + } + private final class CatchingSupplier implements OptionalSupplier { + private final Supplier supplier; + CatchingSupplier(Supplier supplier) { + this.supplier = supplier; + } + @Override + public Optional get() { + try { + return Optional.ofNullable(supplier.get()); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return Optional.empty(); + } + } + } + /** + * Wraps {@link IntSupplier} in a try-catch block. + *

+ * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * Wrapper then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromIntSupplier(() -> my_throwing_lambda).orElse(fallback)} + * + * @param supplier + * the {@link IntSupplier} to wrap, usually a lambda + * @return wrapper that runs {@code supplier} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalIntSupplier fromIntSupplier(IntSupplier supplier) { + return new CatchingIntSupplier(supplier); + } + private final class CatchingIntSupplier implements OptionalIntSupplier { + private final IntSupplier supplier; + CatchingIntSupplier(IntSupplier supplier) { + this.supplier = supplier; + } + @Override + public OptionalInt get() { + try { + return OptionalInt.of(supplier.getAsInt()); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalInt.empty(); + } + } + } + /** + * Wraps {@link LongSupplier} in a try-catch block. + *

+ * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * Wrapper then returns empty {@link OptionalLong} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromLongSupplier(() -> my_throwing_lambda).orElse(fallback)} + * + * @param supplier + * the {@link LongSupplier} to wrap, usually a lambda + * @return wrapper that runs {@code supplier} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalLongSupplier fromLongSupplier(LongSupplier supplier) { + return new CatchingLongSupplier(supplier); + } + private final class CatchingLongSupplier implements OptionalLongSupplier { + private final LongSupplier supplier; + CatchingLongSupplier(LongSupplier supplier) { + this.supplier = supplier; + } + @Override + public OptionalLong get() { + try { + return OptionalLong.of(supplier.getAsLong()); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalLong.empty(); + } + } + } + /** + * Wraps {@link DoubleSupplier} in a try-catch block. + *

+ * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * Wrapper then returns empty {@link OptionalDouble} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromDoubleSupplier(() -> my_throwing_lambda).orElse(fallback)} + * + * @param supplier + * the {@link DoubleSupplier} to wrap, usually a lambda + * @return wrapper that runs {@code supplier} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalDoubleSupplier fromDoubleSupplier(DoubleSupplier supplier) { + return new CatchingDoubleSupplier(supplier); + } + private final class CatchingDoubleSupplier implements OptionalDoubleSupplier { + private final DoubleSupplier supplier; + CatchingDoubleSupplier(DoubleSupplier supplier) { + this.supplier = supplier; + } + @Override + public OptionalDouble get() { + try { + return OptionalDouble.of(supplier.getAsDouble()); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalDouble.empty(); + } + } + } + /** + * Wraps {@link BooleanSupplier} in a try-catch block. + *

+ * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * Wrapper then returns empty {@link OptionalBoolean} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromBooleanSupplier(() -> my_throwing_lambda).orElse(fallback)} + * + * @param supplier + * the {@link BooleanSupplier} to wrap, usually a lambda + * @return wrapper that runs {@code supplier} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalBooleanSupplier fromBooleanSupplier(BooleanSupplier supplier) { + return new CatchingBooleanSupplier(supplier); + } + private final class CatchingBooleanSupplier implements OptionalBooleanSupplier { + private final BooleanSupplier supplier; + CatchingBooleanSupplier(BooleanSupplier supplier) { + this.supplier = supplier; + } + @Override + public OptionalBoolean get() { + try { + return OptionalBoolean.of(supplier.getAsBoolean()); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalBoolean.empty(); + } + } + } + /** + * Wraps {@link Consumer} in a try-catch block. + *

+ * If {@code consumer} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code consumer} is caught too. + * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().consumer(t -> my_throwing_lambda)} + * + * @param + * see {@link Consumer} + * @param consumer + * the {@link Consumer} to wrap, usually a lambda + * @return wrapper that runs {@code consumer} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final Consumer consumer(Consumer consumer) { + return new CatchingConsumer(consumer); + } + private final class CatchingConsumer implements Consumer { + private final Consumer consumer; + CatchingConsumer(Consumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(T t) { + try { + consumer.accept(t); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + } + } + } + /** + * Wraps {@link IntConsumer} in a try-catch block. + *

+ * If {@code consumer} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code consumer} is caught too. + * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromIntConsumer(v -> my_throwing_lambda)} + * + * @param consumer + * the {@link IntConsumer} to wrap, usually a lambda + * @return wrapper that runs {@code consumer} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final IntConsumer fromIntConsumer(IntConsumer consumer) { + return new CatchingIntConsumer(consumer); + } + private final class CatchingIntConsumer implements IntConsumer { + private final IntConsumer consumer; + CatchingIntConsumer(IntConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(int value) { + try { + consumer.accept(value); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + } + } + } + /** + * Wraps {@link LongConsumer} in a try-catch block. + *

+ * If {@code consumer} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code consumer} is caught too. + * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromLongConsumer(v -> my_throwing_lambda)} + * + * @param consumer + * the {@link LongConsumer} to wrap, usually a lambda + * @return wrapper that runs {@code consumer} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final LongConsumer fromLongConsumer(LongConsumer consumer) { + return new CatchingLongConsumer(consumer); + } + private final class CatchingLongConsumer implements LongConsumer { + private final LongConsumer consumer; + CatchingLongConsumer(LongConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(long value) { + try { + consumer.accept(value); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + } + } + } + /** + * Wraps {@link DoubleConsumer} in a try-catch block. + *

+ * If {@code consumer} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code consumer} is caught too. + * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromDoubleConsumer(v -> my_throwing_lambda)} + * + * @param consumer + * the {@link DoubleConsumer} to wrap, usually a lambda + * @return wrapper that runs {@code consumer} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final DoubleConsumer fromDoubleConsumer(DoubleConsumer consumer) { + return new CatchingDoubleConsumer(consumer); + } + private final class CatchingDoubleConsumer implements DoubleConsumer { + private final DoubleConsumer consumer; + CatchingDoubleConsumer(DoubleConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(double value) { + try { + consumer.accept(value); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + } + } + } + /** + * Wraps {@link BiConsumer} in a try-catch block. + *

+ * If {@code consumer} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code consumer} is caught too. + * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromBiConsumer((t, u) -> my_throwing_lambda)} + * + * @param + * see {@link BiConsumer} + * @param + * see {@link BiConsumer} + * @param consumer + * the {@link BiConsumer} to wrap, usually a lambda + * @return wrapper that runs {@code consumer} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final BiConsumer fromBiConsumer(BiConsumer consumer) { + return new CatchingBiConsumer(consumer); + } + private final class CatchingBiConsumer implements BiConsumer { + private final BiConsumer consumer; + CatchingBiConsumer(BiConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(T t, U u) { + try { + consumer.accept(t, u); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + } + } + } + /** + * Wraps {@link ObjIntConsumer} in a try-catch block. + *

+ * If {@code consumer} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code consumer} is caught too. + * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromObjIntConsumer((t, v) -> my_throwing_lambda)} + * + * @param + * see {@link ObjIntConsumer} + * @param consumer + * the {@link ObjIntConsumer} to wrap, usually a lambda + * @return wrapper that runs {@code consumer} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final ObjIntConsumer fromObjIntConsumer(ObjIntConsumer consumer) { + return new CatchingObjIntConsumer(consumer); + } + private final class CatchingObjIntConsumer implements ObjIntConsumer { + private final ObjIntConsumer consumer; + CatchingObjIntConsumer(ObjIntConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(T t, int value) { + try { + consumer.accept(t, value); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + } + } + } + /** + * Wraps {@link ObjLongConsumer} in a try-catch block. + *

+ * If {@code consumer} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code consumer} is caught too. + * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromObjLongConsumer((t, v) -> my_throwing_lambda)} + * + * @param + * see {@link ObjLongConsumer} + * @param consumer + * the {@link ObjLongConsumer} to wrap, usually a lambda + * @return wrapper that runs {@code consumer} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final ObjLongConsumer fromObjLongConsumer(ObjLongConsumer consumer) { + return new CatchingObjLongConsumer(consumer); + } + private final class CatchingObjLongConsumer implements ObjLongConsumer { + private final ObjLongConsumer consumer; + CatchingObjLongConsumer(ObjLongConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(T t, long value) { + try { + consumer.accept(t, value); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + } + } + } + /** + * Wraps {@link ObjDoubleConsumer} in a try-catch block. + *

+ * If {@code consumer} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code consumer} is caught too. + * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromObjDoubleConsumer((t, v) -> my_throwing_lambda)} + * + * @param + * see {@link ObjDoubleConsumer} + * @param consumer + * the {@link ObjDoubleConsumer} to wrap, usually a lambda + * @return wrapper that runs {@code consumer} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final ObjDoubleConsumer fromObjDoubleConsumer(ObjDoubleConsumer consumer) { + return new CatchingObjDoubleConsumer(consumer); + } + private final class CatchingObjDoubleConsumer implements ObjDoubleConsumer { + private final ObjDoubleConsumer consumer; + CatchingObjDoubleConsumer(ObjDoubleConsumer consumer) { + this.consumer = consumer; + } + @Override + public void accept(T t, double value) { + try { + consumer.accept(t, value); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + } + } + } + /** + * Wraps {@link Predicate} in a try-catch block. + *

+ * If {@code predicate} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code predicate} is caught too. + * Wrapper then returns empty {@link OptionalBoolean} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().predicate(t -> my_throwing_lambda).orElse(fallback)} + * + * @param + * see {@link Predicate} + * @param predicate + * the {@link Predicate} to wrap, usually a lambda + * @return wrapper that runs {@code predicate} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalPredicate predicate(Predicate predicate) { + return new CatchingPredicate(predicate); + } + private final class CatchingPredicate implements OptionalPredicate { + private final Predicate predicate; + CatchingPredicate(Predicate predicate) { + this.predicate = predicate; + } + @Override + public OptionalBoolean test(T t) { + try { + return OptionalBoolean.of(predicate.test(t)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalBoolean.empty(); + } + } + } + /** + * Wraps {@link IntPredicate} in a try-catch block. + *

+ * If {@code predicate} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code predicate} is caught too. + * Wrapper then returns empty {@link OptionalBoolean} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromIntPredicate(v -> my_throwing_lambda).orElse(fallback)} + * + * @param predicate + * the {@link IntPredicate} to wrap, usually a lambda + * @return wrapper that runs {@code predicate} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalIntPredicate fromIntPredicate(IntPredicate predicate) { + return new CatchingIntPredicate(predicate); + } + private final class CatchingIntPredicate implements OptionalIntPredicate { + private final IntPredicate predicate; + CatchingIntPredicate(IntPredicate predicate) { + this.predicate = predicate; + } + @Override + public OptionalBoolean test(int value) { + try { + return OptionalBoolean.of(predicate.test(value)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalBoolean.empty(); + } + } + } + /** + * Wraps {@link LongPredicate} in a try-catch block. + *

+ * If {@code predicate} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code predicate} is caught too. + * Wrapper then returns empty {@link OptionalBoolean} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromLongPredicate(v -> my_throwing_lambda).orElse(fallback)} + * + * @param predicate + * the {@link LongPredicate} to wrap, usually a lambda + * @return wrapper that runs {@code predicate} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalLongPredicate fromLongPredicate(LongPredicate predicate) { + return new CatchingLongPredicate(predicate); + } + private final class CatchingLongPredicate implements OptionalLongPredicate { + private final LongPredicate predicate; + CatchingLongPredicate(LongPredicate predicate) { + this.predicate = predicate; + } + @Override + public OptionalBoolean test(long value) { + try { + return OptionalBoolean.of(predicate.test(value)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalBoolean.empty(); + } + } + } + /** + * Wraps {@link DoublePredicate} in a try-catch block. + *

+ * If {@code predicate} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code predicate} is caught too. + * Wrapper then returns empty {@link OptionalBoolean} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromDoublePredicate(v -> my_throwing_lambda).orElse(fallback)} + * + * @param predicate + * the {@link DoublePredicate} to wrap, usually a lambda + * @return wrapper that runs {@code predicate} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalDoublePredicate fromDoublePredicate(DoublePredicate predicate) { + return new CatchingDoublePredicate(predicate); + } + private final class CatchingDoublePredicate implements OptionalDoublePredicate { + private final DoublePredicate predicate; + CatchingDoublePredicate(DoublePredicate predicate) { + this.predicate = predicate; + } + @Override + public OptionalBoolean test(double value) { + try { + return OptionalBoolean.of(predicate.test(value)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalBoolean.empty(); + } + } + } + /** + * Wraps {@link BiPredicate} in a try-catch block. + *

+ * If {@code predicate} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code predicate} is caught too. + * Wrapper then returns empty {@link OptionalBoolean} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromBiPredicate((t, u) -> my_throwing_lambda).orElse(fallback)} + * + * @param + * see {@link BiPredicate} + * @param + * see {@link BiPredicate} + * @param predicate + * the {@link BiPredicate} to wrap, usually a lambda + * @return wrapper that runs {@code predicate} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalBiPredicate fromBiPredicate(BiPredicate predicate) { + return new CatchingBiPredicate(predicate); + } + private final class CatchingBiPredicate implements OptionalBiPredicate { + private final BiPredicate predicate; + CatchingBiPredicate(BiPredicate predicate) { + this.predicate = predicate; + } + @Override + public OptionalBoolean test(T t, U u) { + try { + return OptionalBoolean.of(predicate.test(t, u)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalBoolean.empty(); + } + } + } + /** + * Wraps {@link Function} in a try-catch block. + *

+ * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Wrapper then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().function(t -> my_throwing_lambda).orElse(fallback)} + * + * @param + * see {@link Function} + * @param + * see {@link Function} + * @param function + * the {@link Function} to wrap, usually a lambda + * @return wrapper that runs {@code function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalFunction function(Function function) { + return new CatchingFunction(function); + } + private final class CatchingFunction implements OptionalFunction { + private final Function function; + CatchingFunction(Function function) { + this.function = function; + } + @Override + public Optional apply(T t) { + try { + return Optional.ofNullable(function.apply(t)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return Optional.empty(); + } + } + } + /** + * Wraps {@link ToIntFunction} in a try-catch block. + *

+ * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Wrapper then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromToIntFunction(v -> my_throwing_lambda).orElse(fallback)} + * + * @param + * see {@link ToIntFunction} + * @param function + * the {@link ToIntFunction} to wrap, usually a lambda + * @return wrapper that runs {@code function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalToIntFunction fromToIntFunction(ToIntFunction function) { + return new CatchingToIntFunction(function); + } + private final class CatchingToIntFunction implements OptionalToIntFunction { + private final ToIntFunction function; + CatchingToIntFunction(ToIntFunction function) { + this.function = function; + } + @Override + public OptionalInt apply(T value) { + try { + return OptionalInt.of(function.applyAsInt(value)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalInt.empty(); + } + } + } + /** + * Wraps {@link IntFunction} in a try-catch block. + *

+ * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Wrapper then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromIntFunction(v -> my_throwing_lambda).orElse(fallback)} + * + * @param + * see {@link IntFunction} + * @param function + * the {@link IntFunction} to wrap, usually a lambda + * @return wrapper that runs {@code function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalIntFunction fromIntFunction(IntFunction function) { + return new CatchingIntFunction(function); + } + private final class CatchingIntFunction implements OptionalIntFunction { + private final IntFunction function; + CatchingIntFunction(IntFunction function) { + this.function = function; + } + @Override + public Optional apply(int value) { + try { + return Optional.ofNullable(function.apply(value)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return Optional.empty(); + } + } + } + /** + * Wraps {@link IntToLongFunction} in a try-catch block. + *

+ * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Wrapper then returns empty {@link OptionalLong} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromIntToLongFunction(v -> my_throwing_lambda).orElse(fallback)} + * + * @param function + * the {@link IntToLongFunction} to wrap, usually a lambda + * @return wrapper that runs {@code function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalIntToLongFunction fromIntToLongFunction(IntToLongFunction function) { + return new CatchingIntToLongFunction(function); + } + private final class CatchingIntToLongFunction implements OptionalIntToLongFunction { + private final IntToLongFunction function; + CatchingIntToLongFunction(IntToLongFunction function) { + this.function = function; + } + @Override + public OptionalLong apply(int value) { + try { + return OptionalLong.of(function.applyAsLong(value)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalLong.empty(); + } + } + } + /** + * Wraps {@link IntToDoubleFunction} in a try-catch block. + *

+ * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Wrapper then returns empty {@link OptionalDouble} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromIntToDoubleFunction(v -> my_throwing_lambda).orElse(fallback)} + * + * @param function + * the {@link IntToDoubleFunction} to wrap, usually a lambda + * @return wrapper that runs {@code function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalIntToDoubleFunction fromIntToDoubleFunction(IntToDoubleFunction function) { + return new CatchingIntToDoubleFunction(function); + } + private final class CatchingIntToDoubleFunction implements OptionalIntToDoubleFunction { + private final IntToDoubleFunction function; + CatchingIntToDoubleFunction(IntToDoubleFunction function) { + this.function = function; + } + @Override + public OptionalDouble apply(int value) { + try { + return OptionalDouble.of(function.applyAsDouble(value)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalDouble.empty(); + } + } + } + /** + * Wraps {@link ToLongFunction} in a try-catch block. + *

+ * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Wrapper then returns empty {@link OptionalLong} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromToLongFunction(v -> my_throwing_lambda).orElse(fallback)} + * + * @param + * see {@link ToLongFunction} + * @param function + * the {@link ToLongFunction} to wrap, usually a lambda + * @return wrapper that runs {@code function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalToLongFunction fromToLongFunction(ToLongFunction function) { + return new CatchingToLongFunction(function); + } + private final class CatchingToLongFunction implements OptionalToLongFunction { + private final ToLongFunction function; + CatchingToLongFunction(ToLongFunction function) { + this.function = function; + } + @Override + public OptionalLong apply(T value) { + try { + return OptionalLong.of(function.applyAsLong(value)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalLong.empty(); + } + } + } + /** + * Wraps {@link LongFunction} in a try-catch block. + *

+ * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Wrapper then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromLongFunction(v -> my_throwing_lambda).orElse(fallback)} + * + * @param + * see {@link LongFunction} + * @param function + * the {@link LongFunction} to wrap, usually a lambda + * @return wrapper that runs {@code function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalLongFunction fromLongFunction(LongFunction function) { + return new CatchingLongFunction(function); + } + private final class CatchingLongFunction implements OptionalLongFunction { + private final LongFunction function; + CatchingLongFunction(LongFunction function) { + this.function = function; + } + @Override + public Optional apply(long value) { + try { + return Optional.ofNullable(function.apply(value)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return Optional.empty(); + } + } + } + /** + * Wraps {@link LongToIntFunction} in a try-catch block. + *

+ * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Wrapper then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromLongToIntFunction(v -> my_throwing_lambda).orElse(fallback)} + * + * @param function + * the {@link LongToIntFunction} to wrap, usually a lambda + * @return wrapper that runs {@code function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalLongToIntFunction fromLongToIntFunction(LongToIntFunction function) { + return new CatchingLongToIntFunction(function); + } + private final class CatchingLongToIntFunction implements OptionalLongToIntFunction { + private final LongToIntFunction function; + CatchingLongToIntFunction(LongToIntFunction function) { + this.function = function; + } + @Override + public OptionalInt apply(long value) { + try { + return OptionalInt.of(function.applyAsInt(value)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalInt.empty(); + } + } + } + /** + * Wraps {@link LongToDoubleFunction} in a try-catch block. + *

+ * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Wrapper then returns empty {@link OptionalDouble} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromLongToDoubleFunction(v -> my_throwing_lambda).orElse(fallback)} + * + * @param function + * the {@link LongToDoubleFunction} to wrap, usually a lambda + * @return wrapper that runs {@code function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalLongToDoubleFunction fromLongToDoubleFunction(LongToDoubleFunction function) { + return new CatchingLongToDoubleFunction(function); + } + private final class CatchingLongToDoubleFunction implements OptionalLongToDoubleFunction { + private final LongToDoubleFunction function; + CatchingLongToDoubleFunction(LongToDoubleFunction function) { + this.function = function; + } + @Override + public OptionalDouble apply(long value) { + try { + return OptionalDouble.of(function.applyAsDouble(value)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalDouble.empty(); + } + } + } + /** + * Wraps {@link ToDoubleFunction} in a try-catch block. + *

+ * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Wrapper then returns empty {@link OptionalDouble} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromToDoubleFunction(v -> my_throwing_lambda).orElse(fallback)} + * + * @param + * see {@link ToDoubleFunction} + * @param function + * the {@link ToDoubleFunction} to wrap, usually a lambda + * @return wrapper that runs {@code function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalToDoubleFunction fromToDoubleFunction(ToDoubleFunction function) { + return new CatchingToDoubleFunction(function); + } + private final class CatchingToDoubleFunction implements OptionalToDoubleFunction { + private final ToDoubleFunction function; + CatchingToDoubleFunction(ToDoubleFunction function) { + this.function = function; + } + @Override + public OptionalDouble apply(T value) { + try { + return OptionalDouble.of(function.applyAsDouble(value)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalDouble.empty(); + } + } + } + /** + * Wraps {@link DoubleFunction} in a try-catch block. + *

+ * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Wrapper then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromDoubleFunction(v -> my_throwing_lambda).orElse(fallback)} + * + * @param + * see {@link DoubleFunction} + * @param function + * the {@link DoubleFunction} to wrap, usually a lambda + * @return wrapper that runs {@code function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalDoubleFunction fromDoubleFunction(DoubleFunction function) { + return new CatchingDoubleFunction(function); + } + private final class CatchingDoubleFunction implements OptionalDoubleFunction { + private final DoubleFunction function; + CatchingDoubleFunction(DoubleFunction function) { + this.function = function; + } + @Override + public Optional apply(double value) { + try { + return Optional.ofNullable(function.apply(value)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return Optional.empty(); + } + } + } + /** + * Wraps {@link DoubleToIntFunction} in a try-catch block. + *

+ * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Wrapper then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromDoubleToIntFunction(v -> my_throwing_lambda).orElse(fallback)} + * + * @param function + * the {@link DoubleToIntFunction} to wrap, usually a lambda + * @return wrapper that runs {@code function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalDoubleToIntFunction fromDoubleToIntFunction(DoubleToIntFunction function) { + return new CatchingDoubleToIntFunction(function); + } + private final class CatchingDoubleToIntFunction implements OptionalDoubleToIntFunction { + private final DoubleToIntFunction function; + CatchingDoubleToIntFunction(DoubleToIntFunction function) { + this.function = function; + } + @Override + public OptionalInt apply(double value) { + try { + return OptionalInt.of(function.applyAsInt(value)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalInt.empty(); + } + } + } + /** + * Wraps {@link DoubleToLongFunction} in a try-catch block. + *

+ * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Wrapper then returns empty {@link OptionalLong} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromDoubleToLongFunction(v -> my_throwing_lambda).orElse(fallback)} + * + * @param function + * the {@link DoubleToLongFunction} to wrap, usually a lambda + * @return wrapper that runs {@code function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalDoubleToLongFunction fromDoubleToLongFunction(DoubleToLongFunction function) { + return new CatchingDoubleToLongFunction(function); + } + private final class CatchingDoubleToLongFunction implements OptionalDoubleToLongFunction { + private final DoubleToLongFunction function; + CatchingDoubleToLongFunction(DoubleToLongFunction function) { + this.function = function; + } + @Override + public OptionalLong apply(double value) { + try { + return OptionalLong.of(function.applyAsLong(value)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalLong.empty(); + } + } + } + /** + * Wraps {@link UnaryOperator} in a try-catch block. + *

+ * If {@code operator} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code operator} is caught too. + * Wrapper then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromUnaryOperator(o -> my_throwing_lambda).orElse(fallback)} + * + * @param + * see {@link UnaryOperator} + * @param operator + * the {@link UnaryOperator} to wrap, usually a lambda + * @return wrapper that runs {@code operator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalUnaryOperator fromUnaryOperator(UnaryOperator operator) { + return new CatchingUnaryOperator(operator); + } + private final class CatchingUnaryOperator implements OptionalUnaryOperator { + private final UnaryOperator operator; + CatchingUnaryOperator(UnaryOperator operator) { + this.operator = operator; + } + @Override + public Optional apply(T operand) { + try { + return Optional.ofNullable(operator.apply(operand)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return Optional.empty(); + } + } + } + /** + * Wraps {@link IntUnaryOperator} in a try-catch block. + *

+ * If {@code operator} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code operator} is caught too. + * Wrapper then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromIntUnaryOperator(o -> my_throwing_lambda).orElse(fallback)} + * + * @param operator + * the {@link IntUnaryOperator} to wrap, usually a lambda + * @return wrapper that runs {@code operator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalIntUnaryOperator fromIntUnaryOperator(IntUnaryOperator operator) { + return new CatchingIntUnaryOperator(operator); + } + private final class CatchingIntUnaryOperator implements OptionalIntUnaryOperator { + private final IntUnaryOperator operator; + CatchingIntUnaryOperator(IntUnaryOperator operator) { + this.operator = operator; + } + @Override + public OptionalInt apply(int operand) { + try { + return OptionalInt.of(operator.applyAsInt(operand)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalInt.empty(); + } + } + } + /** + * Wraps {@link LongUnaryOperator} in a try-catch block. + *

+ * If {@code operator} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code operator} is caught too. + * Wrapper then returns empty {@link OptionalLong} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromLongUnaryOperator(o -> my_throwing_lambda).orElse(fallback)} + * + * @param operator + * the {@link LongUnaryOperator} to wrap, usually a lambda + * @return wrapper that runs {@code operator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalLongUnaryOperator fromLongUnaryOperator(LongUnaryOperator operator) { + return new CatchingLongUnaryOperator(operator); + } + private final class CatchingLongUnaryOperator implements OptionalLongUnaryOperator { + private final LongUnaryOperator operator; + CatchingLongUnaryOperator(LongUnaryOperator operator) { + this.operator = operator; + } + @Override + public OptionalLong apply(long operand) { + try { + return OptionalLong.of(operator.applyAsLong(operand)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalLong.empty(); + } + } + } + /** + * Wraps {@link DoubleUnaryOperator} in a try-catch block. + *

+ * If {@code operator} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code operator} is caught too. + * Wrapper then returns empty {@link OptionalDouble} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromDoubleUnaryOperator(o -> my_throwing_lambda).orElse(fallback)} + * + * @param operator + * the {@link DoubleUnaryOperator} to wrap, usually a lambda + * @return wrapper that runs {@code operator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalDoubleUnaryOperator fromDoubleUnaryOperator(DoubleUnaryOperator operator) { + return new CatchingDoubleUnaryOperator(operator); + } + private final class CatchingDoubleUnaryOperator implements OptionalDoubleUnaryOperator { + private final DoubleUnaryOperator operator; + CatchingDoubleUnaryOperator(DoubleUnaryOperator operator) { + this.operator = operator; + } + @Override + public OptionalDouble apply(double operand) { + try { + return OptionalDouble.of(operator.applyAsDouble(operand)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalDouble.empty(); + } + } + } + /** + * Wraps {@link BiFunction} in a try-catch block. + *

+ * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Wrapper then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)} + * + * @param + * see {@link BiFunction} + * @param + * see {@link BiFunction} + * @param + * see {@link BiFunction} + * @param function + * the {@link BiFunction} to wrap, usually a lambda + * @return wrapper that runs {@code function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalBiFunction fromBiFunction(BiFunction function) { + return new CatchingBiFunction(function); + } + private final class CatchingBiFunction implements OptionalBiFunction { + private final BiFunction function; + CatchingBiFunction(BiFunction function) { + this.function = function; + } + @Override + public Optional apply(T t, U u) { + try { + return Optional.ofNullable(function.apply(t, u)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return Optional.empty(); + } + } + } + /** + * Wraps {@link ToIntBiFunction} in a try-catch block. + *

+ * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Wrapper then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromToIntBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)} + * + * @param + * see {@link ToIntBiFunction} + * @param + * see {@link ToIntBiFunction} + * @param function + * the {@link ToIntBiFunction} to wrap, usually a lambda + * @return wrapper that runs {@code function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalToIntBiFunction fromToIntBiFunction(ToIntBiFunction function) { + return new CatchingToIntBiFunction(function); + } + private final class CatchingToIntBiFunction implements OptionalToIntBiFunction { + private final ToIntBiFunction function; + CatchingToIntBiFunction(ToIntBiFunction function) { + this.function = function; + } + @Override + public OptionalInt apply(T t, U u) { + try { + return OptionalInt.of(function.applyAsInt(t, u)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalInt.empty(); + } + } + } + /** + * Wraps {@link ToLongBiFunction} in a try-catch block. + *

+ * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Wrapper then returns empty {@link OptionalLong} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromToLongBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)} + * + * @param + * see {@link ToLongBiFunction} + * @param + * see {@link ToLongBiFunction} + * @param function + * the {@link ToLongBiFunction} to wrap, usually a lambda + * @return wrapper that runs {@code function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalToLongBiFunction fromToLongBiFunction(ToLongBiFunction function) { + return new CatchingToLongBiFunction(function); + } + private final class CatchingToLongBiFunction implements OptionalToLongBiFunction { + private final ToLongBiFunction function; + CatchingToLongBiFunction(ToLongBiFunction function) { + this.function = function; + } + @Override + public OptionalLong apply(T t, U u) { + try { + return OptionalLong.of(function.applyAsLong(t, u)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalLong.empty(); + } + } + } + /** + * Wraps {@link ToDoubleBiFunction} in a try-catch block. + *

+ * If {@code function} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code function} is caught too. + * Wrapper then returns empty {@link OptionalDouble} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromToDoubleBiFunction((t, u) -> my_throwing_lambda).orElse(fallback)} + * + * @param + * see {@link ToDoubleBiFunction} + * @param + * see {@link ToDoubleBiFunction} + * @param function + * the {@link ToDoubleBiFunction} to wrap, usually a lambda + * @return wrapper that runs {@code function} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalToDoubleBiFunction fromToDoubleBiFunction(ToDoubleBiFunction function) { + return new CatchingToDoubleBiFunction(function); + } + private final class CatchingToDoubleBiFunction implements OptionalToDoubleBiFunction { + private final ToDoubleBiFunction function; + CatchingToDoubleBiFunction(ToDoubleBiFunction function) { + this.function = function; + } + @Override + public OptionalDouble apply(T t, U u) { + try { + return OptionalDouble.of(function.applyAsDouble(t, u)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalDouble.empty(); + } + } + } + /** + * Wraps {@link BinaryOperator} in a try-catch block. + *

+ * If {@code operator} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code operator} is caught too. + * Wrapper then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)} + * + * @param + * see {@link BinaryOperator} + * @param operator + * the {@link BinaryOperator} to wrap, usually a lambda + * @return wrapper that runs {@code operator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalBinaryOperator fromBinaryOperator(BinaryOperator operator) { + return new CatchingBinaryOperator(operator); + } + private final class CatchingBinaryOperator implements OptionalBinaryOperator { + private final BinaryOperator operator; + CatchingBinaryOperator(BinaryOperator operator) { + this.operator = operator; + } + @Override + public Optional apply(T left, T right) { + try { + return Optional.ofNullable(operator.apply(left, right)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return Optional.empty(); + } + } + } + /** + * Wraps {@link IntBinaryOperator} in a try-catch block. + *

+ * If {@code operator} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code operator} is caught too. + * Wrapper then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromIntBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)} + * + * @param operator + * the {@link IntBinaryOperator} to wrap, usually a lambda + * @return wrapper that runs {@code operator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalIntBinaryOperator fromIntBinaryOperator(IntBinaryOperator operator) { + return new CatchingIntBinaryOperator(operator); + } + private final class CatchingIntBinaryOperator implements OptionalIntBinaryOperator { + private final IntBinaryOperator operator; + CatchingIntBinaryOperator(IntBinaryOperator operator) { + this.operator = operator; + } + @Override + public OptionalInt apply(int left, int right) { + try { + return OptionalInt.of(operator.applyAsInt(left, right)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalInt.empty(); + } + } + } + /** + * Wraps {@link LongBinaryOperator} in a try-catch block. + *

+ * If {@code operator} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code operator} is caught too. + * Wrapper then returns empty {@link OptionalLong} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromLongBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)} + * + * @param operator + * the {@link LongBinaryOperator} to wrap, usually a lambda + * @return wrapper that runs {@code operator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalLongBinaryOperator fromLongBinaryOperator(LongBinaryOperator operator) { + return new CatchingLongBinaryOperator(operator); + } + private final class CatchingLongBinaryOperator implements OptionalLongBinaryOperator { + private final LongBinaryOperator operator; + CatchingLongBinaryOperator(LongBinaryOperator operator) { + this.operator = operator; + } + @Override + public OptionalLong apply(long left, long right) { + try { + return OptionalLong.of(operator.applyAsLong(left, right)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalLong.empty(); + } + } + } + /** + * Wraps {@link DoubleBinaryOperator} in a try-catch block. + *

+ * If {@code operator} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code operator} is caught too. + * Wrapper then returns empty {@link OptionalDouble} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().fromDoubleBinaryOperator((l, r) -> my_throwing_lambda).orElse(fallback)} + * + * @param operator + * the {@link DoubleBinaryOperator} to wrap, usually a lambda + * @return wrapper that runs {@code operator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalDoubleBinaryOperator fromDoubleBinaryOperator(DoubleBinaryOperator operator) { + return new CatchingDoubleBinaryOperator(operator); + } + private final class CatchingDoubleBinaryOperator implements OptionalDoubleBinaryOperator { + private final DoubleBinaryOperator operator; + CatchingDoubleBinaryOperator(DoubleBinaryOperator operator) { + this.operator = operator; + } + @Override + public OptionalDouble apply(double left, double right) { + try { + return OptionalDouble.of(operator.applyAsDouble(left, right)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalDouble.empty(); + } + } + } + /** + * Wraps {@link Comparator} in a try-catch block. + *

+ * If {@code comparator} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code comparator} is caught too. + * Wrapper then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().comparator((l, r) -> my_throwing_lambda).orElse(fallback)} + * + * @param + * see {@link Comparator} + * @param comparator + * the {@link Comparator} to wrap, usually a lambda + * @return wrapper that runs {@code comparator} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final OptionalComparator comparator(Comparator comparator) { + return new CatchingComparator(comparator); + } + private final class CatchingComparator implements OptionalComparator { + private final Comparator comparator; + CatchingComparator(Comparator comparator) { + this.comparator = comparator; + } + @Override + public OptionalInt compare(T left, T right) { + try { + return OptionalInt.of(comparator.compare(left, right)); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalInt.empty(); + } + } + } + /** + * Wraps {@link CloseableScope} in a try-catch block. + *

+ * If {@code closeable} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code closeable} is caught too. + * Wrapper then completes normally unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code try (var scope = Exceptions.silence().closeable(openSomething()))} + * + * @param closeable + * the {@link CloseableScope} to wrap + * @return wrapper that runs {@code closeable} in a try-catch block + * @see Tutorial + * @see Exceptions + */ + public final CloseableScope closeable(CloseableScope closeable) { + return new CatchingCloseableScope(closeable); + } + private final class CatchingCloseableScope implements CloseableScope { + private final CloseableScope closeable; + CatchingCloseableScope(CloseableScope closeable) { + this.closeable = closeable; + } + @Override + public void close() { + try { + closeable.close(); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + } + } + } + /** + * Runs {@link Runnable} in a try-catch block. + *

+ * If {@code runnable} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code runnable} is caught too. + * This method then completes normally unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().run(() -> my_throwing_lambda)} + * + * @param runnable + * the {@link Runnable} to run, usually a lambda + * @see Tutorial + * @see Exceptions + */ + public final void run(Runnable runnable) { + try { + runnable.run(); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + } + } + /** + * Runs {@link Supplier} in a try-catch block. + *

+ * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * This method then returns empty {@link Optional} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().get(() -> my_throwing_lambda)} + * + * @param + * see {@link Supplier} + * @param supplier + * the {@link Supplier} to run, usually a lambda + * @return an {@link Optional} carrying {@code supplier} result or an empty {@link Optional} if exception was caught + * @see Tutorial + * @see Exceptions + */ + public final Optional get(Supplier supplier) { + try { + return Optional.ofNullable(supplier.get()); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return Optional.empty(); + } + } + /** + * Runs {@link IntSupplier} in a try-catch block. + *

+ * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * This method then returns empty {@link OptionalInt} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().getAsInt(() -> my_throwing_lambda)} + * + * @param supplier + * the {@link IntSupplier} to run, usually a lambda + * @return an {@link OptionalInt} carrying {@code supplier} result or an empty {@link OptionalInt} if exception was caught + * @see Tutorial + * @see Exceptions + */ + public final OptionalInt getAsInt(IntSupplier supplier) { + try { + return OptionalInt.of(supplier.getAsInt()); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalInt.empty(); + } + } + /** + * Runs {@link LongSupplier} in a try-catch block. + *

+ * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * This method then returns empty {@link OptionalLong} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().getAsLong(() -> my_throwing_lambda)} + * + * @param supplier + * the {@link LongSupplier} to run, usually a lambda + * @return an {@link OptionalLong} carrying {@code supplier} result or an empty {@link OptionalLong} if exception was caught + * @see Tutorial + * @see Exceptions + */ + public final OptionalLong getAsLong(LongSupplier supplier) { + try { + return OptionalLong.of(supplier.getAsLong()); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalLong.empty(); + } + } + /** + * Runs {@link DoubleSupplier} in a try-catch block. + *

+ * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * This method then returns empty {@link OptionalDouble} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().getAsDouble(() -> my_throwing_lambda)} + * + * @param supplier + * the {@link DoubleSupplier} to run, usually a lambda + * @return an {@link OptionalDouble} carrying {@code supplier} result or an empty {@link OptionalDouble} if exception was caught + * @see Tutorial + * @see Exceptions + */ + public final OptionalDouble getAsDouble(DoubleSupplier supplier) { + try { + return OptionalDouble.of(supplier.getAsDouble()); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalDouble.empty(); + } + } + /** + * Runs {@link BooleanSupplier} in a try-catch block. + *

+ * If {@code supplier} throws, the exception is caught and passed to {@link #handle(Throwable)}, + * which applies exception handling policy (silence, propagate, log, custom). + * {@link NullPointerException} from {@code null} {@code supplier} is caught too. + * This method then returns empty {@link OptionalBoolean} unless {@link #handle(Throwable)} requests a rethrow. + *

+ * Typical usage: {@code Exceptions.silence().getAsBoolean(() -> my_throwing_lambda)} + * + * @param supplier + * the {@link BooleanSupplier} to run, usually a lambda + * @return an {@link OptionalBoolean} carrying {@code supplier} result or an empty {@link OptionalBoolean} if exception was caught + * @see Tutorial + * @see Exceptions + */ + public final OptionalBoolean getAsBoolean(BooleanSupplier supplier) { + try { + return OptionalBoolean.of(supplier.getAsBoolean()); + } catch (Throwable exception) { + if (!handle(exception)) + throw exception; + return OptionalBoolean.empty(); + } + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultBiFunction.java b/src/main/java/com/machinezoo/noexception/optional/DefaultBiFunction.java index a560606..682cd32 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultBiFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultBiFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultBiFunction implements BiFunction { - private final OptionalBiFunction inner; - private final R result; - public DefaultBiFunction(OptionalBiFunction inner, R result) { - this.inner = inner; - this.result = result; - } - @Override - public R apply(T t, U u) { - return inner.apply(t, u).orElse(result); - } + private final OptionalBiFunction inner; + private final R result; + public DefaultBiFunction(OptionalBiFunction inner, R result) { + this.inner = inner; + this.result = result; + } + @Override + public R apply(T t, U u) { + return inner.apply(t, u).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultBiPredicate.java b/src/main/java/com/machinezoo/noexception/optional/DefaultBiPredicate.java index 6f69eaf..81081e6 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultBiPredicate.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultBiPredicate.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultBiPredicate implements BiPredicate { - private final OptionalBiPredicate inner; - private final boolean result; - public DefaultBiPredicate(OptionalBiPredicate inner, boolean result) { - this.inner = inner; - this.result = result; - } - @Override - public boolean test(T t, U u) { - return inner.test(t, u).orElse(result); - } + private final OptionalBiPredicate inner; + private final boolean result; + public DefaultBiPredicate(OptionalBiPredicate inner, boolean result) { + this.inner = inner; + this.result = result; + } + @Override + public boolean test(T t, U u) { + return inner.test(t, u).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultBinaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/DefaultBinaryOperator.java index f346d22..a7b4e1f 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultBinaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultBinaryOperator.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultBinaryOperator implements BinaryOperator { - private final OptionalBinaryOperator inner; - private final T result; - public DefaultBinaryOperator(OptionalBinaryOperator inner, T result) { - this.inner = inner; - this.result = result; - } - @Override - public T apply(T left, T right) { - return inner.apply(left, right).orElse(result); - } + private final OptionalBinaryOperator inner; + private final T result; + public DefaultBinaryOperator(OptionalBinaryOperator inner, T result) { + this.inner = inner; + this.result = result; + } + @Override + public T apply(T left, T right) { + return inner.apply(left, right).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultBooleanSupplier.java b/src/main/java/com/machinezoo/noexception/optional/DefaultBooleanSupplier.java index 4110f87..bcee6c3 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultBooleanSupplier.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultBooleanSupplier.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultBooleanSupplier implements BooleanSupplier { - private final OptionalBooleanSupplier inner; - private final boolean result; - public DefaultBooleanSupplier(OptionalBooleanSupplier inner, boolean result) { - this.inner = inner; - this.result = result; - } - @Override - public boolean getAsBoolean() { - return inner.get().orElse(result); - } + private final OptionalBooleanSupplier inner; + private final boolean result; + public DefaultBooleanSupplier(OptionalBooleanSupplier inner, boolean result) { + this.inner = inner; + this.result = result; + } + @Override + public boolean getAsBoolean() { + return inner.get().orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultComparator.java b/src/main/java/com/machinezoo/noexception/optional/DefaultComparator.java index 6df51fb..5850191 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultComparator.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultComparator.java @@ -5,14 +5,14 @@ import java.util.*; final class DefaultComparator implements Comparator { - private final OptionalComparator inner; - private final int result; - public DefaultComparator(OptionalComparator inner, int result) { - this.inner = inner; - this.result = result; - } - @Override - public int compare(T left, T right) { - return inner.compare(left, right).orElse(result); - } + private final OptionalComparator inner; + private final int result; + public DefaultComparator(OptionalComparator inner, int result) { + this.inner = inner; + this.result = result; + } + @Override + public int compare(T left, T right) { + return inner.compare(left, right).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleBinaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleBinaryOperator.java index 53c96cd..b9067c3 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleBinaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleBinaryOperator.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultDoubleBinaryOperator implements DoubleBinaryOperator { - private final OptionalDoubleBinaryOperator inner; - private final double result; - public DefaultDoubleBinaryOperator(OptionalDoubleBinaryOperator inner, double result) { - this.inner = inner; - this.result = result; - } - @Override - public double applyAsDouble(double left, double right) { - return inner.apply(left, right).orElse(result); - } + private final OptionalDoubleBinaryOperator inner; + private final double result; + public DefaultDoubleBinaryOperator(OptionalDoubleBinaryOperator inner, double result) { + this.inner = inner; + this.result = result; + } + @Override + public double applyAsDouble(double left, double right) { + return inner.apply(left, right).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleFunction.java b/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleFunction.java index 0102e19..6664c07 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultDoubleFunction implements DoubleFunction { - private final OptionalDoubleFunction inner; - private final R result; - public DefaultDoubleFunction(OptionalDoubleFunction inner, R result) { - this.inner = inner; - this.result = result; - } - @Override - public R apply(double value) { - return inner.apply(value).orElse(result); - } + private final OptionalDoubleFunction inner; + private final R result; + public DefaultDoubleFunction(OptionalDoubleFunction inner, R result) { + this.inner = inner; + this.result = result; + } + @Override + public R apply(double value) { + return inner.apply(value).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultDoublePredicate.java b/src/main/java/com/machinezoo/noexception/optional/DefaultDoublePredicate.java index 4d4edde..6cb4665 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultDoublePredicate.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultDoublePredicate.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultDoublePredicate implements DoublePredicate { - private final OptionalDoublePredicate inner; - private final boolean result; - public DefaultDoublePredicate(OptionalDoublePredicate inner, boolean result) { - this.inner = inner; - this.result = result; - } - @Override - public boolean test(double value) { - return inner.test(value).orElse(result); - } + private final OptionalDoublePredicate inner; + private final boolean result; + public DefaultDoublePredicate(OptionalDoublePredicate inner, boolean result) { + this.inner = inner; + this.result = result; + } + @Override + public boolean test(double value) { + return inner.test(value).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleSupplier.java b/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleSupplier.java index 0a14c3b..338567a 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleSupplier.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleSupplier.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultDoubleSupplier implements DoubleSupplier { - private final OptionalDoubleSupplier inner; - private final double result; - public DefaultDoubleSupplier(OptionalDoubleSupplier inner, double result) { - this.inner = inner; - this.result = result; - } - @Override - public double getAsDouble() { - return inner.get().orElse(result); - } + private final OptionalDoubleSupplier inner; + private final double result; + public DefaultDoubleSupplier(OptionalDoubleSupplier inner, double result) { + this.inner = inner; + this.result = result; + } + @Override + public double getAsDouble() { + return inner.get().orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleToIntFunction.java b/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleToIntFunction.java index 05eb38e..45a0915 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleToIntFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleToIntFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultDoubleToIntFunction implements DoubleToIntFunction { - private final OptionalDoubleToIntFunction inner; - private final int result; - public DefaultDoubleToIntFunction(OptionalDoubleToIntFunction inner, int result) { - this.inner = inner; - this.result = result; - } - @Override - public int applyAsInt(double value) { - return inner.apply(value).orElse(result); - } + private final OptionalDoubleToIntFunction inner; + private final int result; + public DefaultDoubleToIntFunction(OptionalDoubleToIntFunction inner, int result) { + this.inner = inner; + this.result = result; + } + @Override + public int applyAsInt(double value) { + return inner.apply(value).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleToLongFunction.java b/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleToLongFunction.java index 8e89867..d7c1a78 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleToLongFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleToLongFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultDoubleToLongFunction implements DoubleToLongFunction { - private final OptionalDoubleToLongFunction inner; - private final long result; - public DefaultDoubleToLongFunction(OptionalDoubleToLongFunction inner, long result) { - this.inner = inner; - this.result = result; - } - @Override - public long applyAsLong(double value) { - return inner.apply(value).orElse(result); - } + private final OptionalDoubleToLongFunction inner; + private final long result; + public DefaultDoubleToLongFunction(OptionalDoubleToLongFunction inner, long result) { + this.inner = inner; + this.result = result; + } + @Override + public long applyAsLong(double value) { + return inner.apply(value).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleUnaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleUnaryOperator.java index e551b4e..dfb7c92 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleUnaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultDoubleUnaryOperator.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultDoubleUnaryOperator implements DoubleUnaryOperator { - private final OptionalDoubleUnaryOperator inner; - private final double result; - public DefaultDoubleUnaryOperator(OptionalDoubleUnaryOperator inner, double result) { - this.inner = inner; - this.result = result; - } - @Override - public double applyAsDouble(double operand) { - return inner.apply(operand).orElse(result); - } + private final OptionalDoubleUnaryOperator inner; + private final double result; + public DefaultDoubleUnaryOperator(OptionalDoubleUnaryOperator inner, double result) { + this.inner = inner; + this.result = result; + } + @Override + public double applyAsDouble(double operand) { + return inner.apply(operand).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultFunction.java b/src/main/java/com/machinezoo/noexception/optional/DefaultFunction.java index 92d2f22..1b84f84 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultFunction implements Function { - private final OptionalFunction inner; - private final R result; - public DefaultFunction(OptionalFunction inner, R result) { - this.inner = inner; - this.result = result; - } - @Override - public R apply(T t) { - return inner.apply(t).orElse(result); - } + private final OptionalFunction inner; + private final R result; + public DefaultFunction(OptionalFunction inner, R result) { + this.inner = inner; + this.result = result; + } + @Override + public R apply(T t) { + return inner.apply(t).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultIntBinaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/DefaultIntBinaryOperator.java index 20f5cbf..278e967 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultIntBinaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultIntBinaryOperator.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultIntBinaryOperator implements IntBinaryOperator { - private final OptionalIntBinaryOperator inner; - private final int result; - public DefaultIntBinaryOperator(OptionalIntBinaryOperator inner, int result) { - this.inner = inner; - this.result = result; - } - @Override - public int applyAsInt(int left, int right) { - return inner.apply(left, right).orElse(result); - } + private final OptionalIntBinaryOperator inner; + private final int result; + public DefaultIntBinaryOperator(OptionalIntBinaryOperator inner, int result) { + this.inner = inner; + this.result = result; + } + @Override + public int applyAsInt(int left, int right) { + return inner.apply(left, right).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultIntFunction.java b/src/main/java/com/machinezoo/noexception/optional/DefaultIntFunction.java index c5e945f..dedef81 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultIntFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultIntFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultIntFunction implements IntFunction { - private final OptionalIntFunction inner; - private final R result; - public DefaultIntFunction(OptionalIntFunction inner, R result) { - this.inner = inner; - this.result = result; - } - @Override - public R apply(int value) { - return inner.apply(value).orElse(result); - } + private final OptionalIntFunction inner; + private final R result; + public DefaultIntFunction(OptionalIntFunction inner, R result) { + this.inner = inner; + this.result = result; + } + @Override + public R apply(int value) { + return inner.apply(value).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultIntPredicate.java b/src/main/java/com/machinezoo/noexception/optional/DefaultIntPredicate.java index 6c42d51..e7518b9 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultIntPredicate.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultIntPredicate.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultIntPredicate implements IntPredicate { - private final OptionalIntPredicate inner; - private final boolean result; - public DefaultIntPredicate(OptionalIntPredicate inner, boolean result) { - this.inner = inner; - this.result = result; - } - @Override - public boolean test(int value) { - return inner.test(value).orElse(result); - } + private final OptionalIntPredicate inner; + private final boolean result; + public DefaultIntPredicate(OptionalIntPredicate inner, boolean result) { + this.inner = inner; + this.result = result; + } + @Override + public boolean test(int value) { + return inner.test(value).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultIntSupplier.java b/src/main/java/com/machinezoo/noexception/optional/DefaultIntSupplier.java index 8247c8d..9ff1ef7 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultIntSupplier.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultIntSupplier.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultIntSupplier implements IntSupplier { - private final OptionalIntSupplier inner; - private final int result; - public DefaultIntSupplier(OptionalIntSupplier inner, int result) { - this.inner = inner; - this.result = result; - } - @Override - public int getAsInt() { - return inner.get().orElse(result); - } + private final OptionalIntSupplier inner; + private final int result; + public DefaultIntSupplier(OptionalIntSupplier inner, int result) { + this.inner = inner; + this.result = result; + } + @Override + public int getAsInt() { + return inner.get().orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultIntToDoubleFunction.java b/src/main/java/com/machinezoo/noexception/optional/DefaultIntToDoubleFunction.java index cca9962..dc88630 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultIntToDoubleFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultIntToDoubleFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultIntToDoubleFunction implements IntToDoubleFunction { - private final OptionalIntToDoubleFunction inner; - private final double result; - public DefaultIntToDoubleFunction(OptionalIntToDoubleFunction inner, double result) { - this.inner = inner; - this.result = result; - } - @Override - public double applyAsDouble(int value) { - return inner.apply(value).orElse(result); - } + private final OptionalIntToDoubleFunction inner; + private final double result; + public DefaultIntToDoubleFunction(OptionalIntToDoubleFunction inner, double result) { + this.inner = inner; + this.result = result; + } + @Override + public double applyAsDouble(int value) { + return inner.apply(value).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultIntToLongFunction.java b/src/main/java/com/machinezoo/noexception/optional/DefaultIntToLongFunction.java index 5bedb98..501943a 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultIntToLongFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultIntToLongFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultIntToLongFunction implements IntToLongFunction { - private final OptionalIntToLongFunction inner; - private final long result; - public DefaultIntToLongFunction(OptionalIntToLongFunction inner, long result) { - this.inner = inner; - this.result = result; - } - @Override - public long applyAsLong(int value) { - return inner.apply(value).orElse(result); - } + private final OptionalIntToLongFunction inner; + private final long result; + public DefaultIntToLongFunction(OptionalIntToLongFunction inner, long result) { + this.inner = inner; + this.result = result; + } + @Override + public long applyAsLong(int value) { + return inner.apply(value).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultIntUnaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/DefaultIntUnaryOperator.java index f403e34..42cf6d2 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultIntUnaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultIntUnaryOperator.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultIntUnaryOperator implements IntUnaryOperator { - private final OptionalIntUnaryOperator inner; - private final int result; - public DefaultIntUnaryOperator(OptionalIntUnaryOperator inner, int result) { - this.inner = inner; - this.result = result; - } - @Override - public int applyAsInt(int operand) { - return inner.apply(operand).orElse(result); - } + private final OptionalIntUnaryOperator inner; + private final int result; + public DefaultIntUnaryOperator(OptionalIntUnaryOperator inner, int result) { + this.inner = inner; + this.result = result; + } + @Override + public int applyAsInt(int operand) { + return inner.apply(operand).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultLongBinaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/DefaultLongBinaryOperator.java index 45d5262..aceb91d 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultLongBinaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultLongBinaryOperator.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultLongBinaryOperator implements LongBinaryOperator { - private final OptionalLongBinaryOperator inner; - private final long result; - public DefaultLongBinaryOperator(OptionalLongBinaryOperator inner, long result) { - this.inner = inner; - this.result = result; - } - @Override - public long applyAsLong(long left, long right) { - return inner.apply(left, right).orElse(result); - } + private final OptionalLongBinaryOperator inner; + private final long result; + public DefaultLongBinaryOperator(OptionalLongBinaryOperator inner, long result) { + this.inner = inner; + this.result = result; + } + @Override + public long applyAsLong(long left, long right) { + return inner.apply(left, right).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultLongFunction.java b/src/main/java/com/machinezoo/noexception/optional/DefaultLongFunction.java index d1909ff..ae7570c 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultLongFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultLongFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultLongFunction implements LongFunction { - private final OptionalLongFunction inner; - private final R result; - public DefaultLongFunction(OptionalLongFunction inner, R result) { - this.inner = inner; - this.result = result; - } - @Override - public R apply(long value) { - return inner.apply(value).orElse(result); - } + private final OptionalLongFunction inner; + private final R result; + public DefaultLongFunction(OptionalLongFunction inner, R result) { + this.inner = inner; + this.result = result; + } + @Override + public R apply(long value) { + return inner.apply(value).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultLongPredicate.java b/src/main/java/com/machinezoo/noexception/optional/DefaultLongPredicate.java index 37d4097..6003626 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultLongPredicate.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultLongPredicate.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultLongPredicate implements LongPredicate { - private final OptionalLongPredicate inner; - private final boolean result; - public DefaultLongPredicate(OptionalLongPredicate inner, boolean result) { - this.inner = inner; - this.result = result; - } - @Override - public boolean test(long value) { - return inner.test(value).orElse(result); - } + private final OptionalLongPredicate inner; + private final boolean result; + public DefaultLongPredicate(OptionalLongPredicate inner, boolean result) { + this.inner = inner; + this.result = result; + } + @Override + public boolean test(long value) { + return inner.test(value).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultLongSupplier.java b/src/main/java/com/machinezoo/noexception/optional/DefaultLongSupplier.java index cba9f0d..450d47f 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultLongSupplier.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultLongSupplier.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultLongSupplier implements LongSupplier { - private final OptionalLongSupplier inner; - private final long result; - public DefaultLongSupplier(OptionalLongSupplier inner, long result) { - this.inner = inner; - this.result = result; - } - @Override - public long getAsLong() { - return inner.get().orElse(result); - } + private final OptionalLongSupplier inner; + private final long result; + public DefaultLongSupplier(OptionalLongSupplier inner, long result) { + this.inner = inner; + this.result = result; + } + @Override + public long getAsLong() { + return inner.get().orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultLongToDoubleFunction.java b/src/main/java/com/machinezoo/noexception/optional/DefaultLongToDoubleFunction.java index ce4b187..fdb34ab 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultLongToDoubleFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultLongToDoubleFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultLongToDoubleFunction implements LongToDoubleFunction { - private final OptionalLongToDoubleFunction inner; - private final double result; - public DefaultLongToDoubleFunction(OptionalLongToDoubleFunction inner, double result) { - this.inner = inner; - this.result = result; - } - @Override - public double applyAsDouble(long value) { - return inner.apply(value).orElse(result); - } + private final OptionalLongToDoubleFunction inner; + private final double result; + public DefaultLongToDoubleFunction(OptionalLongToDoubleFunction inner, double result) { + this.inner = inner; + this.result = result; + } + @Override + public double applyAsDouble(long value) { + return inner.apply(value).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultLongToIntFunction.java b/src/main/java/com/machinezoo/noexception/optional/DefaultLongToIntFunction.java index d0dd17f..5576136 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultLongToIntFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultLongToIntFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultLongToIntFunction implements LongToIntFunction { - private final OptionalLongToIntFunction inner; - private final int result; - public DefaultLongToIntFunction(OptionalLongToIntFunction inner, int result) { - this.inner = inner; - this.result = result; - } - @Override - public int applyAsInt(long value) { - return inner.apply(value).orElse(result); - } + private final OptionalLongToIntFunction inner; + private final int result; + public DefaultLongToIntFunction(OptionalLongToIntFunction inner, int result) { + this.inner = inner; + this.result = result; + } + @Override + public int applyAsInt(long value) { + return inner.apply(value).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultLongUnaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/DefaultLongUnaryOperator.java index 95aa119..38d04aa 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultLongUnaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultLongUnaryOperator.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultLongUnaryOperator implements LongUnaryOperator { - private final OptionalLongUnaryOperator inner; - private final long result; - public DefaultLongUnaryOperator(OptionalLongUnaryOperator inner, long result) { - this.inner = inner; - this.result = result; - } - @Override - public long applyAsLong(long operand) { - return inner.apply(operand).orElse(result); - } + private final OptionalLongUnaryOperator inner; + private final long result; + public DefaultLongUnaryOperator(OptionalLongUnaryOperator inner, long result) { + this.inner = inner; + this.result = result; + } + @Override + public long applyAsLong(long operand) { + return inner.apply(operand).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultPredicate.java b/src/main/java/com/machinezoo/noexception/optional/DefaultPredicate.java index adaaa50..5ea9d3c 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultPredicate.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultPredicate.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultPredicate implements Predicate { - private final OptionalPredicate inner; - private final boolean result; - public DefaultPredicate(OptionalPredicate inner, boolean result) { - this.inner = inner; - this.result = result; - } - @Override - public boolean test(T t) { - return inner.test(t).orElse(result); - } + private final OptionalPredicate inner; + private final boolean result; + public DefaultPredicate(OptionalPredicate inner, boolean result) { + this.inner = inner; + this.result = result; + } + @Override + public boolean test(T t) { + return inner.test(t).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultSupplier.java b/src/main/java/com/machinezoo/noexception/optional/DefaultSupplier.java index 7f17954..08ec06d 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultSupplier.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultSupplier.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultSupplier implements Supplier { - private final OptionalSupplier inner; - private final T result; - public DefaultSupplier(OptionalSupplier inner, T result) { - this.inner = inner; - this.result = result; - } - @Override - public T get() { - return inner.get().orElse(result); - } + private final OptionalSupplier inner; + private final T result; + public DefaultSupplier(OptionalSupplier inner, T result) { + this.inner = inner; + this.result = result; + } + @Override + public T get() { + return inner.get().orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultToDoubleBiFunction.java b/src/main/java/com/machinezoo/noexception/optional/DefaultToDoubleBiFunction.java index 8ab0884..6318c78 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultToDoubleBiFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultToDoubleBiFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultToDoubleBiFunction implements ToDoubleBiFunction { - private final OptionalToDoubleBiFunction inner; - private final double result; - public DefaultToDoubleBiFunction(OptionalToDoubleBiFunction inner, double result) { - this.inner = inner; - this.result = result; - } - @Override - public double applyAsDouble(T t, U u) { - return inner.apply(t, u).orElse(result); - } + private final OptionalToDoubleBiFunction inner; + private final double result; + public DefaultToDoubleBiFunction(OptionalToDoubleBiFunction inner, double result) { + this.inner = inner; + this.result = result; + } + @Override + public double applyAsDouble(T t, U u) { + return inner.apply(t, u).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultToDoubleFunction.java b/src/main/java/com/machinezoo/noexception/optional/DefaultToDoubleFunction.java index e03d6bc..c8ffc87 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultToDoubleFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultToDoubleFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultToDoubleFunction implements ToDoubleFunction { - private final OptionalToDoubleFunction inner; - private final double result; - public DefaultToDoubleFunction(OptionalToDoubleFunction inner, double result) { - this.inner = inner; - this.result = result; - } - @Override - public double applyAsDouble(T value) { - return inner.apply(value).orElse(result); - } + private final OptionalToDoubleFunction inner; + private final double result; + public DefaultToDoubleFunction(OptionalToDoubleFunction inner, double result) { + this.inner = inner; + this.result = result; + } + @Override + public double applyAsDouble(T value) { + return inner.apply(value).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultToIntBiFunction.java b/src/main/java/com/machinezoo/noexception/optional/DefaultToIntBiFunction.java index aca9f07..9cdf2b0 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultToIntBiFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultToIntBiFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultToIntBiFunction implements ToIntBiFunction { - private final OptionalToIntBiFunction inner; - private final int result; - public DefaultToIntBiFunction(OptionalToIntBiFunction inner, int result) { - this.inner = inner; - this.result = result; - } - @Override - public int applyAsInt(T t, U u) { - return inner.apply(t, u).orElse(result); - } + private final OptionalToIntBiFunction inner; + private final int result; + public DefaultToIntBiFunction(OptionalToIntBiFunction inner, int result) { + this.inner = inner; + this.result = result; + } + @Override + public int applyAsInt(T t, U u) { + return inner.apply(t, u).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultToIntFunction.java b/src/main/java/com/machinezoo/noexception/optional/DefaultToIntFunction.java index a72c4cc..96d7174 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultToIntFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultToIntFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultToIntFunction implements ToIntFunction { - private final OptionalToIntFunction inner; - private final int result; - public DefaultToIntFunction(OptionalToIntFunction inner, int result) { - this.inner = inner; - this.result = result; - } - @Override - public int applyAsInt(T value) { - return inner.apply(value).orElse(result); - } + private final OptionalToIntFunction inner; + private final int result; + public DefaultToIntFunction(OptionalToIntFunction inner, int result) { + this.inner = inner; + this.result = result; + } + @Override + public int applyAsInt(T value) { + return inner.apply(value).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultToLongBiFunction.java b/src/main/java/com/machinezoo/noexception/optional/DefaultToLongBiFunction.java index 0104a18..1bd65f4 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultToLongBiFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultToLongBiFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultToLongBiFunction implements ToLongBiFunction { - private final OptionalToLongBiFunction inner; - private final long result; - public DefaultToLongBiFunction(OptionalToLongBiFunction inner, long result) { - this.inner = inner; - this.result = result; - } - @Override - public long applyAsLong(T t, U u) { - return inner.apply(t, u).orElse(result); - } + private final OptionalToLongBiFunction inner; + private final long result; + public DefaultToLongBiFunction(OptionalToLongBiFunction inner, long result) { + this.inner = inner; + this.result = result; + } + @Override + public long applyAsLong(T t, U u) { + return inner.apply(t, u).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultToLongFunction.java b/src/main/java/com/machinezoo/noexception/optional/DefaultToLongFunction.java index bbcf76d..d549a19 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultToLongFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultToLongFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultToLongFunction implements ToLongFunction { - private final OptionalToLongFunction inner; - private final long result; - public DefaultToLongFunction(OptionalToLongFunction inner, long result) { - this.inner = inner; - this.result = result; - } - @Override - public long applyAsLong(T value) { - return inner.apply(value).orElse(result); - } + private final OptionalToLongFunction inner; + private final long result; + public DefaultToLongFunction(OptionalToLongFunction inner, long result) { + this.inner = inner; + this.result = result; + } + @Override + public long applyAsLong(T value) { + return inner.apply(value).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/DefaultUnaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/DefaultUnaryOperator.java index 11c474f..c2090af 100644 --- a/src/main/java/com/machinezoo/noexception/optional/DefaultUnaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/DefaultUnaryOperator.java @@ -5,14 +5,14 @@ import java.util.function.*; final class DefaultUnaryOperator implements UnaryOperator { - private final OptionalUnaryOperator inner; - private final T result; - public DefaultUnaryOperator(OptionalUnaryOperator inner, T result) { - this.inner = inner; - this.result = result; - } - @Override - public T apply(T operand) { - return inner.apply(operand).orElse(result); - } + private final OptionalUnaryOperator inner; + private final T result; + public DefaultUnaryOperator(OptionalUnaryOperator inner, T result) { + this.inner = inner; + this.result = result; + } + @Override + public T apply(T operand) { + return inner.apply(operand).orElse(result); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackBiFunction.java b/src/main/java/com/machinezoo/noexception/optional/FallbackBiFunction.java index 9563c7c..f380b13 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackBiFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackBiFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackBiFunction implements BiFunction { - private final OptionalBiFunction inner; - private final Supplier source; - public FallbackBiFunction(OptionalBiFunction inner, Supplier source) { - this.inner = inner; - this.source = source; - } - @Override - public R apply(T t, U u) { - return inner.apply(t, u).orElseGet(source); - } + private final OptionalBiFunction inner; + private final Supplier source; + public FallbackBiFunction(OptionalBiFunction inner, Supplier source) { + this.inner = inner; + this.source = source; + } + @Override + public R apply(T t, U u) { + return inner.apply(t, u).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackBiPredicate.java b/src/main/java/com/machinezoo/noexception/optional/FallbackBiPredicate.java index 3996de7..2b54061 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackBiPredicate.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackBiPredicate.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackBiPredicate implements BiPredicate { - private final OptionalBiPredicate inner; - private final BooleanSupplier source; - public FallbackBiPredicate(OptionalBiPredicate inner, BooleanSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public boolean test(T t, U u) { - return inner.test(t, u).orElseGet(source); - } + private final OptionalBiPredicate inner; + private final BooleanSupplier source; + public FallbackBiPredicate(OptionalBiPredicate inner, BooleanSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public boolean test(T t, U u) { + return inner.test(t, u).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackBinaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/FallbackBinaryOperator.java index 2651105..440bdd7 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackBinaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackBinaryOperator.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackBinaryOperator implements BinaryOperator { - private final OptionalBinaryOperator inner; - private final Supplier source; - public FallbackBinaryOperator(OptionalBinaryOperator inner, Supplier source) { - this.inner = inner; - this.source = source; - } - @Override - public T apply(T left, T right) { - return inner.apply(left, right).orElseGet(source); - } + private final OptionalBinaryOperator inner; + private final Supplier source; + public FallbackBinaryOperator(OptionalBinaryOperator inner, Supplier source) { + this.inner = inner; + this.source = source; + } + @Override + public T apply(T left, T right) { + return inner.apply(left, right).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackBooleanSupplier.java b/src/main/java/com/machinezoo/noexception/optional/FallbackBooleanSupplier.java index 317d682..8b5c937 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackBooleanSupplier.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackBooleanSupplier.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackBooleanSupplier implements BooleanSupplier { - private final OptionalBooleanSupplier inner; - private final BooleanSupplier source; - public FallbackBooleanSupplier(OptionalBooleanSupplier inner, BooleanSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public boolean getAsBoolean() { - return inner.get().orElseGet(source); - } + private final OptionalBooleanSupplier inner; + private final BooleanSupplier source; + public FallbackBooleanSupplier(OptionalBooleanSupplier inner, BooleanSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public boolean getAsBoolean() { + return inner.get().orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackComparator.java b/src/main/java/com/machinezoo/noexception/optional/FallbackComparator.java index ef2d80a..a8f5ae5 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackComparator.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackComparator.java @@ -6,14 +6,14 @@ import java.util.function.*; final class FallbackComparator implements Comparator { - private final OptionalComparator inner; - private final IntSupplier source; - public FallbackComparator(OptionalComparator inner, IntSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public int compare(T left, T right) { - return inner.compare(left, right).orElseGet(source); - } + private final OptionalComparator inner; + private final IntSupplier source; + public FallbackComparator(OptionalComparator inner, IntSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public int compare(T left, T right) { + return inner.compare(left, right).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleBinaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleBinaryOperator.java index d3264e7..9585225 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleBinaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleBinaryOperator.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackDoubleBinaryOperator implements DoubleBinaryOperator { - private final OptionalDoubleBinaryOperator inner; - private final DoubleSupplier source; - public FallbackDoubleBinaryOperator(OptionalDoubleBinaryOperator inner, DoubleSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public double applyAsDouble(double left, double right) { - return inner.apply(left, right).orElseGet(source); - } + private final OptionalDoubleBinaryOperator inner; + private final DoubleSupplier source; + public FallbackDoubleBinaryOperator(OptionalDoubleBinaryOperator inner, DoubleSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public double applyAsDouble(double left, double right) { + return inner.apply(left, right).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleFunction.java b/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleFunction.java index 5487745..b140999 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackDoubleFunction implements DoubleFunction { - private final OptionalDoubleFunction inner; - private final Supplier source; - public FallbackDoubleFunction(OptionalDoubleFunction inner, Supplier source) { - this.inner = inner; - this.source = source; - } - @Override - public R apply(double value) { - return inner.apply(value).orElseGet(source); - } + private final OptionalDoubleFunction inner; + private final Supplier source; + public FallbackDoubleFunction(OptionalDoubleFunction inner, Supplier source) { + this.inner = inner; + this.source = source; + } + @Override + public R apply(double value) { + return inner.apply(value).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackDoublePredicate.java b/src/main/java/com/machinezoo/noexception/optional/FallbackDoublePredicate.java index d5eb478..f3e7ce2 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackDoublePredicate.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackDoublePredicate.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackDoublePredicate implements DoublePredicate { - private final OptionalDoublePredicate inner; - private final BooleanSupplier source; - public FallbackDoublePredicate(OptionalDoublePredicate inner, BooleanSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public boolean test(double value) { - return inner.test(value).orElseGet(source); - } + private final OptionalDoublePredicate inner; + private final BooleanSupplier source; + public FallbackDoublePredicate(OptionalDoublePredicate inner, BooleanSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public boolean test(double value) { + return inner.test(value).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleSupplier.java b/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleSupplier.java index 42c56da..2ab6fdc 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleSupplier.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleSupplier.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackDoubleSupplier implements DoubleSupplier { - private final OptionalDoubleSupplier inner; - private final DoubleSupplier source; - public FallbackDoubleSupplier(OptionalDoubleSupplier inner, DoubleSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public double getAsDouble() { - return inner.get().orElseGet(source); - } + private final OptionalDoubleSupplier inner; + private final DoubleSupplier source; + public FallbackDoubleSupplier(OptionalDoubleSupplier inner, DoubleSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public double getAsDouble() { + return inner.get().orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleToIntFunction.java b/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleToIntFunction.java index 0239d07..7c97bf1 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleToIntFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleToIntFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackDoubleToIntFunction implements DoubleToIntFunction { - private final OptionalDoubleToIntFunction inner; - private final IntSupplier source; - public FallbackDoubleToIntFunction(OptionalDoubleToIntFunction inner, IntSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public int applyAsInt(double value) { - return inner.apply(value).orElseGet(source); - } + private final OptionalDoubleToIntFunction inner; + private final IntSupplier source; + public FallbackDoubleToIntFunction(OptionalDoubleToIntFunction inner, IntSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public int applyAsInt(double value) { + return inner.apply(value).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleToLongFunction.java b/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleToLongFunction.java index 4003ae6..df5eb0d 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleToLongFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleToLongFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackDoubleToLongFunction implements DoubleToLongFunction { - private final OptionalDoubleToLongFunction inner; - private final LongSupplier source; - public FallbackDoubleToLongFunction(OptionalDoubleToLongFunction inner, LongSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public long applyAsLong(double value) { - return inner.apply(value).orElseGet(source); - } + private final OptionalDoubleToLongFunction inner; + private final LongSupplier source; + public FallbackDoubleToLongFunction(OptionalDoubleToLongFunction inner, LongSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public long applyAsLong(double value) { + return inner.apply(value).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleUnaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleUnaryOperator.java index d5a4ffc..8119ea1 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleUnaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackDoubleUnaryOperator.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackDoubleUnaryOperator implements DoubleUnaryOperator { - private final OptionalDoubleUnaryOperator inner; - private final DoubleSupplier source; - public FallbackDoubleUnaryOperator(OptionalDoubleUnaryOperator inner, DoubleSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public double applyAsDouble(double operand) { - return inner.apply(operand).orElseGet(source); - } + private final OptionalDoubleUnaryOperator inner; + private final DoubleSupplier source; + public FallbackDoubleUnaryOperator(OptionalDoubleUnaryOperator inner, DoubleSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public double applyAsDouble(double operand) { + return inner.apply(operand).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackFunction.java b/src/main/java/com/machinezoo/noexception/optional/FallbackFunction.java index cf8792e..28d1b94 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackFunction implements Function { - private final OptionalFunction inner; - private final Supplier source; - public FallbackFunction(OptionalFunction inner, Supplier source) { - this.inner = inner; - this.source = source; - } - @Override - public R apply(T t) { - return inner.apply(t).orElseGet(source); - } + private final OptionalFunction inner; + private final Supplier source; + public FallbackFunction(OptionalFunction inner, Supplier source) { + this.inner = inner; + this.source = source; + } + @Override + public R apply(T t) { + return inner.apply(t).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackIntBinaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/FallbackIntBinaryOperator.java index 07644a2..3ca8359 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackIntBinaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackIntBinaryOperator.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackIntBinaryOperator implements IntBinaryOperator { - private final OptionalIntBinaryOperator inner; - private final IntSupplier source; - public FallbackIntBinaryOperator(OptionalIntBinaryOperator inner, IntSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public int applyAsInt(int left, int right) { - return inner.apply(left, right).orElseGet(source); - } + private final OptionalIntBinaryOperator inner; + private final IntSupplier source; + public FallbackIntBinaryOperator(OptionalIntBinaryOperator inner, IntSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public int applyAsInt(int left, int right) { + return inner.apply(left, right).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackIntFunction.java b/src/main/java/com/machinezoo/noexception/optional/FallbackIntFunction.java index d727fae..cbe8740 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackIntFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackIntFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackIntFunction implements IntFunction { - private final OptionalIntFunction inner; - private final Supplier source; - public FallbackIntFunction(OptionalIntFunction inner, Supplier source) { - this.inner = inner; - this.source = source; - } - @Override - public R apply(int value) { - return inner.apply(value).orElseGet(source); - } + private final OptionalIntFunction inner; + private final Supplier source; + public FallbackIntFunction(OptionalIntFunction inner, Supplier source) { + this.inner = inner; + this.source = source; + } + @Override + public R apply(int value) { + return inner.apply(value).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackIntPredicate.java b/src/main/java/com/machinezoo/noexception/optional/FallbackIntPredicate.java index fb5dbff..6a336d1 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackIntPredicate.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackIntPredicate.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackIntPredicate implements IntPredicate { - private final OptionalIntPredicate inner; - private final BooleanSupplier source; - public FallbackIntPredicate(OptionalIntPredicate inner, BooleanSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public boolean test(int value) { - return inner.test(value).orElseGet(source); - } + private final OptionalIntPredicate inner; + private final BooleanSupplier source; + public FallbackIntPredicate(OptionalIntPredicate inner, BooleanSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public boolean test(int value) { + return inner.test(value).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackIntSupplier.java b/src/main/java/com/machinezoo/noexception/optional/FallbackIntSupplier.java index 95578bd..51ee401 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackIntSupplier.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackIntSupplier.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackIntSupplier implements IntSupplier { - private final OptionalIntSupplier inner; - private final IntSupplier source; - public FallbackIntSupplier(OptionalIntSupplier inner, IntSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public int getAsInt() { - return inner.get().orElseGet(source); - } + private final OptionalIntSupplier inner; + private final IntSupplier source; + public FallbackIntSupplier(OptionalIntSupplier inner, IntSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public int getAsInt() { + return inner.get().orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackIntToDoubleFunction.java b/src/main/java/com/machinezoo/noexception/optional/FallbackIntToDoubleFunction.java index 652455b..423bc73 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackIntToDoubleFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackIntToDoubleFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackIntToDoubleFunction implements IntToDoubleFunction { - private final OptionalIntToDoubleFunction inner; - private final DoubleSupplier source; - public FallbackIntToDoubleFunction(OptionalIntToDoubleFunction inner, DoubleSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public double applyAsDouble(int value) { - return inner.apply(value).orElseGet(source); - } + private final OptionalIntToDoubleFunction inner; + private final DoubleSupplier source; + public FallbackIntToDoubleFunction(OptionalIntToDoubleFunction inner, DoubleSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public double applyAsDouble(int value) { + return inner.apply(value).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackIntToLongFunction.java b/src/main/java/com/machinezoo/noexception/optional/FallbackIntToLongFunction.java index d70b9a5..ca69d14 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackIntToLongFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackIntToLongFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackIntToLongFunction implements IntToLongFunction { - private final OptionalIntToLongFunction inner; - private final LongSupplier source; - public FallbackIntToLongFunction(OptionalIntToLongFunction inner, LongSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public long applyAsLong(int value) { - return inner.apply(value).orElseGet(source); - } + private final OptionalIntToLongFunction inner; + private final LongSupplier source; + public FallbackIntToLongFunction(OptionalIntToLongFunction inner, LongSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public long applyAsLong(int value) { + return inner.apply(value).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackIntUnaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/FallbackIntUnaryOperator.java index e46fbe4..cd89b93 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackIntUnaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackIntUnaryOperator.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackIntUnaryOperator implements IntUnaryOperator { - private final OptionalIntUnaryOperator inner; - private final IntSupplier source; - public FallbackIntUnaryOperator(OptionalIntUnaryOperator inner, IntSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public int applyAsInt(int operand) { - return inner.apply(operand).orElseGet(source); - } + private final OptionalIntUnaryOperator inner; + private final IntSupplier source; + public FallbackIntUnaryOperator(OptionalIntUnaryOperator inner, IntSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public int applyAsInt(int operand) { + return inner.apply(operand).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackLongBinaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/FallbackLongBinaryOperator.java index 36b13e9..c268d12 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackLongBinaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackLongBinaryOperator.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackLongBinaryOperator implements LongBinaryOperator { - private final OptionalLongBinaryOperator inner; - private final LongSupplier source; - public FallbackLongBinaryOperator(OptionalLongBinaryOperator inner, LongSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public long applyAsLong(long left, long right) { - return inner.apply(left, right).orElseGet(source); - } + private final OptionalLongBinaryOperator inner; + private final LongSupplier source; + public FallbackLongBinaryOperator(OptionalLongBinaryOperator inner, LongSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public long applyAsLong(long left, long right) { + return inner.apply(left, right).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackLongFunction.java b/src/main/java/com/machinezoo/noexception/optional/FallbackLongFunction.java index 4a49257..73f4053 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackLongFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackLongFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackLongFunction implements LongFunction { - private final OptionalLongFunction inner; - private final Supplier source; - public FallbackLongFunction(OptionalLongFunction inner, Supplier source) { - this.inner = inner; - this.source = source; - } - @Override - public R apply(long value) { - return inner.apply(value).orElseGet(source); - } + private final OptionalLongFunction inner; + private final Supplier source; + public FallbackLongFunction(OptionalLongFunction inner, Supplier source) { + this.inner = inner; + this.source = source; + } + @Override + public R apply(long value) { + return inner.apply(value).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackLongPredicate.java b/src/main/java/com/machinezoo/noexception/optional/FallbackLongPredicate.java index f2529c1..1fd7863 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackLongPredicate.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackLongPredicate.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackLongPredicate implements LongPredicate { - private final OptionalLongPredicate inner; - private final BooleanSupplier source; - public FallbackLongPredicate(OptionalLongPredicate inner, BooleanSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public boolean test(long value) { - return inner.test(value).orElseGet(source); - } + private final OptionalLongPredicate inner; + private final BooleanSupplier source; + public FallbackLongPredicate(OptionalLongPredicate inner, BooleanSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public boolean test(long value) { + return inner.test(value).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackLongSupplier.java b/src/main/java/com/machinezoo/noexception/optional/FallbackLongSupplier.java index 7a963ef..6d9af76 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackLongSupplier.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackLongSupplier.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackLongSupplier implements LongSupplier { - private final OptionalLongSupplier inner; - private final LongSupplier source; - public FallbackLongSupplier(OptionalLongSupplier inner, LongSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public long getAsLong() { - return inner.get().orElseGet(source); - } + private final OptionalLongSupplier inner; + private final LongSupplier source; + public FallbackLongSupplier(OptionalLongSupplier inner, LongSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public long getAsLong() { + return inner.get().orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackLongToDoubleFunction.java b/src/main/java/com/machinezoo/noexception/optional/FallbackLongToDoubleFunction.java index 3a6f41b..e642fdd 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackLongToDoubleFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackLongToDoubleFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackLongToDoubleFunction implements LongToDoubleFunction { - private final OptionalLongToDoubleFunction inner; - private final DoubleSupplier source; - public FallbackLongToDoubleFunction(OptionalLongToDoubleFunction inner, DoubleSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public double applyAsDouble(long value) { - return inner.apply(value).orElseGet(source); - } + private final OptionalLongToDoubleFunction inner; + private final DoubleSupplier source; + public FallbackLongToDoubleFunction(OptionalLongToDoubleFunction inner, DoubleSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public double applyAsDouble(long value) { + return inner.apply(value).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackLongToIntFunction.java b/src/main/java/com/machinezoo/noexception/optional/FallbackLongToIntFunction.java index 9527bb2..20a53fd 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackLongToIntFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackLongToIntFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackLongToIntFunction implements LongToIntFunction { - private final OptionalLongToIntFunction inner; - private final IntSupplier source; - public FallbackLongToIntFunction(OptionalLongToIntFunction inner, IntSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public int applyAsInt(long value) { - return inner.apply(value).orElseGet(source); - } + private final OptionalLongToIntFunction inner; + private final IntSupplier source; + public FallbackLongToIntFunction(OptionalLongToIntFunction inner, IntSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public int applyAsInt(long value) { + return inner.apply(value).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackLongUnaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/FallbackLongUnaryOperator.java index f7f001c..4d83719 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackLongUnaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackLongUnaryOperator.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackLongUnaryOperator implements LongUnaryOperator { - private final OptionalLongUnaryOperator inner; - private final LongSupplier source; - public FallbackLongUnaryOperator(OptionalLongUnaryOperator inner, LongSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public long applyAsLong(long operand) { - return inner.apply(operand).orElseGet(source); - } + private final OptionalLongUnaryOperator inner; + private final LongSupplier source; + public FallbackLongUnaryOperator(OptionalLongUnaryOperator inner, LongSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public long applyAsLong(long operand) { + return inner.apply(operand).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackPredicate.java b/src/main/java/com/machinezoo/noexception/optional/FallbackPredicate.java index 687f589..1584e2e 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackPredicate.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackPredicate.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackPredicate implements Predicate { - private final OptionalPredicate inner; - private final BooleanSupplier source; - public FallbackPredicate(OptionalPredicate inner, BooleanSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public boolean test(T t) { - return inner.test(t).orElseGet(source); - } + private final OptionalPredicate inner; + private final BooleanSupplier source; + public FallbackPredicate(OptionalPredicate inner, BooleanSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public boolean test(T t) { + return inner.test(t).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackSupplier.java b/src/main/java/com/machinezoo/noexception/optional/FallbackSupplier.java index 076de69..e0ef5d6 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackSupplier.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackSupplier.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackSupplier implements Supplier { - private final OptionalSupplier inner; - private final Supplier source; - public FallbackSupplier(OptionalSupplier inner, Supplier source) { - this.inner = inner; - this.source = source; - } - @Override - public T get() { - return inner.get().orElseGet(source); - } + private final OptionalSupplier inner; + private final Supplier source; + public FallbackSupplier(OptionalSupplier inner, Supplier source) { + this.inner = inner; + this.source = source; + } + @Override + public T get() { + return inner.get().orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackToDoubleBiFunction.java b/src/main/java/com/machinezoo/noexception/optional/FallbackToDoubleBiFunction.java index c797c10..fe33aa5 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackToDoubleBiFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackToDoubleBiFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackToDoubleBiFunction implements ToDoubleBiFunction { - private final OptionalToDoubleBiFunction inner; - private final DoubleSupplier source; - public FallbackToDoubleBiFunction(OptionalToDoubleBiFunction inner, DoubleSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public double applyAsDouble(T t, U u) { - return inner.apply(t, u).orElseGet(source); - } + private final OptionalToDoubleBiFunction inner; + private final DoubleSupplier source; + public FallbackToDoubleBiFunction(OptionalToDoubleBiFunction inner, DoubleSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public double applyAsDouble(T t, U u) { + return inner.apply(t, u).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackToDoubleFunction.java b/src/main/java/com/machinezoo/noexception/optional/FallbackToDoubleFunction.java index 4c6237a..b71b7f6 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackToDoubleFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackToDoubleFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackToDoubleFunction implements ToDoubleFunction { - private final OptionalToDoubleFunction inner; - private final DoubleSupplier source; - public FallbackToDoubleFunction(OptionalToDoubleFunction inner, DoubleSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public double applyAsDouble(T value) { - return inner.apply(value).orElseGet(source); - } + private final OptionalToDoubleFunction inner; + private final DoubleSupplier source; + public FallbackToDoubleFunction(OptionalToDoubleFunction inner, DoubleSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public double applyAsDouble(T value) { + return inner.apply(value).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackToIntBiFunction.java b/src/main/java/com/machinezoo/noexception/optional/FallbackToIntBiFunction.java index ca2f207..90003d8 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackToIntBiFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackToIntBiFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackToIntBiFunction implements ToIntBiFunction { - private final OptionalToIntBiFunction inner; - private final IntSupplier source; - public FallbackToIntBiFunction(OptionalToIntBiFunction inner, IntSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public int applyAsInt(T t, U u) { - return inner.apply(t, u).orElseGet(source); - } + private final OptionalToIntBiFunction inner; + private final IntSupplier source; + public FallbackToIntBiFunction(OptionalToIntBiFunction inner, IntSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public int applyAsInt(T t, U u) { + return inner.apply(t, u).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackToIntFunction.java b/src/main/java/com/machinezoo/noexception/optional/FallbackToIntFunction.java index 2b4baa9..8a99872 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackToIntFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackToIntFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackToIntFunction implements ToIntFunction { - private final OptionalToIntFunction inner; - private final IntSupplier source; - public FallbackToIntFunction(OptionalToIntFunction inner, IntSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public int applyAsInt(T value) { - return inner.apply(value).orElseGet(source); - } + private final OptionalToIntFunction inner; + private final IntSupplier source; + public FallbackToIntFunction(OptionalToIntFunction inner, IntSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public int applyAsInt(T value) { + return inner.apply(value).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackToLongBiFunction.java b/src/main/java/com/machinezoo/noexception/optional/FallbackToLongBiFunction.java index 57521a2..c4969e2 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackToLongBiFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackToLongBiFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackToLongBiFunction implements ToLongBiFunction { - private final OptionalToLongBiFunction inner; - private final LongSupplier source; - public FallbackToLongBiFunction(OptionalToLongBiFunction inner, LongSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public long applyAsLong(T t, U u) { - return inner.apply(t, u).orElseGet(source); - } + private final OptionalToLongBiFunction inner; + private final LongSupplier source; + public FallbackToLongBiFunction(OptionalToLongBiFunction inner, LongSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public long applyAsLong(T t, U u) { + return inner.apply(t, u).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackToLongFunction.java b/src/main/java/com/machinezoo/noexception/optional/FallbackToLongFunction.java index f73ca7b..ef726b1 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackToLongFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackToLongFunction.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackToLongFunction implements ToLongFunction { - private final OptionalToLongFunction inner; - private final LongSupplier source; - public FallbackToLongFunction(OptionalToLongFunction inner, LongSupplier source) { - this.inner = inner; - this.source = source; - } - @Override - public long applyAsLong(T value) { - return inner.apply(value).orElseGet(source); - } + private final OptionalToLongFunction inner; + private final LongSupplier source; + public FallbackToLongFunction(OptionalToLongFunction inner, LongSupplier source) { + this.inner = inner; + this.source = source; + } + @Override + public long applyAsLong(T value) { + return inner.apply(value).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/FallbackUnaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/FallbackUnaryOperator.java index 80f6cba..1797a62 100644 --- a/src/main/java/com/machinezoo/noexception/optional/FallbackUnaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/FallbackUnaryOperator.java @@ -5,14 +5,14 @@ import java.util.function.*; final class FallbackUnaryOperator implements UnaryOperator { - private final OptionalUnaryOperator inner; - private final Supplier source; - public FallbackUnaryOperator(OptionalUnaryOperator inner, Supplier source) { - this.inner = inner; - this.source = source; - } - @Override - public T apply(T operand) { - return inner.apply(operand).orElseGet(source); - } + private final OptionalUnaryOperator inner; + private final Supplier source; + public FallbackUnaryOperator(OptionalUnaryOperator inner, Supplier source) { + this.inner = inner; + this.source = source; + } + @Override + public T apply(T operand) { + return inner.apply(operand).orElseGet(source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalBiFunction.java b/src/main/java/com/machinezoo/noexception/optional/OptionalBiFunction.java index bb836c8..8e4798e 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalBiFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalBiFunction.java @@ -23,49 +23,49 @@ */ @FunctionalInterface public interface OptionalBiFunction extends BiFunction> { - /** - * Variation of {@link BiFunction#apply(Object, Object)} that returns {@link Optional}. - * If this {@code OptionalBiFunction} is obtained from {@link ExceptionHandler#fromBiFunction(BiFunction)}, - * the {@link Optional} will be empty only if the underlying {@link BiFunction} throws. - * Otherwise the returned {@link Optional} just wraps the return value of underlying {@link BiFunction} (possibly {@code null}). - * - * @param t - * see {@link BiFunction#apply(Object, Object)} - * @param u - * see {@link BiFunction#apply(Object, Object)} - * @return {@link Optional} typically wrapping return value of {@link BiFunction#apply(Object, Object)}, - * or an empty {@link Optional} (typically signifying an exception) - * @see ExceptionHandler#fromBiFunction(BiFunction) - * @see BiFunction#apply(Object, Object) - */ - @Override - Optional apply(T t, U u); - /** - * Converts this {@code OptionalBiFunction} to plain {@link BiFunction} using default value. - * The returned {@link BiFunction} will unwrap present value from the {@link Optional} if possible, - * or return {@code result} if the {@link Optional} is empty. - * - * @param result - * default value to return instead of an empty {@link Optional} - * @return plain {@link BiFunction} that either unwraps {@link Optional} or returns default value - * @see #orElseGet(Supplier) - * @see Optional#orElse(Object) - */ - default BiFunction orElse(R result) { - return new DefaultBiFunction(this, result); - } - /** - * Converts this {@code OptionalBiFunction} to plain {@link BiFunction} using fallback {@link Supplier}. - * The returned {@link BiFunction} will unwrap present value from the {@link Optional} if possible, - * or fall back to calling {@code source} if the {@link Optional} is empty. - * - * @param source - * {@link Supplier} to query for fallback value when {@link Optional} is empty - * @return plain {@link BiFunction} that either unwraps {@link Optional} or falls back to {@code source} - * @see #orElse(Object) - * @see Optional#orElseGet(Supplier) - */ - default BiFunction orElseGet(Supplier source) { - return new FallbackBiFunction(this, source); - } + /** + * Variation of {@link BiFunction#apply(Object, Object)} that returns {@link Optional}. + * If this {@code OptionalBiFunction} is obtained from {@link ExceptionHandler#fromBiFunction(BiFunction)}, + * the {@link Optional} will be empty only if the underlying {@link BiFunction} throws. + * Otherwise the returned {@link Optional} just wraps the return value of underlying {@link BiFunction} (possibly {@code null}). + * + * @param t + * see {@link BiFunction#apply(Object, Object)} + * @param u + * see {@link BiFunction#apply(Object, Object)} + * @return {@link Optional} typically wrapping return value of {@link BiFunction#apply(Object, Object)}, + * or an empty {@link Optional} (typically signifying an exception) + * @see ExceptionHandler#fromBiFunction(BiFunction) + * @see BiFunction#apply(Object, Object) + */ + @Override + Optional apply(T t, U u); + /** + * Converts this {@code OptionalBiFunction} to plain {@link BiFunction} using default value. + * The returned {@link BiFunction} will unwrap present value from the {@link Optional} if possible, + * or return {@code result} if the {@link Optional} is empty. + * + * @param result + * default value to return instead of an empty {@link Optional} + * @return plain {@link BiFunction} that either unwraps {@link Optional} or returns default value + * @see #orElseGet(Supplier) + * @see Optional#orElse(Object) + */ + default BiFunction orElse(R result) { + return new DefaultBiFunction(this, result); + } + /** + * Converts this {@code OptionalBiFunction} to plain {@link BiFunction} using fallback {@link Supplier}. + * The returned {@link BiFunction} will unwrap present value from the {@link Optional} if possible, + * or fall back to calling {@code source} if the {@link Optional} is empty. + * + * @param source + * {@link Supplier} to query for fallback value when {@link Optional} is empty + * @return plain {@link BiFunction} that either unwraps {@link Optional} or falls back to {@code source} + * @see #orElse(Object) + * @see Optional#orElseGet(Supplier) + */ + default BiFunction orElseGet(Supplier source) { + return new FallbackBiFunction(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalBiPredicate.java b/src/main/java/com/machinezoo/noexception/optional/OptionalBiPredicate.java index 4d3fb4a..5ce9f92 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalBiPredicate.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalBiPredicate.java @@ -20,48 +20,48 @@ */ @FunctionalInterface public interface OptionalBiPredicate { - /** - * Variation of {@link BiPredicate#test(Object, Object)} that returns {@link OptionalBoolean}. - * If this {@code OptionalBiPredicate} is obtained from {@link ExceptionHandler#fromBiPredicate(BiPredicate)}, - * the {@link OptionalBoolean} will be empty only if the underlying {@link BiPredicate} throws. - * Otherwise the returned {@link OptionalBoolean} just wraps the return value of underlying {@link BiPredicate}. - * - * @param t - * see {@link BiPredicate#test(Object, Object)} - * @param u - * see {@link BiPredicate#test(Object, Object)} - * @return {@link OptionalBoolean} typically wrapping return value of {@link BiPredicate#test(Object, Object)}, - * or an empty {@link OptionalBoolean} (typically signifying an exception) - * @see ExceptionHandler#fromBiPredicate(BiPredicate) - * @see BiPredicate#test(Object, Object) - */ - OptionalBoolean test(T t, U u); - /** - * Converts this {@code OptionalBiPredicate} to plain {@link BiPredicate} using default value. - * The returned {@link BiPredicate} will unwrap present value from the {@link OptionalBoolean} if possible, - * or return {@code result} if the {@link OptionalBoolean} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalBoolean} - * @return plain {@link BiPredicate} that either unwraps {@link OptionalBoolean} or returns default value - * @see #orElseGet(BooleanSupplier) - * @see OptionalBoolean#orElse(boolean) - */ - default BiPredicate orElse(boolean result) { - return new DefaultBiPredicate(this, result); - } - /** - * Converts this {@code OptionalBiPredicate} to plain {@link BiPredicate} using fallback {@link BooleanSupplier}. - * The returned {@link BiPredicate} will unwrap present value from the {@link OptionalBoolean} if possible, - * or fall back to calling {@code source} if the {@link OptionalBoolean} is empty. - * - * @param source - * {@link BooleanSupplier} to query for fallback value when {@link OptionalBoolean} is empty - * @return plain {@link BiPredicate} that either unwraps {@link OptionalBoolean} or falls back to {@code source} - * @see #orElse(boolean) - * @see OptionalBoolean#orElseGet(BooleanSupplier) - */ - default BiPredicate orElseGet(BooleanSupplier source) { - return new FallbackBiPredicate(this, source); - } + /** + * Variation of {@link BiPredicate#test(Object, Object)} that returns {@link OptionalBoolean}. + * If this {@code OptionalBiPredicate} is obtained from {@link ExceptionHandler#fromBiPredicate(BiPredicate)}, + * the {@link OptionalBoolean} will be empty only if the underlying {@link BiPredicate} throws. + * Otherwise the returned {@link OptionalBoolean} just wraps the return value of underlying {@link BiPredicate}. + * + * @param t + * see {@link BiPredicate#test(Object, Object)} + * @param u + * see {@link BiPredicate#test(Object, Object)} + * @return {@link OptionalBoolean} typically wrapping return value of {@link BiPredicate#test(Object, Object)}, + * or an empty {@link OptionalBoolean} (typically signifying an exception) + * @see ExceptionHandler#fromBiPredicate(BiPredicate) + * @see BiPredicate#test(Object, Object) + */ + OptionalBoolean test(T t, U u); + /** + * Converts this {@code OptionalBiPredicate} to plain {@link BiPredicate} using default value. + * The returned {@link BiPredicate} will unwrap present value from the {@link OptionalBoolean} if possible, + * or return {@code result} if the {@link OptionalBoolean} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalBoolean} + * @return plain {@link BiPredicate} that either unwraps {@link OptionalBoolean} or returns default value + * @see #orElseGet(BooleanSupplier) + * @see OptionalBoolean#orElse(boolean) + */ + default BiPredicate orElse(boolean result) { + return new DefaultBiPredicate(this, result); + } + /** + * Converts this {@code OptionalBiPredicate} to plain {@link BiPredicate} using fallback {@link BooleanSupplier}. + * The returned {@link BiPredicate} will unwrap present value from the {@link OptionalBoolean} if possible, + * or fall back to calling {@code source} if the {@link OptionalBoolean} is empty. + * + * @param source + * {@link BooleanSupplier} to query for fallback value when {@link OptionalBoolean} is empty + * @return plain {@link BiPredicate} that either unwraps {@link OptionalBoolean} or falls back to {@code source} + * @see #orElse(boolean) + * @see OptionalBoolean#orElseGet(BooleanSupplier) + */ + default BiPredicate orElseGet(BooleanSupplier source) { + return new FallbackBiPredicate(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalBinaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/OptionalBinaryOperator.java index d5d2602..b3f0552 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalBinaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalBinaryOperator.java @@ -19,49 +19,49 @@ */ @FunctionalInterface public interface OptionalBinaryOperator extends BiFunction> { - /** - * Variation of {@link BinaryOperator#apply(Object, Object)} that returns {@link Optional}. - * If this {@code OptionalBinaryOperator} is obtained from {@link ExceptionHandler#fromBinaryOperator(BinaryOperator)}, - * the {@link Optional} will be empty only if the underlying {@link BinaryOperator} throws. - * Otherwise the returned {@link Optional} just wraps the return value of underlying {@link BinaryOperator} (possibly {@code null}). - * - * @param left - * see {@link BinaryOperator#apply(Object, Object)} - * @param right - * see {@link BinaryOperator#apply(Object, Object)} - * @return {@link Optional} typically wrapping return value of {@link BinaryOperator#apply(Object, Object)}, - * or an empty {@link Optional} (typically signifying an exception) - * @see ExceptionHandler#fromBinaryOperator(BinaryOperator) - * @see BinaryOperator#apply(Object, Object) - */ - @Override - Optional apply(T left, T right); - /** - * Converts this {@code OptionalBinaryOperator} to plain {@link BinaryOperator} using default value. - * The returned {@link BinaryOperator} will unwrap present value from the {@link Optional} if possible, - * or return {@code result} if the {@link Optional} is empty. - * - * @param result - * default value to return instead of an empty {@link Optional} - * @return plain {@link BinaryOperator} that either unwraps {@link Optional} or returns default value - * @see #orElseGet(Supplier) - * @see Optional#orElse(Object) - */ - default BinaryOperator orElse(T result) { - return new DefaultBinaryOperator(this, result); - } - /** - * Converts this {@code OptionalBinaryOperator} to plain {@link BinaryOperator} using fallback {@link Supplier}. - * The returned {@link BinaryOperator} will unwrap present value from the {@link Optional} if possible, - * or fall back to calling {@code source} if the {@link Optional} is empty. - * - * @param source - * {@link Supplier} to query for fallback value when {@link Optional} is empty - * @return plain {@link BinaryOperator} that either unwraps {@link Optional} or falls back to {@code source} - * @see #orElse(Object) - * @see Optional#orElseGet(Supplier) - */ - default BinaryOperator orElseGet(Supplier source) { - return new FallbackBinaryOperator(this, source); - } + /** + * Variation of {@link BinaryOperator#apply(Object, Object)} that returns {@link Optional}. + * If this {@code OptionalBinaryOperator} is obtained from {@link ExceptionHandler#fromBinaryOperator(BinaryOperator)}, + * the {@link Optional} will be empty only if the underlying {@link BinaryOperator} throws. + * Otherwise the returned {@link Optional} just wraps the return value of underlying {@link BinaryOperator} (possibly {@code null}). + * + * @param left + * see {@link BinaryOperator#apply(Object, Object)} + * @param right + * see {@link BinaryOperator#apply(Object, Object)} + * @return {@link Optional} typically wrapping return value of {@link BinaryOperator#apply(Object, Object)}, + * or an empty {@link Optional} (typically signifying an exception) + * @see ExceptionHandler#fromBinaryOperator(BinaryOperator) + * @see BinaryOperator#apply(Object, Object) + */ + @Override + Optional apply(T left, T right); + /** + * Converts this {@code OptionalBinaryOperator} to plain {@link BinaryOperator} using default value. + * The returned {@link BinaryOperator} will unwrap present value from the {@link Optional} if possible, + * or return {@code result} if the {@link Optional} is empty. + * + * @param result + * default value to return instead of an empty {@link Optional} + * @return plain {@link BinaryOperator} that either unwraps {@link Optional} or returns default value + * @see #orElseGet(Supplier) + * @see Optional#orElse(Object) + */ + default BinaryOperator orElse(T result) { + return new DefaultBinaryOperator(this, result); + } + /** + * Converts this {@code OptionalBinaryOperator} to plain {@link BinaryOperator} using fallback {@link Supplier}. + * The returned {@link BinaryOperator} will unwrap present value from the {@link Optional} if possible, + * or fall back to calling {@code source} if the {@link Optional} is empty. + * + * @param source + * {@link Supplier} to query for fallback value when {@link Optional} is empty + * @return plain {@link BinaryOperator} that either unwraps {@link Optional} or falls back to {@code source} + * @see #orElse(Object) + * @see Optional#orElseGet(Supplier) + */ + default BinaryOperator orElseGet(Supplier source) { + return new FallbackBinaryOperator(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalBooleanSupplier.java b/src/main/java/com/machinezoo/noexception/optional/OptionalBooleanSupplier.java index c554860..3048d93 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalBooleanSupplier.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalBooleanSupplier.java @@ -16,45 +16,45 @@ */ @FunctionalInterface public interface OptionalBooleanSupplier extends Supplier { - /** - * Variation of {@link BooleanSupplier#getAsBoolean()} that returns {@link OptionalBoolean}. - * If this {@code OptionalBooleanSupplier} is obtained from {@link ExceptionHandler#fromBooleanSupplier(BooleanSupplier)}, - * the {@link OptionalBoolean} will be empty only if the underlying {@link BooleanSupplier} throws. - * Otherwise the returned {@link OptionalBoolean} just wraps the return value of underlying {@link BooleanSupplier}. - * - * @return {@link OptionalBoolean} typically wrapping return value of {@link BooleanSupplier#getAsBoolean()}, - * or an empty {@link OptionalBoolean} (typically signifying an exception) - * @see ExceptionHandler#fromBooleanSupplier(BooleanSupplier) - * @see BooleanSupplier#getAsBoolean() - */ - @Override - OptionalBoolean get(); - /** - * Converts this {@code OptionalBooleanSupplier} to plain {@link BooleanSupplier} using default value. - * The returned {@link BooleanSupplier} will unwrap present value from the {@link OptionalBoolean} if possible, - * or return {@code result} if the {@link OptionalBoolean} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalBoolean} - * @return plain {@link BooleanSupplier} that either unwraps {@link OptionalBoolean} or returns default value - * @see #orElseGet(BooleanSupplier) - * @see OptionalBoolean#orElse(boolean) - */ - default BooleanSupplier orElse(boolean result) { - return new DefaultBooleanSupplier(this, result); - } - /** - * Converts this {@code OptionalBooleanSupplier} to plain {@link BooleanSupplier} using fallback {@link BooleanSupplier}. - * The returned {@link BooleanSupplier} will unwrap present value from the {@link OptionalBoolean} if possible, - * or fall back to calling {@code source} if the {@link OptionalBoolean} is empty. - * - * @param source - * {@link BooleanSupplier} to query for fallback value when {@link OptionalBoolean} is empty - * @return plain {@link BooleanSupplier} that either unwraps {@link OptionalBoolean} or falls back to {@code source} - * @see #orElse(boolean) - * @see OptionalBoolean#orElseGet(BooleanSupplier) - */ - default BooleanSupplier orElseGet(BooleanSupplier source) { - return new FallbackBooleanSupplier(this, source); - } + /** + * Variation of {@link BooleanSupplier#getAsBoolean()} that returns {@link OptionalBoolean}. + * If this {@code OptionalBooleanSupplier} is obtained from {@link ExceptionHandler#fromBooleanSupplier(BooleanSupplier)}, + * the {@link OptionalBoolean} will be empty only if the underlying {@link BooleanSupplier} throws. + * Otherwise the returned {@link OptionalBoolean} just wraps the return value of underlying {@link BooleanSupplier}. + * + * @return {@link OptionalBoolean} typically wrapping return value of {@link BooleanSupplier#getAsBoolean()}, + * or an empty {@link OptionalBoolean} (typically signifying an exception) + * @see ExceptionHandler#fromBooleanSupplier(BooleanSupplier) + * @see BooleanSupplier#getAsBoolean() + */ + @Override + OptionalBoolean get(); + /** + * Converts this {@code OptionalBooleanSupplier} to plain {@link BooleanSupplier} using default value. + * The returned {@link BooleanSupplier} will unwrap present value from the {@link OptionalBoolean} if possible, + * or return {@code result} if the {@link OptionalBoolean} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalBoolean} + * @return plain {@link BooleanSupplier} that either unwraps {@link OptionalBoolean} or returns default value + * @see #orElseGet(BooleanSupplier) + * @see OptionalBoolean#orElse(boolean) + */ + default BooleanSupplier orElse(boolean result) { + return new DefaultBooleanSupplier(this, result); + } + /** + * Converts this {@code OptionalBooleanSupplier} to plain {@link BooleanSupplier} using fallback {@link BooleanSupplier}. + * The returned {@link BooleanSupplier} will unwrap present value from the {@link OptionalBoolean} if possible, + * or fall back to calling {@code source} if the {@link OptionalBoolean} is empty. + * + * @param source + * {@link BooleanSupplier} to query for fallback value when {@link OptionalBoolean} is empty + * @return plain {@link BooleanSupplier} that either unwraps {@link OptionalBoolean} or falls back to {@code source} + * @see #orElse(boolean) + * @see OptionalBoolean#orElseGet(BooleanSupplier) + */ + default BooleanSupplier orElseGet(BooleanSupplier source) { + return new FallbackBooleanSupplier(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalComparator.java b/src/main/java/com/machinezoo/noexception/optional/OptionalComparator.java index 48b652e..70dd99e 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalComparator.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalComparator.java @@ -19,48 +19,48 @@ */ @FunctionalInterface public interface OptionalComparator { - /** - * Variation of {@link Comparator#compare(Object, Object)} that returns {@link OptionalInt}. - * If this {@code OptionalComparator} is obtained from {@link ExceptionHandler#comparator(Comparator)}, - * the {@link OptionalInt} will be empty only if the underlying {@link Comparator} throws. - * Otherwise the returned {@link OptionalInt} just wraps the return value of underlying {@link Comparator}. - * - * @param left - * see {@link Comparator#compare(Object, Object)} - * @param right - * see {@link Comparator#compare(Object, Object)} - * @return {@link OptionalInt} typically wrapping return value of {@link Comparator#compare(Object, Object)}, - * or an empty {@link OptionalInt} (typically signifying an exception) - * @see ExceptionHandler#comparator(Comparator) - * @see Comparator#compare(Object, Object) - */ - OptionalInt compare(T left, T right); - /** - * Converts this {@code OptionalComparator} to plain {@link Comparator} using default value. - * The returned {@link Comparator} will unwrap present value from the {@link OptionalInt} if possible, - * or return {@code result} if the {@link OptionalInt} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalInt} - * @return plain {@link Comparator} that either unwraps {@link OptionalInt} or returns default value - * @see #orElseGet(IntSupplier) - * @see OptionalInt#orElse(int) - */ - default Comparator orElse(int result) { - return new DefaultComparator(this, result); - } - /** - * Converts this {@code OptionalComparator} to plain {@link Comparator} using fallback {@link IntSupplier}. - * The returned {@link Comparator} will unwrap present value from the {@link OptionalInt} if possible, - * or fall back to calling {@code source} if the {@link OptionalInt} is empty. - * - * @param source - * {@link IntSupplier} to query for fallback value when {@link OptionalInt} is empty - * @return plain {@link Comparator} that either unwraps {@link OptionalInt} or falls back to {@code source} - * @see #orElse(int) - * @see OptionalInt#orElseGet(IntSupplier) - */ - default Comparator orElseGet(IntSupplier source) { - return new FallbackComparator(this, source); - } + /** + * Variation of {@link Comparator#compare(Object, Object)} that returns {@link OptionalInt}. + * If this {@code OptionalComparator} is obtained from {@link ExceptionHandler#comparator(Comparator)}, + * the {@link OptionalInt} will be empty only if the underlying {@link Comparator} throws. + * Otherwise the returned {@link OptionalInt} just wraps the return value of underlying {@link Comparator}. + * + * @param left + * see {@link Comparator#compare(Object, Object)} + * @param right + * see {@link Comparator#compare(Object, Object)} + * @return {@link OptionalInt} typically wrapping return value of {@link Comparator#compare(Object, Object)}, + * or an empty {@link OptionalInt} (typically signifying an exception) + * @see ExceptionHandler#comparator(Comparator) + * @see Comparator#compare(Object, Object) + */ + OptionalInt compare(T left, T right); + /** + * Converts this {@code OptionalComparator} to plain {@link Comparator} using default value. + * The returned {@link Comparator} will unwrap present value from the {@link OptionalInt} if possible, + * or return {@code result} if the {@link OptionalInt} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalInt} + * @return plain {@link Comparator} that either unwraps {@link OptionalInt} or returns default value + * @see #orElseGet(IntSupplier) + * @see OptionalInt#orElse(int) + */ + default Comparator orElse(int result) { + return new DefaultComparator(this, result); + } + /** + * Converts this {@code OptionalComparator} to plain {@link Comparator} using fallback {@link IntSupplier}. + * The returned {@link Comparator} will unwrap present value from the {@link OptionalInt} if possible, + * or fall back to calling {@code source} if the {@link OptionalInt} is empty. + * + * @param source + * {@link IntSupplier} to query for fallback value when {@link OptionalInt} is empty + * @return plain {@link Comparator} that either unwraps {@link OptionalInt} or falls back to {@code source} + * @see #orElse(int) + * @see OptionalInt#orElseGet(IntSupplier) + */ + default Comparator orElseGet(IntSupplier source) { + return new FallbackComparator(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleBinaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleBinaryOperator.java index 17a6b63..9968d8e 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleBinaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleBinaryOperator.java @@ -17,48 +17,48 @@ */ @FunctionalInterface public interface OptionalDoubleBinaryOperator { - /** - * Variation of {@link DoubleBinaryOperator#applyAsDouble(double, double)} that returns {@link OptionalDouble}. - * If this {@code OptionalDoubleBinaryOperator} is obtained from {@link ExceptionHandler#fromDoubleBinaryOperator(DoubleBinaryOperator)}, - * the {@link OptionalDouble} will be empty only if the underlying {@link DoubleBinaryOperator} throws. - * Otherwise the returned {@link OptionalDouble} just wraps the return value of underlying {@link DoubleBinaryOperator}. - * - * @param left - * see {@link DoubleBinaryOperator#applyAsDouble(double, double)} - * @param right - * see {@link DoubleBinaryOperator#applyAsDouble(double, double)} - * @return {@link OptionalDouble} typically wrapping return value of {@link DoubleBinaryOperator#applyAsDouble(double, double)}, - * or an empty {@link OptionalDouble} (typically signifying an exception) - * @see ExceptionHandler#fromDoubleBinaryOperator(DoubleBinaryOperator) - * @see DoubleBinaryOperator#applyAsDouble(double, double) - */ - OptionalDouble apply(double left, double right); - /** - * Converts this {@code OptionalDoubleBinaryOperator} to plain {@link DoubleBinaryOperator} using default value. - * The returned {@link DoubleBinaryOperator} will unwrap present value from the {@link OptionalDouble} if possible, - * or return {@code result} if the {@link OptionalDouble} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalDouble} - * @return plain {@link DoubleBinaryOperator} that either unwraps {@link OptionalDouble} or returns default value - * @see #orElseGet(DoubleSupplier) - * @see OptionalDouble#orElse(double) - */ - default DoubleBinaryOperator orElse(double result) { - return new DefaultDoubleBinaryOperator(this, result); - } - /** - * Converts this {@code OptionalDoubleBinaryOperator} to plain {@link DoubleBinaryOperator} using fallback {@link DoubleSupplier}. - * The returned {@link DoubleBinaryOperator} will unwrap present value from the {@link OptionalDouble} if possible, - * or fall back to calling {@code source} if the {@link OptionalDouble} is empty. - * - * @param source - * {@link DoubleSupplier} to query for fallback value when {@link OptionalDouble} is empty - * @return plain {@link DoubleBinaryOperator} that either unwraps {@link OptionalDouble} or falls back to {@code source} - * @see #orElse(double) - * @see OptionalDouble#orElseGet(DoubleSupplier) - */ - default DoubleBinaryOperator orElseGet(DoubleSupplier source) { - return new FallbackDoubleBinaryOperator(this, source); - } + /** + * Variation of {@link DoubleBinaryOperator#applyAsDouble(double, double)} that returns {@link OptionalDouble}. + * If this {@code OptionalDoubleBinaryOperator} is obtained from {@link ExceptionHandler#fromDoubleBinaryOperator(DoubleBinaryOperator)}, + * the {@link OptionalDouble} will be empty only if the underlying {@link DoubleBinaryOperator} throws. + * Otherwise the returned {@link OptionalDouble} just wraps the return value of underlying {@link DoubleBinaryOperator}. + * + * @param left + * see {@link DoubleBinaryOperator#applyAsDouble(double, double)} + * @param right + * see {@link DoubleBinaryOperator#applyAsDouble(double, double)} + * @return {@link OptionalDouble} typically wrapping return value of {@link DoubleBinaryOperator#applyAsDouble(double, double)}, + * or an empty {@link OptionalDouble} (typically signifying an exception) + * @see ExceptionHandler#fromDoubleBinaryOperator(DoubleBinaryOperator) + * @see DoubleBinaryOperator#applyAsDouble(double, double) + */ + OptionalDouble apply(double left, double right); + /** + * Converts this {@code OptionalDoubleBinaryOperator} to plain {@link DoubleBinaryOperator} using default value. + * The returned {@link DoubleBinaryOperator} will unwrap present value from the {@link OptionalDouble} if possible, + * or return {@code result} if the {@link OptionalDouble} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalDouble} + * @return plain {@link DoubleBinaryOperator} that either unwraps {@link OptionalDouble} or returns default value + * @see #orElseGet(DoubleSupplier) + * @see OptionalDouble#orElse(double) + */ + default DoubleBinaryOperator orElse(double result) { + return new DefaultDoubleBinaryOperator(this, result); + } + /** + * Converts this {@code OptionalDoubleBinaryOperator} to plain {@link DoubleBinaryOperator} using fallback {@link DoubleSupplier}. + * The returned {@link DoubleBinaryOperator} will unwrap present value from the {@link OptionalDouble} if possible, + * or fall back to calling {@code source} if the {@link OptionalDouble} is empty. + * + * @param source + * {@link DoubleSupplier} to query for fallback value when {@link OptionalDouble} is empty + * @return plain {@link DoubleBinaryOperator} that either unwraps {@link OptionalDouble} or falls back to {@code source} + * @see #orElse(double) + * @see OptionalDouble#orElseGet(DoubleSupplier) + */ + default DoubleBinaryOperator orElseGet(DoubleSupplier source) { + return new FallbackDoubleBinaryOperator(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleFunction.java b/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleFunction.java index ea5c0ef..43ac445 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleFunction.java @@ -19,47 +19,47 @@ */ @FunctionalInterface public interface OptionalDoubleFunction extends DoubleFunction> { - /** - * Variation of {@link DoubleFunction#apply(double)} that returns {@link Optional}. - * If this {@code OptionalDoubleFunction} is obtained from {@link ExceptionHandler#fromDoubleFunction(DoubleFunction)}, - * the {@link Optional} will be empty only if the underlying {@link DoubleFunction} throws. - * Otherwise the returned {@link Optional} just wraps the return value of underlying {@link DoubleFunction} (possibly {@code null}). - * - * @param value - * see {@link DoubleFunction#apply(double)} - * @return {@link Optional} typically wrapping return value of {@link DoubleFunction#apply(double)}, - * or an empty {@link Optional} (typically signifying an exception) - * @see ExceptionHandler#fromDoubleFunction(DoubleFunction) - * @see DoubleFunction#apply(double) - */ - @Override - Optional apply(double value); - /** - * Converts this {@code OptionalDoubleFunction} to plain {@link DoubleFunction} using default value. - * The returned {@link DoubleFunction} will unwrap present value from the {@link Optional} if possible, - * or return {@code result} if the {@link Optional} is empty. - * - * @param result - * default value to return instead of an empty {@link Optional} - * @return plain {@link DoubleFunction} that either unwraps {@link Optional} or returns default value - * @see #orElseGet(Supplier) - * @see Optional#orElse(Object) - */ - default DoubleFunction orElse(R result) { - return new DefaultDoubleFunction(this, result); - } - /** - * Converts this {@code OptionalDoubleFunction} to plain {@link DoubleFunction} using fallback {@link Supplier}. - * The returned {@link DoubleFunction} will unwrap present value from the {@link Optional} if possible, - * or fall back to calling {@code source} if the {@link Optional} is empty. - * - * @param source - * {@link Supplier} to query for fallback value when {@link Optional} is empty - * @return plain {@link DoubleFunction} that either unwraps {@link Optional} or falls back to {@code source} - * @see #orElse(Object) - * @see Optional#orElseGet(Supplier) - */ - default DoubleFunction orElseGet(Supplier source) { - return new FallbackDoubleFunction(this, source); - } + /** + * Variation of {@link DoubleFunction#apply(double)} that returns {@link Optional}. + * If this {@code OptionalDoubleFunction} is obtained from {@link ExceptionHandler#fromDoubleFunction(DoubleFunction)}, + * the {@link Optional} will be empty only if the underlying {@link DoubleFunction} throws. + * Otherwise the returned {@link Optional} just wraps the return value of underlying {@link DoubleFunction} (possibly {@code null}). + * + * @param value + * see {@link DoubleFunction#apply(double)} + * @return {@link Optional} typically wrapping return value of {@link DoubleFunction#apply(double)}, + * or an empty {@link Optional} (typically signifying an exception) + * @see ExceptionHandler#fromDoubleFunction(DoubleFunction) + * @see DoubleFunction#apply(double) + */ + @Override + Optional apply(double value); + /** + * Converts this {@code OptionalDoubleFunction} to plain {@link DoubleFunction} using default value. + * The returned {@link DoubleFunction} will unwrap present value from the {@link Optional} if possible, + * or return {@code result} if the {@link Optional} is empty. + * + * @param result + * default value to return instead of an empty {@link Optional} + * @return plain {@link DoubleFunction} that either unwraps {@link Optional} or returns default value + * @see #orElseGet(Supplier) + * @see Optional#orElse(Object) + */ + default DoubleFunction orElse(R result) { + return new DefaultDoubleFunction(this, result); + } + /** + * Converts this {@code OptionalDoubleFunction} to plain {@link DoubleFunction} using fallback {@link Supplier}. + * The returned {@link DoubleFunction} will unwrap present value from the {@link Optional} if possible, + * or fall back to calling {@code source} if the {@link Optional} is empty. + * + * @param source + * {@link Supplier} to query for fallback value when {@link Optional} is empty + * @return plain {@link DoubleFunction} that either unwraps {@link Optional} or falls back to {@code source} + * @see #orElse(Object) + * @see Optional#orElseGet(Supplier) + */ + default DoubleFunction orElseGet(Supplier source) { + return new FallbackDoubleFunction(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalDoublePredicate.java b/src/main/java/com/machinezoo/noexception/optional/OptionalDoublePredicate.java index 9ab25e6..9268691 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalDoublePredicate.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalDoublePredicate.java @@ -16,46 +16,46 @@ */ @FunctionalInterface public interface OptionalDoublePredicate { - /** - * Variation of {@link DoublePredicate#test(double)} that returns {@link OptionalBoolean}. - * If this {@code OptionalDoublePredicate} is obtained from {@link ExceptionHandler#fromDoublePredicate(DoublePredicate)}, - * the {@link OptionalBoolean} will be empty only if the underlying {@link DoublePredicate} throws. - * Otherwise the returned {@link OptionalBoolean} just wraps the return value of underlying {@link DoublePredicate}. - * - * @param value - * see {@link DoublePredicate#test(double)} - * @return {@link OptionalBoolean} typically wrapping return value of {@link DoublePredicate#test(double)}, - * or an empty {@link OptionalBoolean} (typically signifying an exception) - * @see ExceptionHandler#fromDoublePredicate(DoublePredicate) - * @see DoublePredicate#test(double) - */ - OptionalBoolean test(double value); - /** - * Converts this {@code OptionalDoublePredicate} to plain {@link DoublePredicate} using default value. - * The returned {@link DoublePredicate} will unwrap present value from the {@link OptionalBoolean} if possible, - * or return {@code result} if the {@link OptionalBoolean} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalBoolean} - * @return plain {@link DoublePredicate} that either unwraps {@link OptionalBoolean} or returns default value - * @see #orElseGet(BooleanSupplier) - * @see OptionalBoolean#orElse(boolean) - */ - default DoublePredicate orElse(boolean result) { - return new DefaultDoublePredicate(this, result); - } - /** - * Converts this {@code OptionalDoublePredicate} to plain {@link DoublePredicate} using fallback {@link BooleanSupplier}. - * The returned {@link DoublePredicate} will unwrap present value from the {@link OptionalBoolean} if possible, - * or fall back to calling {@code source} if the {@link OptionalBoolean} is empty. - * - * @param source - * {@link BooleanSupplier} to query for fallback value when {@link OptionalBoolean} is empty - * @return plain {@link DoublePredicate} that either unwraps {@link OptionalBoolean} or falls back to {@code source} - * @see #orElse(boolean) - * @see OptionalBoolean#orElseGet(BooleanSupplier) - */ - default DoublePredicate orElseGet(BooleanSupplier source) { - return new FallbackDoublePredicate(this, source); - } + /** + * Variation of {@link DoublePredicate#test(double)} that returns {@link OptionalBoolean}. + * If this {@code OptionalDoublePredicate} is obtained from {@link ExceptionHandler#fromDoublePredicate(DoublePredicate)}, + * the {@link OptionalBoolean} will be empty only if the underlying {@link DoublePredicate} throws. + * Otherwise the returned {@link OptionalBoolean} just wraps the return value of underlying {@link DoublePredicate}. + * + * @param value + * see {@link DoublePredicate#test(double)} + * @return {@link OptionalBoolean} typically wrapping return value of {@link DoublePredicate#test(double)}, + * or an empty {@link OptionalBoolean} (typically signifying an exception) + * @see ExceptionHandler#fromDoublePredicate(DoublePredicate) + * @see DoublePredicate#test(double) + */ + OptionalBoolean test(double value); + /** + * Converts this {@code OptionalDoublePredicate} to plain {@link DoublePredicate} using default value. + * The returned {@link DoublePredicate} will unwrap present value from the {@link OptionalBoolean} if possible, + * or return {@code result} if the {@link OptionalBoolean} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalBoolean} + * @return plain {@link DoublePredicate} that either unwraps {@link OptionalBoolean} or returns default value + * @see #orElseGet(BooleanSupplier) + * @see OptionalBoolean#orElse(boolean) + */ + default DoublePredicate orElse(boolean result) { + return new DefaultDoublePredicate(this, result); + } + /** + * Converts this {@code OptionalDoublePredicate} to plain {@link DoublePredicate} using fallback {@link BooleanSupplier}. + * The returned {@link DoublePredicate} will unwrap present value from the {@link OptionalBoolean} if possible, + * or fall back to calling {@code source} if the {@link OptionalBoolean} is empty. + * + * @param source + * {@link BooleanSupplier} to query for fallback value when {@link OptionalBoolean} is empty + * @return plain {@link DoublePredicate} that either unwraps {@link OptionalBoolean} or falls back to {@code source} + * @see #orElse(boolean) + * @see OptionalBoolean#orElseGet(BooleanSupplier) + */ + default DoublePredicate orElseGet(BooleanSupplier source) { + return new FallbackDoublePredicate(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleSupplier.java b/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleSupplier.java index da0eec9..795f1df 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleSupplier.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleSupplier.java @@ -17,45 +17,45 @@ */ @FunctionalInterface public interface OptionalDoubleSupplier extends Supplier { - /** - * Variation of {@link DoubleSupplier#getAsDouble()} that returns {@link OptionalDouble}. - * If this {@code OptionalDoubleSupplier} is obtained from {@link ExceptionHandler#fromDoubleSupplier(DoubleSupplier)}, - * the {@link OptionalDouble} will be empty only if the underlying {@link DoubleSupplier} throws. - * Otherwise the returned {@link OptionalDouble} just wraps the return value of underlying {@link DoubleSupplier}. - * - * @return {@link OptionalDouble} typically wrapping return value of {@link DoubleSupplier#getAsDouble()}, - * or an empty {@link OptionalDouble} (typically signifying an exception) - * @see ExceptionHandler#fromDoubleSupplier(DoubleSupplier) - * @see DoubleSupplier#getAsDouble() - */ - @Override - OptionalDouble get(); - /** - * Converts this {@code OptionalDoubleSupplier} to plain {@link DoubleSupplier} using default value. - * The returned {@link DoubleSupplier} will unwrap present value from the {@link OptionalDouble} if possible, - * or return {@code result} if the {@link OptionalDouble} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalDouble} - * @return plain {@link DoubleSupplier} that either unwraps {@link OptionalDouble} or returns default value - * @see #orElseGet(DoubleSupplier) - * @see OptionalDouble#orElse(double) - */ - default DoubleSupplier orElse(double result) { - return new DefaultDoubleSupplier(this, result); - } - /** - * Converts this {@code OptionalDoubleSupplier} to plain {@link DoubleSupplier} using fallback {@link DoubleSupplier}. - * The returned {@link DoubleSupplier} will unwrap present value from the {@link OptionalDouble} if possible, - * or fall back to calling {@code source} if the {@link OptionalDouble} is empty. - * - * @param source - * {@link DoubleSupplier} to query for fallback value when {@link OptionalDouble} is empty - * @return plain {@link DoubleSupplier} that either unwraps {@link OptionalDouble} or falls back to {@code source} - * @see #orElse(double) - * @see OptionalDouble#orElseGet(DoubleSupplier) - */ - default DoubleSupplier orElseGet(DoubleSupplier source) { - return new FallbackDoubleSupplier(this, source); - } + /** + * Variation of {@link DoubleSupplier#getAsDouble()} that returns {@link OptionalDouble}. + * If this {@code OptionalDoubleSupplier} is obtained from {@link ExceptionHandler#fromDoubleSupplier(DoubleSupplier)}, + * the {@link OptionalDouble} will be empty only if the underlying {@link DoubleSupplier} throws. + * Otherwise the returned {@link OptionalDouble} just wraps the return value of underlying {@link DoubleSupplier}. + * + * @return {@link OptionalDouble} typically wrapping return value of {@link DoubleSupplier#getAsDouble()}, + * or an empty {@link OptionalDouble} (typically signifying an exception) + * @see ExceptionHandler#fromDoubleSupplier(DoubleSupplier) + * @see DoubleSupplier#getAsDouble() + */ + @Override + OptionalDouble get(); + /** + * Converts this {@code OptionalDoubleSupplier} to plain {@link DoubleSupplier} using default value. + * The returned {@link DoubleSupplier} will unwrap present value from the {@link OptionalDouble} if possible, + * or return {@code result} if the {@link OptionalDouble} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalDouble} + * @return plain {@link DoubleSupplier} that either unwraps {@link OptionalDouble} or returns default value + * @see #orElseGet(DoubleSupplier) + * @see OptionalDouble#orElse(double) + */ + default DoubleSupplier orElse(double result) { + return new DefaultDoubleSupplier(this, result); + } + /** + * Converts this {@code OptionalDoubleSupplier} to plain {@link DoubleSupplier} using fallback {@link DoubleSupplier}. + * The returned {@link DoubleSupplier} will unwrap present value from the {@link OptionalDouble} if possible, + * or fall back to calling {@code source} if the {@link OptionalDouble} is empty. + * + * @param source + * {@link DoubleSupplier} to query for fallback value when {@link OptionalDouble} is empty + * @return plain {@link DoubleSupplier} that either unwraps {@link OptionalDouble} or falls back to {@code source} + * @see #orElse(double) + * @see OptionalDouble#orElseGet(DoubleSupplier) + */ + default DoubleSupplier orElseGet(DoubleSupplier source) { + return new FallbackDoubleSupplier(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleToIntFunction.java b/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleToIntFunction.java index b1f4272..7b07c72 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleToIntFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleToIntFunction.java @@ -17,47 +17,47 @@ */ @FunctionalInterface public interface OptionalDoubleToIntFunction extends DoubleFunction { - /** - * Variation of {@link DoubleToIntFunction#applyAsInt(double)} that returns {@link OptionalInt}. - * If this {@code OptionalDoubleToIntFunction} is obtained from {@link ExceptionHandler#fromDoubleToIntFunction(DoubleToIntFunction)}, - * the {@link OptionalInt} will be empty only if the underlying {@link DoubleToIntFunction} throws. - * Otherwise the returned {@link OptionalInt} just wraps the return value of underlying {@link DoubleToIntFunction}. - * - * @param value - * see {@link DoubleToIntFunction#applyAsInt(double)} - * @return {@link OptionalInt} typically wrapping return value of {@link DoubleToIntFunction#applyAsInt(double)}, - * or an empty {@link OptionalInt} (typically signifying an exception) - * @see ExceptionHandler#fromDoubleToIntFunction(DoubleToIntFunction) - * @see DoubleToIntFunction#applyAsInt(double) - */ - @Override - OptionalInt apply(double value); - /** - * Converts this {@code OptionalDoubleToIntFunction} to plain {@link DoubleToIntFunction} using default value. - * The returned {@link DoubleToIntFunction} will unwrap present value from the {@link OptionalInt} if possible, - * or return {@code result} if the {@link OptionalInt} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalInt} - * @return plain {@link DoubleToIntFunction} that either unwraps {@link OptionalInt} or returns default value - * @see #orElseGet(IntSupplier) - * @see OptionalInt#orElse(int) - */ - default DoubleToIntFunction orElse(int result) { - return new DefaultDoubleToIntFunction(this, result); - } - /** - * Converts this {@code OptionalDoubleToIntFunction} to plain {@link DoubleToIntFunction} using fallback {@link IntSupplier}. - * The returned {@link DoubleToIntFunction} will unwrap present value from the {@link OptionalInt} if possible, - * or fall back to calling {@code source} if the {@link OptionalInt} is empty. - * - * @param source - * {@link IntSupplier} to query for fallback value when {@link OptionalInt} is empty - * @return plain {@link DoubleToIntFunction} that either unwraps {@link OptionalInt} or falls back to {@code source} - * @see #orElse(int) - * @see OptionalInt#orElseGet(IntSupplier) - */ - default DoubleToIntFunction orElseGet(IntSupplier source) { - return new FallbackDoubleToIntFunction(this, source); - } + /** + * Variation of {@link DoubleToIntFunction#applyAsInt(double)} that returns {@link OptionalInt}. + * If this {@code OptionalDoubleToIntFunction} is obtained from {@link ExceptionHandler#fromDoubleToIntFunction(DoubleToIntFunction)}, + * the {@link OptionalInt} will be empty only if the underlying {@link DoubleToIntFunction} throws. + * Otherwise the returned {@link OptionalInt} just wraps the return value of underlying {@link DoubleToIntFunction}. + * + * @param value + * see {@link DoubleToIntFunction#applyAsInt(double)} + * @return {@link OptionalInt} typically wrapping return value of {@link DoubleToIntFunction#applyAsInt(double)}, + * or an empty {@link OptionalInt} (typically signifying an exception) + * @see ExceptionHandler#fromDoubleToIntFunction(DoubleToIntFunction) + * @see DoubleToIntFunction#applyAsInt(double) + */ + @Override + OptionalInt apply(double value); + /** + * Converts this {@code OptionalDoubleToIntFunction} to plain {@link DoubleToIntFunction} using default value. + * The returned {@link DoubleToIntFunction} will unwrap present value from the {@link OptionalInt} if possible, + * or return {@code result} if the {@link OptionalInt} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalInt} + * @return plain {@link DoubleToIntFunction} that either unwraps {@link OptionalInt} or returns default value + * @see #orElseGet(IntSupplier) + * @see OptionalInt#orElse(int) + */ + default DoubleToIntFunction orElse(int result) { + return new DefaultDoubleToIntFunction(this, result); + } + /** + * Converts this {@code OptionalDoubleToIntFunction} to plain {@link DoubleToIntFunction} using fallback {@link IntSupplier}. + * The returned {@link DoubleToIntFunction} will unwrap present value from the {@link OptionalInt} if possible, + * or fall back to calling {@code source} if the {@link OptionalInt} is empty. + * + * @param source + * {@link IntSupplier} to query for fallback value when {@link OptionalInt} is empty + * @return plain {@link DoubleToIntFunction} that either unwraps {@link OptionalInt} or falls back to {@code source} + * @see #orElse(int) + * @see OptionalInt#orElseGet(IntSupplier) + */ + default DoubleToIntFunction orElseGet(IntSupplier source) { + return new FallbackDoubleToIntFunction(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleToLongFunction.java b/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleToLongFunction.java index a4629f8..473b87f 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleToLongFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleToLongFunction.java @@ -17,47 +17,47 @@ */ @FunctionalInterface public interface OptionalDoubleToLongFunction extends DoubleFunction { - /** - * Variation of {@link DoubleToLongFunction#applyAsLong(double)} that returns {@link OptionalLong}. - * If this {@code OptionalDoubleToLongFunction} is obtained from {@link ExceptionHandler#fromDoubleToLongFunction(DoubleToLongFunction)}, - * the {@link OptionalLong} will be empty only if the underlying {@link DoubleToLongFunction} throws. - * Otherwise the returned {@link OptionalLong} just wraps the return value of underlying {@link DoubleToLongFunction}. - * - * @param value - * see {@link DoubleToLongFunction#applyAsLong(double)} - * @return {@link OptionalLong} typically wrapping return value of {@link DoubleToLongFunction#applyAsLong(double)}, - * or an empty {@link OptionalLong} (typically signifying an exception) - * @see ExceptionHandler#fromDoubleToLongFunction(DoubleToLongFunction) - * @see DoubleToLongFunction#applyAsLong(double) - */ - @Override - OptionalLong apply(double value); - /** - * Converts this {@code OptionalDoubleToLongFunction} to plain {@link DoubleToLongFunction} using default value. - * The returned {@link DoubleToLongFunction} will unwrap present value from the {@link OptionalLong} if possible, - * or return {@code result} if the {@link OptionalLong} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalLong} - * @return plain {@link DoubleToLongFunction} that either unwraps {@link OptionalLong} or returns default value - * @see #orElseGet(LongSupplier) - * @see OptionalLong#orElse(long) - */ - default DoubleToLongFunction orElse(long result) { - return new DefaultDoubleToLongFunction(this, result); - } - /** - * Converts this {@code OptionalDoubleToLongFunction} to plain {@link DoubleToLongFunction} using fallback {@link LongSupplier}. - * The returned {@link DoubleToLongFunction} will unwrap present value from the {@link OptionalLong} if possible, - * or fall back to calling {@code source} if the {@link OptionalLong} is empty. - * - * @param source - * {@link LongSupplier} to query for fallback value when {@link OptionalLong} is empty - * @return plain {@link DoubleToLongFunction} that either unwraps {@link OptionalLong} or falls back to {@code source} - * @see #orElse(long) - * @see OptionalLong#orElseGet(LongSupplier) - */ - default DoubleToLongFunction orElseGet(LongSupplier source) { - return new FallbackDoubleToLongFunction(this, source); - } + /** + * Variation of {@link DoubleToLongFunction#applyAsLong(double)} that returns {@link OptionalLong}. + * If this {@code OptionalDoubleToLongFunction} is obtained from {@link ExceptionHandler#fromDoubleToLongFunction(DoubleToLongFunction)}, + * the {@link OptionalLong} will be empty only if the underlying {@link DoubleToLongFunction} throws. + * Otherwise the returned {@link OptionalLong} just wraps the return value of underlying {@link DoubleToLongFunction}. + * + * @param value + * see {@link DoubleToLongFunction#applyAsLong(double)} + * @return {@link OptionalLong} typically wrapping return value of {@link DoubleToLongFunction#applyAsLong(double)}, + * or an empty {@link OptionalLong} (typically signifying an exception) + * @see ExceptionHandler#fromDoubleToLongFunction(DoubleToLongFunction) + * @see DoubleToLongFunction#applyAsLong(double) + */ + @Override + OptionalLong apply(double value); + /** + * Converts this {@code OptionalDoubleToLongFunction} to plain {@link DoubleToLongFunction} using default value. + * The returned {@link DoubleToLongFunction} will unwrap present value from the {@link OptionalLong} if possible, + * or return {@code result} if the {@link OptionalLong} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalLong} + * @return plain {@link DoubleToLongFunction} that either unwraps {@link OptionalLong} or returns default value + * @see #orElseGet(LongSupplier) + * @see OptionalLong#orElse(long) + */ + default DoubleToLongFunction orElse(long result) { + return new DefaultDoubleToLongFunction(this, result); + } + /** + * Converts this {@code OptionalDoubleToLongFunction} to plain {@link DoubleToLongFunction} using fallback {@link LongSupplier}. + * The returned {@link DoubleToLongFunction} will unwrap present value from the {@link OptionalLong} if possible, + * or fall back to calling {@code source} if the {@link OptionalLong} is empty. + * + * @param source + * {@link LongSupplier} to query for fallback value when {@link OptionalLong} is empty + * @return plain {@link DoubleToLongFunction} that either unwraps {@link OptionalLong} or falls back to {@code source} + * @see #orElse(long) + * @see OptionalLong#orElseGet(LongSupplier) + */ + default DoubleToLongFunction orElseGet(LongSupplier source) { + return new FallbackDoubleToLongFunction(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleUnaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleUnaryOperator.java index 7781872..9b99eca 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleUnaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalDoubleUnaryOperator.java @@ -17,47 +17,47 @@ */ @FunctionalInterface public interface OptionalDoubleUnaryOperator extends DoubleFunction { - /** - * Variation of {@link DoubleUnaryOperator#applyAsDouble(double)} that returns {@link OptionalDouble}. - * If this {@code OptionalDoubleUnaryOperator} is obtained from {@link ExceptionHandler#fromDoubleUnaryOperator(DoubleUnaryOperator)}, - * the {@link OptionalDouble} will be empty only if the underlying {@link DoubleUnaryOperator} throws. - * Otherwise the returned {@link OptionalDouble} just wraps the return value of underlying {@link DoubleUnaryOperator}. - * - * @param operand - * see {@link DoubleUnaryOperator#applyAsDouble(double)} - * @return {@link OptionalDouble} typically wrapping return value of {@link DoubleUnaryOperator#applyAsDouble(double)}, - * or an empty {@link OptionalDouble} (typically signifying an exception) - * @see ExceptionHandler#fromDoubleUnaryOperator(DoubleUnaryOperator) - * @see DoubleUnaryOperator#applyAsDouble(double) - */ - @Override - OptionalDouble apply(double operand); - /** - * Converts this {@code OptionalDoubleUnaryOperator} to plain {@link DoubleUnaryOperator} using default value. - * The returned {@link DoubleUnaryOperator} will unwrap present value from the {@link OptionalDouble} if possible, - * or return {@code result} if the {@link OptionalDouble} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalDouble} - * @return plain {@link DoubleUnaryOperator} that either unwraps {@link OptionalDouble} or returns default value - * @see #orElseGet(DoubleSupplier) - * @see OptionalDouble#orElse(double) - */ - default DoubleUnaryOperator orElse(double result) { - return new DefaultDoubleUnaryOperator(this, result); - } - /** - * Converts this {@code OptionalDoubleUnaryOperator} to plain {@link DoubleUnaryOperator} using fallback {@link DoubleSupplier}. - * The returned {@link DoubleUnaryOperator} will unwrap present value from the {@link OptionalDouble} if possible, - * or fall back to calling {@code source} if the {@link OptionalDouble} is empty. - * - * @param source - * {@link DoubleSupplier} to query for fallback value when {@link OptionalDouble} is empty - * @return plain {@link DoubleUnaryOperator} that either unwraps {@link OptionalDouble} or falls back to {@code source} - * @see #orElse(double) - * @see OptionalDouble#orElseGet(DoubleSupplier) - */ - default DoubleUnaryOperator orElseGet(DoubleSupplier source) { - return new FallbackDoubleUnaryOperator(this, source); - } + /** + * Variation of {@link DoubleUnaryOperator#applyAsDouble(double)} that returns {@link OptionalDouble}. + * If this {@code OptionalDoubleUnaryOperator} is obtained from {@link ExceptionHandler#fromDoubleUnaryOperator(DoubleUnaryOperator)}, + * the {@link OptionalDouble} will be empty only if the underlying {@link DoubleUnaryOperator} throws. + * Otherwise the returned {@link OptionalDouble} just wraps the return value of underlying {@link DoubleUnaryOperator}. + * + * @param operand + * see {@link DoubleUnaryOperator#applyAsDouble(double)} + * @return {@link OptionalDouble} typically wrapping return value of {@link DoubleUnaryOperator#applyAsDouble(double)}, + * or an empty {@link OptionalDouble} (typically signifying an exception) + * @see ExceptionHandler#fromDoubleUnaryOperator(DoubleUnaryOperator) + * @see DoubleUnaryOperator#applyAsDouble(double) + */ + @Override + OptionalDouble apply(double operand); + /** + * Converts this {@code OptionalDoubleUnaryOperator} to plain {@link DoubleUnaryOperator} using default value. + * The returned {@link DoubleUnaryOperator} will unwrap present value from the {@link OptionalDouble} if possible, + * or return {@code result} if the {@link OptionalDouble} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalDouble} + * @return plain {@link DoubleUnaryOperator} that either unwraps {@link OptionalDouble} or returns default value + * @see #orElseGet(DoubleSupplier) + * @see OptionalDouble#orElse(double) + */ + default DoubleUnaryOperator orElse(double result) { + return new DefaultDoubleUnaryOperator(this, result); + } + /** + * Converts this {@code OptionalDoubleUnaryOperator} to plain {@link DoubleUnaryOperator} using fallback {@link DoubleSupplier}. + * The returned {@link DoubleUnaryOperator} will unwrap present value from the {@link OptionalDouble} if possible, + * or fall back to calling {@code source} if the {@link OptionalDouble} is empty. + * + * @param source + * {@link DoubleSupplier} to query for fallback value when {@link OptionalDouble} is empty + * @return plain {@link DoubleUnaryOperator} that either unwraps {@link OptionalDouble} or falls back to {@code source} + * @see #orElse(double) + * @see OptionalDouble#orElseGet(DoubleSupplier) + */ + default DoubleUnaryOperator orElseGet(DoubleSupplier source) { + return new FallbackDoubleUnaryOperator(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalFunction.java b/src/main/java/com/machinezoo/noexception/optional/OptionalFunction.java index ea52c23..122fdb2 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalFunction.java @@ -21,47 +21,47 @@ */ @FunctionalInterface public interface OptionalFunction extends Function> { - /** - * Variation of {@link Function#apply(Object)} that returns {@link Optional}. - * If this {@code OptionalFunction} is obtained from {@link ExceptionHandler#function(Function)}, - * the {@link Optional} will be empty only if the underlying {@link Function} throws. - * Otherwise the returned {@link Optional} just wraps the return value of underlying {@link Function} (possibly {@code null}). - * - * @param t - * see {@link Function#apply(Object)} - * @return {@link Optional} typically wrapping return value of {@link Function#apply(Object)}, - * or an empty {@link Optional} (typically signifying an exception) - * @see ExceptionHandler#function(Function) - * @see Function#apply(Object) - */ - @Override - Optional apply(T t); - /** - * Converts this {@code OptionalFunction} to plain {@link Function} using default value. - * The returned {@link Function} will unwrap present value from the {@link Optional} if possible, - * or return {@code result} if the {@link Optional} is empty. - * - * @param result - * default value to return instead of an empty {@link Optional} - * @return plain {@link Function} that either unwraps {@link Optional} or returns default value - * @see #orElseGet(Supplier) - * @see Optional#orElse(Object) - */ - default Function orElse(R result) { - return new DefaultFunction(this, result); - } - /** - * Converts this {@code OptionalFunction} to plain {@link Function} using fallback {@link Supplier}. - * The returned {@link Function} will unwrap present value from the {@link Optional} if possible, - * or fall back to calling {@code source} if the {@link Optional} is empty. - * - * @param source - * {@link Supplier} to query for fallback value when {@link Optional} is empty - * @return plain {@link Function} that either unwraps {@link Optional} or falls back to {@code source} - * @see #orElse(Object) - * @see Optional#orElseGet(Supplier) - */ - default Function orElseGet(Supplier source) { - return new FallbackFunction(this, source); - } + /** + * Variation of {@link Function#apply(Object)} that returns {@link Optional}. + * If this {@code OptionalFunction} is obtained from {@link ExceptionHandler#function(Function)}, + * the {@link Optional} will be empty only if the underlying {@link Function} throws. + * Otherwise the returned {@link Optional} just wraps the return value of underlying {@link Function} (possibly {@code null}). + * + * @param t + * see {@link Function#apply(Object)} + * @return {@link Optional} typically wrapping return value of {@link Function#apply(Object)}, + * or an empty {@link Optional} (typically signifying an exception) + * @see ExceptionHandler#function(Function) + * @see Function#apply(Object) + */ + @Override + Optional apply(T t); + /** + * Converts this {@code OptionalFunction} to plain {@link Function} using default value. + * The returned {@link Function} will unwrap present value from the {@link Optional} if possible, + * or return {@code result} if the {@link Optional} is empty. + * + * @param result + * default value to return instead of an empty {@link Optional} + * @return plain {@link Function} that either unwraps {@link Optional} or returns default value + * @see #orElseGet(Supplier) + * @see Optional#orElse(Object) + */ + default Function orElse(R result) { + return new DefaultFunction(this, result); + } + /** + * Converts this {@code OptionalFunction} to plain {@link Function} using fallback {@link Supplier}. + * The returned {@link Function} will unwrap present value from the {@link Optional} if possible, + * or fall back to calling {@code source} if the {@link Optional} is empty. + * + * @param source + * {@link Supplier} to query for fallback value when {@link Optional} is empty + * @return plain {@link Function} that either unwraps {@link Optional} or falls back to {@code source} + * @see #orElse(Object) + * @see Optional#orElseGet(Supplier) + */ + default Function orElseGet(Supplier source) { + return new FallbackFunction(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalIntBinaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/OptionalIntBinaryOperator.java index 53af60b..2c70724 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalIntBinaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalIntBinaryOperator.java @@ -17,48 +17,48 @@ */ @FunctionalInterface public interface OptionalIntBinaryOperator { - /** - * Variation of {@link IntBinaryOperator#applyAsInt(int, int)} that returns {@link OptionalInt}. - * If this {@code OptionalIntBinaryOperator} is obtained from {@link ExceptionHandler#fromIntBinaryOperator(IntBinaryOperator)}, - * the {@link OptionalInt} will be empty only if the underlying {@link IntBinaryOperator} throws. - * Otherwise the returned {@link OptionalInt} just wraps the return value of underlying {@link IntBinaryOperator}. - * - * @param left - * see {@link IntBinaryOperator#applyAsInt(int, int)} - * @param right - * see {@link IntBinaryOperator#applyAsInt(int, int)} - * @return {@link OptionalInt} typically wrapping return value of {@link IntBinaryOperator#applyAsInt(int, int)}, - * or an empty {@link OptionalInt} (typically signifying an exception) - * @see ExceptionHandler#fromIntBinaryOperator(IntBinaryOperator) - * @see IntBinaryOperator#applyAsInt(int, int) - */ - OptionalInt apply(int left, int right); - /** - * Converts this {@code OptionalIntBinaryOperator} to plain {@link IntBinaryOperator} using default value. - * The returned {@link IntBinaryOperator} will unwrap present value from the {@link OptionalInt} if possible, - * or return {@code result} if the {@link OptionalInt} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalInt} - * @return plain {@link IntBinaryOperator} that either unwraps {@link OptionalInt} or returns default value - * @see #orElseGet(IntSupplier) - * @see OptionalInt#orElse(int) - */ - default IntBinaryOperator orElse(int result) { - return new DefaultIntBinaryOperator(this, result); - } - /** - * Converts this {@code OptionalIntBinaryOperator} to plain {@link IntBinaryOperator} using fallback {@link IntSupplier}. - * The returned {@link IntBinaryOperator} will unwrap present value from the {@link OptionalInt} if possible, - * or fall back to calling {@code source} if the {@link OptionalInt} is empty. - * - * @param source - * {@link IntSupplier} to query for fallback value when {@link OptionalInt} is empty - * @return plain {@link IntBinaryOperator} that either unwraps {@link OptionalInt} or falls back to {@code source} - * @see #orElse(int) - * @see OptionalInt#orElseGet(IntSupplier) - */ - default IntBinaryOperator orElseGet(IntSupplier source) { - return new FallbackIntBinaryOperator(this, source); - } + /** + * Variation of {@link IntBinaryOperator#applyAsInt(int, int)} that returns {@link OptionalInt}. + * If this {@code OptionalIntBinaryOperator} is obtained from {@link ExceptionHandler#fromIntBinaryOperator(IntBinaryOperator)}, + * the {@link OptionalInt} will be empty only if the underlying {@link IntBinaryOperator} throws. + * Otherwise the returned {@link OptionalInt} just wraps the return value of underlying {@link IntBinaryOperator}. + * + * @param left + * see {@link IntBinaryOperator#applyAsInt(int, int)} + * @param right + * see {@link IntBinaryOperator#applyAsInt(int, int)} + * @return {@link OptionalInt} typically wrapping return value of {@link IntBinaryOperator#applyAsInt(int, int)}, + * or an empty {@link OptionalInt} (typically signifying an exception) + * @see ExceptionHandler#fromIntBinaryOperator(IntBinaryOperator) + * @see IntBinaryOperator#applyAsInt(int, int) + */ + OptionalInt apply(int left, int right); + /** + * Converts this {@code OptionalIntBinaryOperator} to plain {@link IntBinaryOperator} using default value. + * The returned {@link IntBinaryOperator} will unwrap present value from the {@link OptionalInt} if possible, + * or return {@code result} if the {@link OptionalInt} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalInt} + * @return plain {@link IntBinaryOperator} that either unwraps {@link OptionalInt} or returns default value + * @see #orElseGet(IntSupplier) + * @see OptionalInt#orElse(int) + */ + default IntBinaryOperator orElse(int result) { + return new DefaultIntBinaryOperator(this, result); + } + /** + * Converts this {@code OptionalIntBinaryOperator} to plain {@link IntBinaryOperator} using fallback {@link IntSupplier}. + * The returned {@link IntBinaryOperator} will unwrap present value from the {@link OptionalInt} if possible, + * or fall back to calling {@code source} if the {@link OptionalInt} is empty. + * + * @param source + * {@link IntSupplier} to query for fallback value when {@link OptionalInt} is empty + * @return plain {@link IntBinaryOperator} that either unwraps {@link OptionalInt} or falls back to {@code source} + * @see #orElse(int) + * @see OptionalInt#orElseGet(IntSupplier) + */ + default IntBinaryOperator orElseGet(IntSupplier source) { + return new FallbackIntBinaryOperator(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalIntFunction.java b/src/main/java/com/machinezoo/noexception/optional/OptionalIntFunction.java index 3ef710e..ac15e59 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalIntFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalIntFunction.java @@ -19,47 +19,47 @@ */ @FunctionalInterface public interface OptionalIntFunction extends IntFunction> { - /** - * Variation of {@link IntFunction#apply(int)} that returns {@link Optional}. - * If this {@code OptionalIntFunction} is obtained from {@link ExceptionHandler#fromIntFunction(IntFunction)}, - * the {@link Optional} will be empty only if the underlying {@link IntFunction} throws. - * Otherwise the returned {@link Optional} just wraps the return value of underlying {@link IntFunction} (possibly {@code null}). - * - * @param value - * see {@link IntFunction#apply(int)} - * @return {@link Optional} typically wrapping return value of {@link IntFunction#apply(int)}, - * or an empty {@link Optional} (typically signifying an exception) - * @see ExceptionHandler#fromIntFunction(IntFunction) - * @see IntFunction#apply(int) - */ - @Override - Optional apply(int value); - /** - * Converts this {@code OptionalIntFunction} to plain {@link IntFunction} using default value. - * The returned {@link IntFunction} will unwrap present value from the {@link Optional} if possible, - * or return {@code result} if the {@link Optional} is empty. - * - * @param result - * default value to return instead of an empty {@link Optional} - * @return plain {@link IntFunction} that either unwraps {@link Optional} or returns default value - * @see #orElseGet(Supplier) - * @see Optional#orElse(Object) - */ - default IntFunction orElse(R result) { - return new DefaultIntFunction(this, result); - } - /** - * Converts this {@code OptionalIntFunction} to plain {@link IntFunction} using fallback {@link Supplier}. - * The returned {@link IntFunction} will unwrap present value from the {@link Optional} if possible, - * or fall back to calling {@code source} if the {@link Optional} is empty. - * - * @param source - * {@link Supplier} to query for fallback value when {@link Optional} is empty - * @return plain {@link IntFunction} that either unwraps {@link Optional} or falls back to {@code source} - * @see #orElse(Object) - * @see Optional#orElseGet(Supplier) - */ - default IntFunction orElseGet(Supplier source) { - return new FallbackIntFunction(this, source); - } + /** + * Variation of {@link IntFunction#apply(int)} that returns {@link Optional}. + * If this {@code OptionalIntFunction} is obtained from {@link ExceptionHandler#fromIntFunction(IntFunction)}, + * the {@link Optional} will be empty only if the underlying {@link IntFunction} throws. + * Otherwise the returned {@link Optional} just wraps the return value of underlying {@link IntFunction} (possibly {@code null}). + * + * @param value + * see {@link IntFunction#apply(int)} + * @return {@link Optional} typically wrapping return value of {@link IntFunction#apply(int)}, + * or an empty {@link Optional} (typically signifying an exception) + * @see ExceptionHandler#fromIntFunction(IntFunction) + * @see IntFunction#apply(int) + */ + @Override + Optional apply(int value); + /** + * Converts this {@code OptionalIntFunction} to plain {@link IntFunction} using default value. + * The returned {@link IntFunction} will unwrap present value from the {@link Optional} if possible, + * or return {@code result} if the {@link Optional} is empty. + * + * @param result + * default value to return instead of an empty {@link Optional} + * @return plain {@link IntFunction} that either unwraps {@link Optional} or returns default value + * @see #orElseGet(Supplier) + * @see Optional#orElse(Object) + */ + default IntFunction orElse(R result) { + return new DefaultIntFunction(this, result); + } + /** + * Converts this {@code OptionalIntFunction} to plain {@link IntFunction} using fallback {@link Supplier}. + * The returned {@link IntFunction} will unwrap present value from the {@link Optional} if possible, + * or fall back to calling {@code source} if the {@link Optional} is empty. + * + * @param source + * {@link Supplier} to query for fallback value when {@link Optional} is empty + * @return plain {@link IntFunction} that either unwraps {@link Optional} or falls back to {@code source} + * @see #orElse(Object) + * @see Optional#orElseGet(Supplier) + */ + default IntFunction orElseGet(Supplier source) { + return new FallbackIntFunction(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalIntPredicate.java b/src/main/java/com/machinezoo/noexception/optional/OptionalIntPredicate.java index e3e6e6d..8287f62 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalIntPredicate.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalIntPredicate.java @@ -16,46 +16,46 @@ */ @FunctionalInterface public interface OptionalIntPredicate { - /** - * Variation of {@link IntPredicate#test(int)} that returns {@link OptionalBoolean}. - * If this {@code OptionalIntPredicate} is obtained from {@link ExceptionHandler#fromIntPredicate(IntPredicate)}, - * the {@link OptionalBoolean} will be empty only if the underlying {@link IntPredicate} throws. - * Otherwise the returned {@link OptionalBoolean} just wraps the return value of underlying {@link IntPredicate}. - * - * @param value - * see {@link IntPredicate#test(int)} - * @return {@link OptionalBoolean} typically wrapping return value of {@link IntPredicate#test(int)}, - * or an empty {@link OptionalBoolean} (typically signifying an exception) - * @see ExceptionHandler#fromIntPredicate(IntPredicate) - * @see IntPredicate#test(int) - */ - OptionalBoolean test(int value); - /** - * Converts this {@code OptionalIntPredicate} to plain {@link IntPredicate} using default value. - * The returned {@link IntPredicate} will unwrap present value from the {@link OptionalBoolean} if possible, - * or return {@code result} if the {@link OptionalBoolean} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalBoolean} - * @return plain {@link IntPredicate} that either unwraps {@link OptionalBoolean} or returns default value - * @see #orElseGet(BooleanSupplier) - * @see OptionalBoolean#orElse(boolean) - */ - default IntPredicate orElse(boolean result) { - return new DefaultIntPredicate(this, result); - } - /** - * Converts this {@code OptionalIntPredicate} to plain {@link IntPredicate} using fallback {@link BooleanSupplier}. - * The returned {@link IntPredicate} will unwrap present value from the {@link OptionalBoolean} if possible, - * or fall back to calling {@code source} if the {@link OptionalBoolean} is empty. - * - * @param source - * {@link BooleanSupplier} to query for fallback value when {@link OptionalBoolean} is empty - * @return plain {@link IntPredicate} that either unwraps {@link OptionalBoolean} or falls back to {@code source} - * @see #orElse(boolean) - * @see OptionalBoolean#orElseGet(BooleanSupplier) - */ - default IntPredicate orElseGet(BooleanSupplier source) { - return new FallbackIntPredicate(this, source); - } + /** + * Variation of {@link IntPredicate#test(int)} that returns {@link OptionalBoolean}. + * If this {@code OptionalIntPredicate} is obtained from {@link ExceptionHandler#fromIntPredicate(IntPredicate)}, + * the {@link OptionalBoolean} will be empty only if the underlying {@link IntPredicate} throws. + * Otherwise the returned {@link OptionalBoolean} just wraps the return value of underlying {@link IntPredicate}. + * + * @param value + * see {@link IntPredicate#test(int)} + * @return {@link OptionalBoolean} typically wrapping return value of {@link IntPredicate#test(int)}, + * or an empty {@link OptionalBoolean} (typically signifying an exception) + * @see ExceptionHandler#fromIntPredicate(IntPredicate) + * @see IntPredicate#test(int) + */ + OptionalBoolean test(int value); + /** + * Converts this {@code OptionalIntPredicate} to plain {@link IntPredicate} using default value. + * The returned {@link IntPredicate} will unwrap present value from the {@link OptionalBoolean} if possible, + * or return {@code result} if the {@link OptionalBoolean} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalBoolean} + * @return plain {@link IntPredicate} that either unwraps {@link OptionalBoolean} or returns default value + * @see #orElseGet(BooleanSupplier) + * @see OptionalBoolean#orElse(boolean) + */ + default IntPredicate orElse(boolean result) { + return new DefaultIntPredicate(this, result); + } + /** + * Converts this {@code OptionalIntPredicate} to plain {@link IntPredicate} using fallback {@link BooleanSupplier}. + * The returned {@link IntPredicate} will unwrap present value from the {@link OptionalBoolean} if possible, + * or fall back to calling {@code source} if the {@link OptionalBoolean} is empty. + * + * @param source + * {@link BooleanSupplier} to query for fallback value when {@link OptionalBoolean} is empty + * @return plain {@link IntPredicate} that either unwraps {@link OptionalBoolean} or falls back to {@code source} + * @see #orElse(boolean) + * @see OptionalBoolean#orElseGet(BooleanSupplier) + */ + default IntPredicate orElseGet(BooleanSupplier source) { + return new FallbackIntPredicate(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalIntSupplier.java b/src/main/java/com/machinezoo/noexception/optional/OptionalIntSupplier.java index 7c74865..c7938b5 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalIntSupplier.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalIntSupplier.java @@ -17,45 +17,45 @@ */ @FunctionalInterface public interface OptionalIntSupplier extends Supplier { - /** - * Variation of {@link IntSupplier#getAsInt()} that returns {@link OptionalInt}. - * If this {@code OptionalIntSupplier} is obtained from {@link ExceptionHandler#fromIntSupplier(IntSupplier)}, - * the {@link OptionalInt} will be empty only if the underlying {@link IntSupplier} throws. - * Otherwise the returned {@link OptionalInt} just wraps the return value of underlying {@link IntSupplier}. - * - * @return {@link OptionalInt} typically wrapping return value of {@link IntSupplier#getAsInt()}, - * or an empty {@link OptionalInt} (typically signifying an exception) - * @see ExceptionHandler#fromIntSupplier(IntSupplier) - * @see IntSupplier#getAsInt() - */ - @Override - OptionalInt get(); - /** - * Converts this {@code OptionalIntSupplier} to plain {@link IntSupplier} using default value. - * The returned {@link IntSupplier} will unwrap present value from the {@link OptionalInt} if possible, - * or return {@code result} if the {@link OptionalInt} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalInt} - * @return plain {@link IntSupplier} that either unwraps {@link OptionalInt} or returns default value - * @see #orElseGet(IntSupplier) - * @see OptionalInt#orElse(int) - */ - default IntSupplier orElse(int result) { - return new DefaultIntSupplier(this, result); - } - /** - * Converts this {@code OptionalIntSupplier} to plain {@link IntSupplier} using fallback {@link IntSupplier}. - * The returned {@link IntSupplier} will unwrap present value from the {@link OptionalInt} if possible, - * or fall back to calling {@code source} if the {@link OptionalInt} is empty. - * - * @param source - * {@link IntSupplier} to query for fallback value when {@link OptionalInt} is empty - * @return plain {@link IntSupplier} that either unwraps {@link OptionalInt} or falls back to {@code source} - * @see #orElse(int) - * @see OptionalInt#orElseGet(IntSupplier) - */ - default IntSupplier orElseGet(IntSupplier source) { - return new FallbackIntSupplier(this, source); - } + /** + * Variation of {@link IntSupplier#getAsInt()} that returns {@link OptionalInt}. + * If this {@code OptionalIntSupplier} is obtained from {@link ExceptionHandler#fromIntSupplier(IntSupplier)}, + * the {@link OptionalInt} will be empty only if the underlying {@link IntSupplier} throws. + * Otherwise the returned {@link OptionalInt} just wraps the return value of underlying {@link IntSupplier}. + * + * @return {@link OptionalInt} typically wrapping return value of {@link IntSupplier#getAsInt()}, + * or an empty {@link OptionalInt} (typically signifying an exception) + * @see ExceptionHandler#fromIntSupplier(IntSupplier) + * @see IntSupplier#getAsInt() + */ + @Override + OptionalInt get(); + /** + * Converts this {@code OptionalIntSupplier} to plain {@link IntSupplier} using default value. + * The returned {@link IntSupplier} will unwrap present value from the {@link OptionalInt} if possible, + * or return {@code result} if the {@link OptionalInt} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalInt} + * @return plain {@link IntSupplier} that either unwraps {@link OptionalInt} or returns default value + * @see #orElseGet(IntSupplier) + * @see OptionalInt#orElse(int) + */ + default IntSupplier orElse(int result) { + return new DefaultIntSupplier(this, result); + } + /** + * Converts this {@code OptionalIntSupplier} to plain {@link IntSupplier} using fallback {@link IntSupplier}. + * The returned {@link IntSupplier} will unwrap present value from the {@link OptionalInt} if possible, + * or fall back to calling {@code source} if the {@link OptionalInt} is empty. + * + * @param source + * {@link IntSupplier} to query for fallback value when {@link OptionalInt} is empty + * @return plain {@link IntSupplier} that either unwraps {@link OptionalInt} or falls back to {@code source} + * @see #orElse(int) + * @see OptionalInt#orElseGet(IntSupplier) + */ + default IntSupplier orElseGet(IntSupplier source) { + return new FallbackIntSupplier(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalIntToDoubleFunction.java b/src/main/java/com/machinezoo/noexception/optional/OptionalIntToDoubleFunction.java index e2e16c5..d672ae1 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalIntToDoubleFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalIntToDoubleFunction.java @@ -17,47 +17,47 @@ */ @FunctionalInterface public interface OptionalIntToDoubleFunction extends IntFunction { - /** - * Variation of {@link IntToDoubleFunction#applyAsDouble(int)} that returns {@link OptionalDouble}. - * If this {@code OptionalIntToDoubleFunction} is obtained from {@link ExceptionHandler#fromIntToDoubleFunction(IntToDoubleFunction)}, - * the {@link OptionalDouble} will be empty only if the underlying {@link IntToDoubleFunction} throws. - * Otherwise the returned {@link OptionalDouble} just wraps the return value of underlying {@link IntToDoubleFunction}. - * - * @param value - * see {@link IntToDoubleFunction#applyAsDouble(int)} - * @return {@link OptionalDouble} typically wrapping return value of {@link IntToDoubleFunction#applyAsDouble(int)}, - * or an empty {@link OptionalDouble} (typically signifying an exception) - * @see ExceptionHandler#fromIntToDoubleFunction(IntToDoubleFunction) - * @see IntToDoubleFunction#applyAsDouble(int) - */ - @Override - OptionalDouble apply(int value); - /** - * Converts this {@code OptionalIntToDoubleFunction} to plain {@link IntToDoubleFunction} using default value. - * The returned {@link IntToDoubleFunction} will unwrap present value from the {@link OptionalDouble} if possible, - * or return {@code result} if the {@link OptionalDouble} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalDouble} - * @return plain {@link IntToDoubleFunction} that either unwraps {@link OptionalDouble} or returns default value - * @see #orElseGet(DoubleSupplier) - * @see OptionalDouble#orElse(double) - */ - default IntToDoubleFunction orElse(double result) { - return new DefaultIntToDoubleFunction(this, result); - } - /** - * Converts this {@code OptionalIntToDoubleFunction} to plain {@link IntToDoubleFunction} using fallback {@link DoubleSupplier}. - * The returned {@link IntToDoubleFunction} will unwrap present value from the {@link OptionalDouble} if possible, - * or fall back to calling {@code source} if the {@link OptionalDouble} is empty. - * - * @param source - * {@link DoubleSupplier} to query for fallback value when {@link OptionalDouble} is empty - * @return plain {@link IntToDoubleFunction} that either unwraps {@link OptionalDouble} or falls back to {@code source} - * @see #orElse(double) - * @see OptionalDouble#orElseGet(DoubleSupplier) - */ - default IntToDoubleFunction orElseGet(DoubleSupplier source) { - return new FallbackIntToDoubleFunction(this, source); - } + /** + * Variation of {@link IntToDoubleFunction#applyAsDouble(int)} that returns {@link OptionalDouble}. + * If this {@code OptionalIntToDoubleFunction} is obtained from {@link ExceptionHandler#fromIntToDoubleFunction(IntToDoubleFunction)}, + * the {@link OptionalDouble} will be empty only if the underlying {@link IntToDoubleFunction} throws. + * Otherwise the returned {@link OptionalDouble} just wraps the return value of underlying {@link IntToDoubleFunction}. + * + * @param value + * see {@link IntToDoubleFunction#applyAsDouble(int)} + * @return {@link OptionalDouble} typically wrapping return value of {@link IntToDoubleFunction#applyAsDouble(int)}, + * or an empty {@link OptionalDouble} (typically signifying an exception) + * @see ExceptionHandler#fromIntToDoubleFunction(IntToDoubleFunction) + * @see IntToDoubleFunction#applyAsDouble(int) + */ + @Override + OptionalDouble apply(int value); + /** + * Converts this {@code OptionalIntToDoubleFunction} to plain {@link IntToDoubleFunction} using default value. + * The returned {@link IntToDoubleFunction} will unwrap present value from the {@link OptionalDouble} if possible, + * or return {@code result} if the {@link OptionalDouble} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalDouble} + * @return plain {@link IntToDoubleFunction} that either unwraps {@link OptionalDouble} or returns default value + * @see #orElseGet(DoubleSupplier) + * @see OptionalDouble#orElse(double) + */ + default IntToDoubleFunction orElse(double result) { + return new DefaultIntToDoubleFunction(this, result); + } + /** + * Converts this {@code OptionalIntToDoubleFunction} to plain {@link IntToDoubleFunction} using fallback {@link DoubleSupplier}. + * The returned {@link IntToDoubleFunction} will unwrap present value from the {@link OptionalDouble} if possible, + * or fall back to calling {@code source} if the {@link OptionalDouble} is empty. + * + * @param source + * {@link DoubleSupplier} to query for fallback value when {@link OptionalDouble} is empty + * @return plain {@link IntToDoubleFunction} that either unwraps {@link OptionalDouble} or falls back to {@code source} + * @see #orElse(double) + * @see OptionalDouble#orElseGet(DoubleSupplier) + */ + default IntToDoubleFunction orElseGet(DoubleSupplier source) { + return new FallbackIntToDoubleFunction(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalIntToLongFunction.java b/src/main/java/com/machinezoo/noexception/optional/OptionalIntToLongFunction.java index e57c760..08fe248 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalIntToLongFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalIntToLongFunction.java @@ -17,47 +17,47 @@ */ @FunctionalInterface public interface OptionalIntToLongFunction extends IntFunction { - /** - * Variation of {@link IntToLongFunction#applyAsLong(int)} that returns {@link OptionalLong}. - * If this {@code OptionalIntToLongFunction} is obtained from {@link ExceptionHandler#fromIntToLongFunction(IntToLongFunction)}, - * the {@link OptionalLong} will be empty only if the underlying {@link IntToLongFunction} throws. - * Otherwise the returned {@link OptionalLong} just wraps the return value of underlying {@link IntToLongFunction}. - * - * @param value - * see {@link IntToLongFunction#applyAsLong(int)} - * @return {@link OptionalLong} typically wrapping return value of {@link IntToLongFunction#applyAsLong(int)}, - * or an empty {@link OptionalLong} (typically signifying an exception) - * @see ExceptionHandler#fromIntToLongFunction(IntToLongFunction) - * @see IntToLongFunction#applyAsLong(int) - */ - @Override - OptionalLong apply(int value); - /** - * Converts this {@code OptionalIntToLongFunction} to plain {@link IntToLongFunction} using default value. - * The returned {@link IntToLongFunction} will unwrap present value from the {@link OptionalLong} if possible, - * or return {@code result} if the {@link OptionalLong} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalLong} - * @return plain {@link IntToLongFunction} that either unwraps {@link OptionalLong} or returns default value - * @see #orElseGet(LongSupplier) - * @see OptionalLong#orElse(long) - */ - default IntToLongFunction orElse(long result) { - return new DefaultIntToLongFunction(this, result); - } - /** - * Converts this {@code OptionalIntToLongFunction} to plain {@link IntToLongFunction} using fallback {@link LongSupplier}. - * The returned {@link IntToLongFunction} will unwrap present value from the {@link OptionalLong} if possible, - * or fall back to calling {@code source} if the {@link OptionalLong} is empty. - * - * @param source - * {@link LongSupplier} to query for fallback value when {@link OptionalLong} is empty - * @return plain {@link IntToLongFunction} that either unwraps {@link OptionalLong} or falls back to {@code source} - * @see #orElse(long) - * @see OptionalLong#orElseGet(LongSupplier) - */ - default IntToLongFunction orElseGet(LongSupplier source) { - return new FallbackIntToLongFunction(this, source); - } + /** + * Variation of {@link IntToLongFunction#applyAsLong(int)} that returns {@link OptionalLong}. + * If this {@code OptionalIntToLongFunction} is obtained from {@link ExceptionHandler#fromIntToLongFunction(IntToLongFunction)}, + * the {@link OptionalLong} will be empty only if the underlying {@link IntToLongFunction} throws. + * Otherwise the returned {@link OptionalLong} just wraps the return value of underlying {@link IntToLongFunction}. + * + * @param value + * see {@link IntToLongFunction#applyAsLong(int)} + * @return {@link OptionalLong} typically wrapping return value of {@link IntToLongFunction#applyAsLong(int)}, + * or an empty {@link OptionalLong} (typically signifying an exception) + * @see ExceptionHandler#fromIntToLongFunction(IntToLongFunction) + * @see IntToLongFunction#applyAsLong(int) + */ + @Override + OptionalLong apply(int value); + /** + * Converts this {@code OptionalIntToLongFunction} to plain {@link IntToLongFunction} using default value. + * The returned {@link IntToLongFunction} will unwrap present value from the {@link OptionalLong} if possible, + * or return {@code result} if the {@link OptionalLong} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalLong} + * @return plain {@link IntToLongFunction} that either unwraps {@link OptionalLong} or returns default value + * @see #orElseGet(LongSupplier) + * @see OptionalLong#orElse(long) + */ + default IntToLongFunction orElse(long result) { + return new DefaultIntToLongFunction(this, result); + } + /** + * Converts this {@code OptionalIntToLongFunction} to plain {@link IntToLongFunction} using fallback {@link LongSupplier}. + * The returned {@link IntToLongFunction} will unwrap present value from the {@link OptionalLong} if possible, + * or fall back to calling {@code source} if the {@link OptionalLong} is empty. + * + * @param source + * {@link LongSupplier} to query for fallback value when {@link OptionalLong} is empty + * @return plain {@link IntToLongFunction} that either unwraps {@link OptionalLong} or falls back to {@code source} + * @see #orElse(long) + * @see OptionalLong#orElseGet(LongSupplier) + */ + default IntToLongFunction orElseGet(LongSupplier source) { + return new FallbackIntToLongFunction(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalIntUnaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/OptionalIntUnaryOperator.java index d867667..d954766 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalIntUnaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalIntUnaryOperator.java @@ -17,47 +17,47 @@ */ @FunctionalInterface public interface OptionalIntUnaryOperator extends IntFunction { - /** - * Variation of {@link IntUnaryOperator#applyAsInt(int)} that returns {@link OptionalInt}. - * If this {@code OptionalIntUnaryOperator} is obtained from {@link ExceptionHandler#fromIntUnaryOperator(IntUnaryOperator)}, - * the {@link OptionalInt} will be empty only if the underlying {@link IntUnaryOperator} throws. - * Otherwise the returned {@link OptionalInt} just wraps the return value of underlying {@link IntUnaryOperator}. - * - * @param operand - * see {@link IntUnaryOperator#applyAsInt(int)} - * @return {@link OptionalInt} typically wrapping return value of {@link IntUnaryOperator#applyAsInt(int)}, - * or an empty {@link OptionalInt} (typically signifying an exception) - * @see ExceptionHandler#fromIntUnaryOperator(IntUnaryOperator) - * @see IntUnaryOperator#applyAsInt(int) - */ - @Override - OptionalInt apply(int operand); - /** - * Converts this {@code OptionalIntUnaryOperator} to plain {@link IntUnaryOperator} using default value. - * The returned {@link IntUnaryOperator} will unwrap present value from the {@link OptionalInt} if possible, - * or return {@code result} if the {@link OptionalInt} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalInt} - * @return plain {@link IntUnaryOperator} that either unwraps {@link OptionalInt} or returns default value - * @see #orElseGet(IntSupplier) - * @see OptionalInt#orElse(int) - */ - default IntUnaryOperator orElse(int result) { - return new DefaultIntUnaryOperator(this, result); - } - /** - * Converts this {@code OptionalIntUnaryOperator} to plain {@link IntUnaryOperator} using fallback {@link IntSupplier}. - * The returned {@link IntUnaryOperator} will unwrap present value from the {@link OptionalInt} if possible, - * or fall back to calling {@code source} if the {@link OptionalInt} is empty. - * - * @param source - * {@link IntSupplier} to query for fallback value when {@link OptionalInt} is empty - * @return plain {@link IntUnaryOperator} that either unwraps {@link OptionalInt} or falls back to {@code source} - * @see #orElse(int) - * @see OptionalInt#orElseGet(IntSupplier) - */ - default IntUnaryOperator orElseGet(IntSupplier source) { - return new FallbackIntUnaryOperator(this, source); - } + /** + * Variation of {@link IntUnaryOperator#applyAsInt(int)} that returns {@link OptionalInt}. + * If this {@code OptionalIntUnaryOperator} is obtained from {@link ExceptionHandler#fromIntUnaryOperator(IntUnaryOperator)}, + * the {@link OptionalInt} will be empty only if the underlying {@link IntUnaryOperator} throws. + * Otherwise the returned {@link OptionalInt} just wraps the return value of underlying {@link IntUnaryOperator}. + * + * @param operand + * see {@link IntUnaryOperator#applyAsInt(int)} + * @return {@link OptionalInt} typically wrapping return value of {@link IntUnaryOperator#applyAsInt(int)}, + * or an empty {@link OptionalInt} (typically signifying an exception) + * @see ExceptionHandler#fromIntUnaryOperator(IntUnaryOperator) + * @see IntUnaryOperator#applyAsInt(int) + */ + @Override + OptionalInt apply(int operand); + /** + * Converts this {@code OptionalIntUnaryOperator} to plain {@link IntUnaryOperator} using default value. + * The returned {@link IntUnaryOperator} will unwrap present value from the {@link OptionalInt} if possible, + * or return {@code result} if the {@link OptionalInt} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalInt} + * @return plain {@link IntUnaryOperator} that either unwraps {@link OptionalInt} or returns default value + * @see #orElseGet(IntSupplier) + * @see OptionalInt#orElse(int) + */ + default IntUnaryOperator orElse(int result) { + return new DefaultIntUnaryOperator(this, result); + } + /** + * Converts this {@code OptionalIntUnaryOperator} to plain {@link IntUnaryOperator} using fallback {@link IntSupplier}. + * The returned {@link IntUnaryOperator} will unwrap present value from the {@link OptionalInt} if possible, + * or fall back to calling {@code source} if the {@link OptionalInt} is empty. + * + * @param source + * {@link IntSupplier} to query for fallback value when {@link OptionalInt} is empty + * @return plain {@link IntUnaryOperator} that either unwraps {@link OptionalInt} or falls back to {@code source} + * @see #orElse(int) + * @see OptionalInt#orElseGet(IntSupplier) + */ + default IntUnaryOperator orElseGet(IntSupplier source) { + return new FallbackIntUnaryOperator(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalLongBinaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/OptionalLongBinaryOperator.java index 826eaa0..7540615 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalLongBinaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalLongBinaryOperator.java @@ -17,48 +17,48 @@ */ @FunctionalInterface public interface OptionalLongBinaryOperator { - /** - * Variation of {@link LongBinaryOperator#applyAsLong(long, long)} that returns {@link OptionalLong}. - * If this {@code OptionalLongBinaryOperator} is obtained from {@link ExceptionHandler#fromLongBinaryOperator(LongBinaryOperator)}, - * the {@link OptionalLong} will be empty only if the underlying {@link LongBinaryOperator} throws. - * Otherwise the returned {@link OptionalLong} just wraps the return value of underlying {@link LongBinaryOperator}. - * - * @param left - * see {@link LongBinaryOperator#applyAsLong(long, long)} - * @param right - * see {@link LongBinaryOperator#applyAsLong(long, long)} - * @return {@link OptionalLong} typically wrapping return value of {@link LongBinaryOperator#applyAsLong(long, long)}, - * or an empty {@link OptionalLong} (typically signifying an exception) - * @see ExceptionHandler#fromLongBinaryOperator(LongBinaryOperator) - * @see LongBinaryOperator#applyAsLong(long, long) - */ - OptionalLong apply(long left, long right); - /** - * Converts this {@code OptionalLongBinaryOperator} to plain {@link LongBinaryOperator} using default value. - * The returned {@link LongBinaryOperator} will unwrap present value from the {@link OptionalLong} if possible, - * or return {@code result} if the {@link OptionalLong} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalLong} - * @return plain {@link LongBinaryOperator} that either unwraps {@link OptionalLong} or returns default value - * @see #orElseGet(LongSupplier) - * @see OptionalLong#orElse(long) - */ - default LongBinaryOperator orElse(long result) { - return new DefaultLongBinaryOperator(this, result); - } - /** - * Converts this {@code OptionalLongBinaryOperator} to plain {@link LongBinaryOperator} using fallback {@link LongSupplier}. - * The returned {@link LongBinaryOperator} will unwrap present value from the {@link OptionalLong} if possible, - * or fall back to calling {@code source} if the {@link OptionalLong} is empty. - * - * @param source - * {@link LongSupplier} to query for fallback value when {@link OptionalLong} is empty - * @return plain {@link LongBinaryOperator} that either unwraps {@link OptionalLong} or falls back to {@code source} - * @see #orElse(long) - * @see OptionalLong#orElseGet(LongSupplier) - */ - default LongBinaryOperator orElseGet(LongSupplier source) { - return new FallbackLongBinaryOperator(this, source); - } + /** + * Variation of {@link LongBinaryOperator#applyAsLong(long, long)} that returns {@link OptionalLong}. + * If this {@code OptionalLongBinaryOperator} is obtained from {@link ExceptionHandler#fromLongBinaryOperator(LongBinaryOperator)}, + * the {@link OptionalLong} will be empty only if the underlying {@link LongBinaryOperator} throws. + * Otherwise the returned {@link OptionalLong} just wraps the return value of underlying {@link LongBinaryOperator}. + * + * @param left + * see {@link LongBinaryOperator#applyAsLong(long, long)} + * @param right + * see {@link LongBinaryOperator#applyAsLong(long, long)} + * @return {@link OptionalLong} typically wrapping return value of {@link LongBinaryOperator#applyAsLong(long, long)}, + * or an empty {@link OptionalLong} (typically signifying an exception) + * @see ExceptionHandler#fromLongBinaryOperator(LongBinaryOperator) + * @see LongBinaryOperator#applyAsLong(long, long) + */ + OptionalLong apply(long left, long right); + /** + * Converts this {@code OptionalLongBinaryOperator} to plain {@link LongBinaryOperator} using default value. + * The returned {@link LongBinaryOperator} will unwrap present value from the {@link OptionalLong} if possible, + * or return {@code result} if the {@link OptionalLong} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalLong} + * @return plain {@link LongBinaryOperator} that either unwraps {@link OptionalLong} or returns default value + * @see #orElseGet(LongSupplier) + * @see OptionalLong#orElse(long) + */ + default LongBinaryOperator orElse(long result) { + return new DefaultLongBinaryOperator(this, result); + } + /** + * Converts this {@code OptionalLongBinaryOperator} to plain {@link LongBinaryOperator} using fallback {@link LongSupplier}. + * The returned {@link LongBinaryOperator} will unwrap present value from the {@link OptionalLong} if possible, + * or fall back to calling {@code source} if the {@link OptionalLong} is empty. + * + * @param source + * {@link LongSupplier} to query for fallback value when {@link OptionalLong} is empty + * @return plain {@link LongBinaryOperator} that either unwraps {@link OptionalLong} or falls back to {@code source} + * @see #orElse(long) + * @see OptionalLong#orElseGet(LongSupplier) + */ + default LongBinaryOperator orElseGet(LongSupplier source) { + return new FallbackLongBinaryOperator(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalLongFunction.java b/src/main/java/com/machinezoo/noexception/optional/OptionalLongFunction.java index f234c07..6322322 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalLongFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalLongFunction.java @@ -19,47 +19,47 @@ */ @FunctionalInterface public interface OptionalLongFunction extends LongFunction> { - /** - * Variation of {@link LongFunction#apply(long)} that returns {@link Optional}. - * If this {@code OptionalLongFunction} is obtained from {@link ExceptionHandler#fromLongFunction(LongFunction)}, - * the {@link Optional} will be empty only if the underlying {@link LongFunction} throws. - * Otherwise the returned {@link Optional} just wraps the return value of underlying {@link LongFunction} (possibly {@code null}). - * - * @param value - * see {@link LongFunction#apply(long)} - * @return {@link Optional} typically wrapping return value of {@link LongFunction#apply(long)}, - * or an empty {@link Optional} (typically signifying an exception) - * @see ExceptionHandler#fromLongFunction(LongFunction) - * @see LongFunction#apply(long) - */ - @Override - Optional apply(long value); - /** - * Converts this {@code OptionalLongFunction} to plain {@link LongFunction} using default value. - * The returned {@link LongFunction} will unwrap present value from the {@link Optional} if possible, - * or return {@code result} if the {@link Optional} is empty. - * - * @param result - * default value to return instead of an empty {@link Optional} - * @return plain {@link LongFunction} that either unwraps {@link Optional} or returns default value - * @see #orElseGet(Supplier) - * @see Optional#orElse(Object) - */ - default LongFunction orElse(R result) { - return new DefaultLongFunction(this, result); - } - /** - * Converts this {@code OptionalLongFunction} to plain {@link LongFunction} using fallback {@link Supplier}. - * The returned {@link LongFunction} will unwrap present value from the {@link Optional} if possible, - * or fall back to calling {@code source} if the {@link Optional} is empty. - * - * @param source - * {@link Supplier} to query for fallback value when {@link Optional} is empty - * @return plain {@link LongFunction} that either unwraps {@link Optional} or falls back to {@code source} - * @see #orElse(Object) - * @see Optional#orElseGet(Supplier) - */ - default LongFunction orElseGet(Supplier source) { - return new FallbackLongFunction(this, source); - } + /** + * Variation of {@link LongFunction#apply(long)} that returns {@link Optional}. + * If this {@code OptionalLongFunction} is obtained from {@link ExceptionHandler#fromLongFunction(LongFunction)}, + * the {@link Optional} will be empty only if the underlying {@link LongFunction} throws. + * Otherwise the returned {@link Optional} just wraps the return value of underlying {@link LongFunction} (possibly {@code null}). + * + * @param value + * see {@link LongFunction#apply(long)} + * @return {@link Optional} typically wrapping return value of {@link LongFunction#apply(long)}, + * or an empty {@link Optional} (typically signifying an exception) + * @see ExceptionHandler#fromLongFunction(LongFunction) + * @see LongFunction#apply(long) + */ + @Override + Optional apply(long value); + /** + * Converts this {@code OptionalLongFunction} to plain {@link LongFunction} using default value. + * The returned {@link LongFunction} will unwrap present value from the {@link Optional} if possible, + * or return {@code result} if the {@link Optional} is empty. + * + * @param result + * default value to return instead of an empty {@link Optional} + * @return plain {@link LongFunction} that either unwraps {@link Optional} or returns default value + * @see #orElseGet(Supplier) + * @see Optional#orElse(Object) + */ + default LongFunction orElse(R result) { + return new DefaultLongFunction(this, result); + } + /** + * Converts this {@code OptionalLongFunction} to plain {@link LongFunction} using fallback {@link Supplier}. + * The returned {@link LongFunction} will unwrap present value from the {@link Optional} if possible, + * or fall back to calling {@code source} if the {@link Optional} is empty. + * + * @param source + * {@link Supplier} to query for fallback value when {@link Optional} is empty + * @return plain {@link LongFunction} that either unwraps {@link Optional} or falls back to {@code source} + * @see #orElse(Object) + * @see Optional#orElseGet(Supplier) + */ + default LongFunction orElseGet(Supplier source) { + return new FallbackLongFunction(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalLongPredicate.java b/src/main/java/com/machinezoo/noexception/optional/OptionalLongPredicate.java index 4893d44..a37c127 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalLongPredicate.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalLongPredicate.java @@ -16,46 +16,46 @@ */ @FunctionalInterface public interface OptionalLongPredicate { - /** - * Variation of {@link LongPredicate#test(long)} that returns {@link OptionalBoolean}. - * If this {@code OptionalLongPredicate} is obtained from {@link ExceptionHandler#fromLongPredicate(LongPredicate)}, - * the {@link OptionalBoolean} will be empty only if the underlying {@link LongPredicate} throws. - * Otherwise the returned {@link OptionalBoolean} just wraps the return value of underlying {@link LongPredicate}. - * - * @param value - * see {@link LongPredicate#test(long)} - * @return {@link OptionalBoolean} typically wrapping return value of {@link LongPredicate#test(long)}, - * or an empty {@link OptionalBoolean} (typically signifying an exception) - * @see ExceptionHandler#fromLongPredicate(LongPredicate) - * @see LongPredicate#test(long) - */ - OptionalBoolean test(long value); - /** - * Converts this {@code OptionalLongPredicate} to plain {@link LongPredicate} using default value. - * The returned {@link LongPredicate} will unwrap present value from the {@link OptionalBoolean} if possible, - * or return {@code result} if the {@link OptionalBoolean} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalBoolean} - * @return plain {@link LongPredicate} that either unwraps {@link OptionalBoolean} or returns default value - * @see #orElseGet(BooleanSupplier) - * @see OptionalBoolean#orElse(boolean) - */ - default LongPredicate orElse(boolean result) { - return new DefaultLongPredicate(this, result); - } - /** - * Converts this {@code OptionalLongPredicate} to plain {@link LongPredicate} using fallback {@link BooleanSupplier}. - * The returned {@link LongPredicate} will unwrap present value from the {@link OptionalBoolean} if possible, - * or fall back to calling {@code source} if the {@link OptionalBoolean} is empty. - * - * @param source - * {@link BooleanSupplier} to query for fallback value when {@link OptionalBoolean} is empty - * @return plain {@link LongPredicate} that either unwraps {@link OptionalBoolean} or falls back to {@code source} - * @see #orElse(boolean) - * @see OptionalBoolean#orElseGet(BooleanSupplier) - */ - default LongPredicate orElseGet(BooleanSupplier source) { - return new FallbackLongPredicate(this, source); - } + /** + * Variation of {@link LongPredicate#test(long)} that returns {@link OptionalBoolean}. + * If this {@code OptionalLongPredicate} is obtained from {@link ExceptionHandler#fromLongPredicate(LongPredicate)}, + * the {@link OptionalBoolean} will be empty only if the underlying {@link LongPredicate} throws. + * Otherwise the returned {@link OptionalBoolean} just wraps the return value of underlying {@link LongPredicate}. + * + * @param value + * see {@link LongPredicate#test(long)} + * @return {@link OptionalBoolean} typically wrapping return value of {@link LongPredicate#test(long)}, + * or an empty {@link OptionalBoolean} (typically signifying an exception) + * @see ExceptionHandler#fromLongPredicate(LongPredicate) + * @see LongPredicate#test(long) + */ + OptionalBoolean test(long value); + /** + * Converts this {@code OptionalLongPredicate} to plain {@link LongPredicate} using default value. + * The returned {@link LongPredicate} will unwrap present value from the {@link OptionalBoolean} if possible, + * or return {@code result} if the {@link OptionalBoolean} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalBoolean} + * @return plain {@link LongPredicate} that either unwraps {@link OptionalBoolean} or returns default value + * @see #orElseGet(BooleanSupplier) + * @see OptionalBoolean#orElse(boolean) + */ + default LongPredicate orElse(boolean result) { + return new DefaultLongPredicate(this, result); + } + /** + * Converts this {@code OptionalLongPredicate} to plain {@link LongPredicate} using fallback {@link BooleanSupplier}. + * The returned {@link LongPredicate} will unwrap present value from the {@link OptionalBoolean} if possible, + * or fall back to calling {@code source} if the {@link OptionalBoolean} is empty. + * + * @param source + * {@link BooleanSupplier} to query for fallback value when {@link OptionalBoolean} is empty + * @return plain {@link LongPredicate} that either unwraps {@link OptionalBoolean} or falls back to {@code source} + * @see #orElse(boolean) + * @see OptionalBoolean#orElseGet(BooleanSupplier) + */ + default LongPredicate orElseGet(BooleanSupplier source) { + return new FallbackLongPredicate(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalLongSupplier.java b/src/main/java/com/machinezoo/noexception/optional/OptionalLongSupplier.java index 9e6b020..4f5a99c 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalLongSupplier.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalLongSupplier.java @@ -17,45 +17,45 @@ */ @FunctionalInterface public interface OptionalLongSupplier extends Supplier { - /** - * Variation of {@link LongSupplier#getAsLong()} that returns {@link OptionalLong}. - * If this {@code OptionalLongSupplier} is obtained from {@link ExceptionHandler#fromLongSupplier(LongSupplier)}, - * the {@link OptionalLong} will be empty only if the underlying {@link LongSupplier} throws. - * Otherwise the returned {@link OptionalLong} just wraps the return value of underlying {@link LongSupplier}. - * - * @return {@link OptionalLong} typically wrapping return value of {@link LongSupplier#getAsLong()}, - * or an empty {@link OptionalLong} (typically signifying an exception) - * @see ExceptionHandler#fromLongSupplier(LongSupplier) - * @see LongSupplier#getAsLong() - */ - @Override - OptionalLong get(); - /** - * Converts this {@code OptionalLongSupplier} to plain {@link LongSupplier} using default value. - * The returned {@link LongSupplier} will unwrap present value from the {@link OptionalLong} if possible, - * or return {@code result} if the {@link OptionalLong} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalLong} - * @return plain {@link LongSupplier} that either unwraps {@link OptionalLong} or returns default value - * @see #orElseGet(LongSupplier) - * @see OptionalLong#orElse(long) - */ - default LongSupplier orElse(long result) { - return new DefaultLongSupplier(this, result); - } - /** - * Converts this {@code OptionalLongSupplier} to plain {@link LongSupplier} using fallback {@link LongSupplier}. - * The returned {@link LongSupplier} will unwrap present value from the {@link OptionalLong} if possible, - * or fall back to calling {@code source} if the {@link OptionalLong} is empty. - * - * @param source - * {@link LongSupplier} to query for fallback value when {@link OptionalLong} is empty - * @return plain {@link LongSupplier} that either unwraps {@link OptionalLong} or falls back to {@code source} - * @see #orElse(long) - * @see OptionalLong#orElseGet(LongSupplier) - */ - default LongSupplier orElseGet(LongSupplier source) { - return new FallbackLongSupplier(this, source); - } + /** + * Variation of {@link LongSupplier#getAsLong()} that returns {@link OptionalLong}. + * If this {@code OptionalLongSupplier} is obtained from {@link ExceptionHandler#fromLongSupplier(LongSupplier)}, + * the {@link OptionalLong} will be empty only if the underlying {@link LongSupplier} throws. + * Otherwise the returned {@link OptionalLong} just wraps the return value of underlying {@link LongSupplier}. + * + * @return {@link OptionalLong} typically wrapping return value of {@link LongSupplier#getAsLong()}, + * or an empty {@link OptionalLong} (typically signifying an exception) + * @see ExceptionHandler#fromLongSupplier(LongSupplier) + * @see LongSupplier#getAsLong() + */ + @Override + OptionalLong get(); + /** + * Converts this {@code OptionalLongSupplier} to plain {@link LongSupplier} using default value. + * The returned {@link LongSupplier} will unwrap present value from the {@link OptionalLong} if possible, + * or return {@code result} if the {@link OptionalLong} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalLong} + * @return plain {@link LongSupplier} that either unwraps {@link OptionalLong} or returns default value + * @see #orElseGet(LongSupplier) + * @see OptionalLong#orElse(long) + */ + default LongSupplier orElse(long result) { + return new DefaultLongSupplier(this, result); + } + /** + * Converts this {@code OptionalLongSupplier} to plain {@link LongSupplier} using fallback {@link LongSupplier}. + * The returned {@link LongSupplier} will unwrap present value from the {@link OptionalLong} if possible, + * or fall back to calling {@code source} if the {@link OptionalLong} is empty. + * + * @param source + * {@link LongSupplier} to query for fallback value when {@link OptionalLong} is empty + * @return plain {@link LongSupplier} that either unwraps {@link OptionalLong} or falls back to {@code source} + * @see #orElse(long) + * @see OptionalLong#orElseGet(LongSupplier) + */ + default LongSupplier orElseGet(LongSupplier source) { + return new FallbackLongSupplier(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalLongToDoubleFunction.java b/src/main/java/com/machinezoo/noexception/optional/OptionalLongToDoubleFunction.java index a9bdf9e..b9f68d6 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalLongToDoubleFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalLongToDoubleFunction.java @@ -17,47 +17,47 @@ */ @FunctionalInterface public interface OptionalLongToDoubleFunction extends LongFunction { - /** - * Variation of {@link LongToDoubleFunction#applyAsDouble(long)} that returns {@link OptionalDouble}. - * If this {@code OptionalLongToDoubleFunction} is obtained from {@link ExceptionHandler#fromLongToDoubleFunction(LongToDoubleFunction)}, - * the {@link OptionalDouble} will be empty only if the underlying {@link LongToDoubleFunction} throws. - * Otherwise the returned {@link OptionalDouble} just wraps the return value of underlying {@link LongToDoubleFunction}. - * - * @param value - * see {@link LongToDoubleFunction#applyAsDouble(long)} - * @return {@link OptionalDouble} typically wrapping return value of {@link LongToDoubleFunction#applyAsDouble(long)}, - * or an empty {@link OptionalDouble} (typically signifying an exception) - * @see ExceptionHandler#fromLongToDoubleFunction(LongToDoubleFunction) - * @see LongToDoubleFunction#applyAsDouble(long) - */ - @Override - OptionalDouble apply(long value); - /** - * Converts this {@code OptionalLongToDoubleFunction} to plain {@link LongToDoubleFunction} using default value. - * The returned {@link LongToDoubleFunction} will unwrap present value from the {@link OptionalDouble} if possible, - * or return {@code result} if the {@link OptionalDouble} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalDouble} - * @return plain {@link LongToDoubleFunction} that either unwraps {@link OptionalDouble} or returns default value - * @see #orElseGet(DoubleSupplier) - * @see OptionalDouble#orElse(double) - */ - default LongToDoubleFunction orElse(double result) { - return new DefaultLongToDoubleFunction(this, result); - } - /** - * Converts this {@code OptionalLongToDoubleFunction} to plain {@link LongToDoubleFunction} using fallback {@link DoubleSupplier}. - * The returned {@link LongToDoubleFunction} will unwrap present value from the {@link OptionalDouble} if possible, - * or fall back to calling {@code source} if the {@link OptionalDouble} is empty. - * - * @param source - * {@link DoubleSupplier} to query for fallback value when {@link OptionalDouble} is empty - * @return plain {@link LongToDoubleFunction} that either unwraps {@link OptionalDouble} or falls back to {@code source} - * @see #orElse(double) - * @see OptionalDouble#orElseGet(DoubleSupplier) - */ - default LongToDoubleFunction orElseGet(DoubleSupplier source) { - return new FallbackLongToDoubleFunction(this, source); - } + /** + * Variation of {@link LongToDoubleFunction#applyAsDouble(long)} that returns {@link OptionalDouble}. + * If this {@code OptionalLongToDoubleFunction} is obtained from {@link ExceptionHandler#fromLongToDoubleFunction(LongToDoubleFunction)}, + * the {@link OptionalDouble} will be empty only if the underlying {@link LongToDoubleFunction} throws. + * Otherwise the returned {@link OptionalDouble} just wraps the return value of underlying {@link LongToDoubleFunction}. + * + * @param value + * see {@link LongToDoubleFunction#applyAsDouble(long)} + * @return {@link OptionalDouble} typically wrapping return value of {@link LongToDoubleFunction#applyAsDouble(long)}, + * or an empty {@link OptionalDouble} (typically signifying an exception) + * @see ExceptionHandler#fromLongToDoubleFunction(LongToDoubleFunction) + * @see LongToDoubleFunction#applyAsDouble(long) + */ + @Override + OptionalDouble apply(long value); + /** + * Converts this {@code OptionalLongToDoubleFunction} to plain {@link LongToDoubleFunction} using default value. + * The returned {@link LongToDoubleFunction} will unwrap present value from the {@link OptionalDouble} if possible, + * or return {@code result} if the {@link OptionalDouble} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalDouble} + * @return plain {@link LongToDoubleFunction} that either unwraps {@link OptionalDouble} or returns default value + * @see #orElseGet(DoubleSupplier) + * @see OptionalDouble#orElse(double) + */ + default LongToDoubleFunction orElse(double result) { + return new DefaultLongToDoubleFunction(this, result); + } + /** + * Converts this {@code OptionalLongToDoubleFunction} to plain {@link LongToDoubleFunction} using fallback {@link DoubleSupplier}. + * The returned {@link LongToDoubleFunction} will unwrap present value from the {@link OptionalDouble} if possible, + * or fall back to calling {@code source} if the {@link OptionalDouble} is empty. + * + * @param source + * {@link DoubleSupplier} to query for fallback value when {@link OptionalDouble} is empty + * @return plain {@link LongToDoubleFunction} that either unwraps {@link OptionalDouble} or falls back to {@code source} + * @see #orElse(double) + * @see OptionalDouble#orElseGet(DoubleSupplier) + */ + default LongToDoubleFunction orElseGet(DoubleSupplier source) { + return new FallbackLongToDoubleFunction(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalLongToIntFunction.java b/src/main/java/com/machinezoo/noexception/optional/OptionalLongToIntFunction.java index 43eed3f..771c132 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalLongToIntFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalLongToIntFunction.java @@ -17,47 +17,47 @@ */ @FunctionalInterface public interface OptionalLongToIntFunction extends LongFunction { - /** - * Variation of {@link LongToIntFunction#applyAsInt(long)} that returns {@link OptionalInt}. - * If this {@code OptionalLongToIntFunction} is obtained from {@link ExceptionHandler#fromLongToIntFunction(LongToIntFunction)}, - * the {@link OptionalInt} will be empty only if the underlying {@link LongToIntFunction} throws. - * Otherwise the returned {@link OptionalInt} just wraps the return value of underlying {@link LongToIntFunction}. - * - * @param value - * see {@link LongToIntFunction#applyAsInt(long)} - * @return {@link OptionalInt} typically wrapping return value of {@link LongToIntFunction#applyAsInt(long)}, - * or an empty {@link OptionalInt} (typically signifying an exception) - * @see ExceptionHandler#fromLongToIntFunction(LongToIntFunction) - * @see LongToIntFunction#applyAsInt(long) - */ - @Override - OptionalInt apply(long value); - /** - * Converts this {@code OptionalLongToIntFunction} to plain {@link LongToIntFunction} using default value. - * The returned {@link LongToIntFunction} will unwrap present value from the {@link OptionalInt} if possible, - * or return {@code result} if the {@link OptionalInt} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalInt} - * @return plain {@link LongToIntFunction} that either unwraps {@link OptionalInt} or returns default value - * @see #orElseGet(IntSupplier) - * @see OptionalInt#orElse(int) - */ - default LongToIntFunction orElse(int result) { - return new DefaultLongToIntFunction(this, result); - } - /** - * Converts this {@code OptionalLongToIntFunction} to plain {@link LongToIntFunction} using fallback {@link IntSupplier}. - * The returned {@link LongToIntFunction} will unwrap present value from the {@link OptionalInt} if possible, - * or fall back to calling {@code source} if the {@link OptionalInt} is empty. - * - * @param source - * {@link IntSupplier} to query for fallback value when {@link OptionalInt} is empty - * @return plain {@link LongToIntFunction} that either unwraps {@link OptionalInt} or falls back to {@code source} - * @see #orElse(int) - * @see OptionalInt#orElseGet(IntSupplier) - */ - default LongToIntFunction orElseGet(IntSupplier source) { - return new FallbackLongToIntFunction(this, source); - } + /** + * Variation of {@link LongToIntFunction#applyAsInt(long)} that returns {@link OptionalInt}. + * If this {@code OptionalLongToIntFunction} is obtained from {@link ExceptionHandler#fromLongToIntFunction(LongToIntFunction)}, + * the {@link OptionalInt} will be empty only if the underlying {@link LongToIntFunction} throws. + * Otherwise the returned {@link OptionalInt} just wraps the return value of underlying {@link LongToIntFunction}. + * + * @param value + * see {@link LongToIntFunction#applyAsInt(long)} + * @return {@link OptionalInt} typically wrapping return value of {@link LongToIntFunction#applyAsInt(long)}, + * or an empty {@link OptionalInt} (typically signifying an exception) + * @see ExceptionHandler#fromLongToIntFunction(LongToIntFunction) + * @see LongToIntFunction#applyAsInt(long) + */ + @Override + OptionalInt apply(long value); + /** + * Converts this {@code OptionalLongToIntFunction} to plain {@link LongToIntFunction} using default value. + * The returned {@link LongToIntFunction} will unwrap present value from the {@link OptionalInt} if possible, + * or return {@code result} if the {@link OptionalInt} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalInt} + * @return plain {@link LongToIntFunction} that either unwraps {@link OptionalInt} or returns default value + * @see #orElseGet(IntSupplier) + * @see OptionalInt#orElse(int) + */ + default LongToIntFunction orElse(int result) { + return new DefaultLongToIntFunction(this, result); + } + /** + * Converts this {@code OptionalLongToIntFunction} to plain {@link LongToIntFunction} using fallback {@link IntSupplier}. + * The returned {@link LongToIntFunction} will unwrap present value from the {@link OptionalInt} if possible, + * or fall back to calling {@code source} if the {@link OptionalInt} is empty. + * + * @param source + * {@link IntSupplier} to query for fallback value when {@link OptionalInt} is empty + * @return plain {@link LongToIntFunction} that either unwraps {@link OptionalInt} or falls back to {@code source} + * @see #orElse(int) + * @see OptionalInt#orElseGet(IntSupplier) + */ + default LongToIntFunction orElseGet(IntSupplier source) { + return new FallbackLongToIntFunction(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalLongUnaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/OptionalLongUnaryOperator.java index 82c9812..6195033 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalLongUnaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalLongUnaryOperator.java @@ -17,47 +17,47 @@ */ @FunctionalInterface public interface OptionalLongUnaryOperator extends LongFunction { - /** - * Variation of {@link LongUnaryOperator#applyAsLong(long)} that returns {@link OptionalLong}. - * If this {@code OptionalLongUnaryOperator} is obtained from {@link ExceptionHandler#fromLongUnaryOperator(LongUnaryOperator)}, - * the {@link OptionalLong} will be empty only if the underlying {@link LongUnaryOperator} throws. - * Otherwise the returned {@link OptionalLong} just wraps the return value of underlying {@link LongUnaryOperator}. - * - * @param operand - * see {@link LongUnaryOperator#applyAsLong(long)} - * @return {@link OptionalLong} typically wrapping return value of {@link LongUnaryOperator#applyAsLong(long)}, - * or an empty {@link OptionalLong} (typically signifying an exception) - * @see ExceptionHandler#fromLongUnaryOperator(LongUnaryOperator) - * @see LongUnaryOperator#applyAsLong(long) - */ - @Override - OptionalLong apply(long operand); - /** - * Converts this {@code OptionalLongUnaryOperator} to plain {@link LongUnaryOperator} using default value. - * The returned {@link LongUnaryOperator} will unwrap present value from the {@link OptionalLong} if possible, - * or return {@code result} if the {@link OptionalLong} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalLong} - * @return plain {@link LongUnaryOperator} that either unwraps {@link OptionalLong} or returns default value - * @see #orElseGet(LongSupplier) - * @see OptionalLong#orElse(long) - */ - default LongUnaryOperator orElse(long result) { - return new DefaultLongUnaryOperator(this, result); - } - /** - * Converts this {@code OptionalLongUnaryOperator} to plain {@link LongUnaryOperator} using fallback {@link LongSupplier}. - * The returned {@link LongUnaryOperator} will unwrap present value from the {@link OptionalLong} if possible, - * or fall back to calling {@code source} if the {@link OptionalLong} is empty. - * - * @param source - * {@link LongSupplier} to query for fallback value when {@link OptionalLong} is empty - * @return plain {@link LongUnaryOperator} that either unwraps {@link OptionalLong} or falls back to {@code source} - * @see #orElse(long) - * @see OptionalLong#orElseGet(LongSupplier) - */ - default LongUnaryOperator orElseGet(LongSupplier source) { - return new FallbackLongUnaryOperator(this, source); - } + /** + * Variation of {@link LongUnaryOperator#applyAsLong(long)} that returns {@link OptionalLong}. + * If this {@code OptionalLongUnaryOperator} is obtained from {@link ExceptionHandler#fromLongUnaryOperator(LongUnaryOperator)}, + * the {@link OptionalLong} will be empty only if the underlying {@link LongUnaryOperator} throws. + * Otherwise the returned {@link OptionalLong} just wraps the return value of underlying {@link LongUnaryOperator}. + * + * @param operand + * see {@link LongUnaryOperator#applyAsLong(long)} + * @return {@link OptionalLong} typically wrapping return value of {@link LongUnaryOperator#applyAsLong(long)}, + * or an empty {@link OptionalLong} (typically signifying an exception) + * @see ExceptionHandler#fromLongUnaryOperator(LongUnaryOperator) + * @see LongUnaryOperator#applyAsLong(long) + */ + @Override + OptionalLong apply(long operand); + /** + * Converts this {@code OptionalLongUnaryOperator} to plain {@link LongUnaryOperator} using default value. + * The returned {@link LongUnaryOperator} will unwrap present value from the {@link OptionalLong} if possible, + * or return {@code result} if the {@link OptionalLong} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalLong} + * @return plain {@link LongUnaryOperator} that either unwraps {@link OptionalLong} or returns default value + * @see #orElseGet(LongSupplier) + * @see OptionalLong#orElse(long) + */ + default LongUnaryOperator orElse(long result) { + return new DefaultLongUnaryOperator(this, result); + } + /** + * Converts this {@code OptionalLongUnaryOperator} to plain {@link LongUnaryOperator} using fallback {@link LongSupplier}. + * The returned {@link LongUnaryOperator} will unwrap present value from the {@link OptionalLong} if possible, + * or fall back to calling {@code source} if the {@link OptionalLong} is empty. + * + * @param source + * {@link LongSupplier} to query for fallback value when {@link OptionalLong} is empty + * @return plain {@link LongUnaryOperator} that either unwraps {@link OptionalLong} or falls back to {@code source} + * @see #orElse(long) + * @see OptionalLong#orElseGet(LongSupplier) + */ + default LongUnaryOperator orElseGet(LongSupplier source) { + return new FallbackLongUnaryOperator(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalPredicate.java b/src/main/java/com/machinezoo/noexception/optional/OptionalPredicate.java index 43e9e76..392f7a2 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalPredicate.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalPredicate.java @@ -18,46 +18,46 @@ */ @FunctionalInterface public interface OptionalPredicate { - /** - * Variation of {@link Predicate#test(Object)} that returns {@link OptionalBoolean}. - * If this {@code OptionalPredicate} is obtained from {@link ExceptionHandler#predicate(Predicate)}, - * the {@link OptionalBoolean} will be empty only if the underlying {@link Predicate} throws. - * Otherwise the returned {@link OptionalBoolean} just wraps the return value of underlying {@link Predicate}. - * - * @param t - * see {@link Predicate#test(Object)} - * @return {@link OptionalBoolean} typically wrapping return value of {@link Predicate#test(Object)}, - * or an empty {@link OptionalBoolean} (typically signifying an exception) - * @see ExceptionHandler#predicate(Predicate) - * @see Predicate#test(Object) - */ - OptionalBoolean test(T t); - /** - * Converts this {@code OptionalPredicate} to plain {@link Predicate} using default value. - * The returned {@link Predicate} will unwrap present value from the {@link OptionalBoolean} if possible, - * or return {@code result} if the {@link OptionalBoolean} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalBoolean} - * @return plain {@link Predicate} that either unwraps {@link OptionalBoolean} or returns default value - * @see #orElseGet(BooleanSupplier) - * @see OptionalBoolean#orElse(boolean) - */ - default Predicate orElse(boolean result) { - return new DefaultPredicate(this, result); - } - /** - * Converts this {@code OptionalPredicate} to plain {@link Predicate} using fallback {@link BooleanSupplier}. - * The returned {@link Predicate} will unwrap present value from the {@link OptionalBoolean} if possible, - * or fall back to calling {@code source} if the {@link OptionalBoolean} is empty. - * - * @param source - * {@link BooleanSupplier} to query for fallback value when {@link OptionalBoolean} is empty - * @return plain {@link Predicate} that either unwraps {@link OptionalBoolean} or falls back to {@code source} - * @see #orElse(boolean) - * @see OptionalBoolean#orElseGet(BooleanSupplier) - */ - default Predicate orElseGet(BooleanSupplier source) { - return new FallbackPredicate(this, source); - } + /** + * Variation of {@link Predicate#test(Object)} that returns {@link OptionalBoolean}. + * If this {@code OptionalPredicate} is obtained from {@link ExceptionHandler#predicate(Predicate)}, + * the {@link OptionalBoolean} will be empty only if the underlying {@link Predicate} throws. + * Otherwise the returned {@link OptionalBoolean} just wraps the return value of underlying {@link Predicate}. + * + * @param t + * see {@link Predicate#test(Object)} + * @return {@link OptionalBoolean} typically wrapping return value of {@link Predicate#test(Object)}, + * or an empty {@link OptionalBoolean} (typically signifying an exception) + * @see ExceptionHandler#predicate(Predicate) + * @see Predicate#test(Object) + */ + OptionalBoolean test(T t); + /** + * Converts this {@code OptionalPredicate} to plain {@link Predicate} using default value. + * The returned {@link Predicate} will unwrap present value from the {@link OptionalBoolean} if possible, + * or return {@code result} if the {@link OptionalBoolean} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalBoolean} + * @return plain {@link Predicate} that either unwraps {@link OptionalBoolean} or returns default value + * @see #orElseGet(BooleanSupplier) + * @see OptionalBoolean#orElse(boolean) + */ + default Predicate orElse(boolean result) { + return new DefaultPredicate(this, result); + } + /** + * Converts this {@code OptionalPredicate} to plain {@link Predicate} using fallback {@link BooleanSupplier}. + * The returned {@link Predicate} will unwrap present value from the {@link OptionalBoolean} if possible, + * or fall back to calling {@code source} if the {@link OptionalBoolean} is empty. + * + * @param source + * {@link BooleanSupplier} to query for fallback value when {@link OptionalBoolean} is empty + * @return plain {@link Predicate} that either unwraps {@link OptionalBoolean} or falls back to {@code source} + * @see #orElse(boolean) + * @see OptionalBoolean#orElseGet(BooleanSupplier) + */ + default Predicate orElseGet(BooleanSupplier source) { + return new FallbackPredicate(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalSupplier.java b/src/main/java/com/machinezoo/noexception/optional/OptionalSupplier.java index 0d34f1c..6d97e01 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalSupplier.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalSupplier.java @@ -19,45 +19,45 @@ */ @FunctionalInterface public interface OptionalSupplier extends Supplier> { - /** - * Variation of {@link Supplier#get()} that returns {@link Optional}. - * If this {@code OptionalSupplier} is obtained from {@link ExceptionHandler#supplier(Supplier)}, - * the {@link Optional} will be empty only if the underlying {@link Supplier} throws. - * Otherwise the returned {@link Optional} just wraps the return value of underlying {@link Supplier} (possibly {@code null}). - * - * @return {@link Optional} typically wrapping return value of {@link Supplier#get()}, - * or an empty {@link Optional} (typically signifying an exception) - * @see ExceptionHandler#supplier(Supplier) - * @see Supplier#get() - */ - @Override - Optional get(); - /** - * Converts this {@code OptionalSupplier} to plain {@link Supplier} using default value. - * The returned {@link Supplier} will unwrap present value from the {@link Optional} if possible, - * or return {@code result} if the {@link Optional} is empty. - * - * @param result - * default value to return instead of an empty {@link Optional} - * @return plain {@link Supplier} that either unwraps {@link Optional} or returns default value - * @see #orElseGet(Supplier) - * @see Optional#orElse(Object) - */ - default Supplier orElse(T result) { - return new DefaultSupplier(this, result); - } - /** - * Converts this {@code OptionalSupplier} to plain {@link Supplier} using fallback {@link Supplier}. - * The returned {@link Supplier} will unwrap present value from the {@link Optional} if possible, - * or fall back to calling {@code source} if the {@link Optional} is empty. - * - * @param source - * {@link Supplier} to query for fallback value when {@link Optional} is empty - * @return plain {@link Supplier} that either unwraps {@link Optional} or falls back to {@code source} - * @see #orElse(Object) - * @see Optional#orElseGet(Supplier) - */ - default Supplier orElseGet(Supplier source) { - return new FallbackSupplier(this, source); - } + /** + * Variation of {@link Supplier#get()} that returns {@link Optional}. + * If this {@code OptionalSupplier} is obtained from {@link ExceptionHandler#supplier(Supplier)}, + * the {@link Optional} will be empty only if the underlying {@link Supplier} throws. + * Otherwise the returned {@link Optional} just wraps the return value of underlying {@link Supplier} (possibly {@code null}). + * + * @return {@link Optional} typically wrapping return value of {@link Supplier#get()}, + * or an empty {@link Optional} (typically signifying an exception) + * @see ExceptionHandler#supplier(Supplier) + * @see Supplier#get() + */ + @Override + Optional get(); + /** + * Converts this {@code OptionalSupplier} to plain {@link Supplier} using default value. + * The returned {@link Supplier} will unwrap present value from the {@link Optional} if possible, + * or return {@code result} if the {@link Optional} is empty. + * + * @param result + * default value to return instead of an empty {@link Optional} + * @return plain {@link Supplier} that either unwraps {@link Optional} or returns default value + * @see #orElseGet(Supplier) + * @see Optional#orElse(Object) + */ + default Supplier orElse(T result) { + return new DefaultSupplier(this, result); + } + /** + * Converts this {@code OptionalSupplier} to plain {@link Supplier} using fallback {@link Supplier}. + * The returned {@link Supplier} will unwrap present value from the {@link Optional} if possible, + * or fall back to calling {@code source} if the {@link Optional} is empty. + * + * @param source + * {@link Supplier} to query for fallback value when {@link Optional} is empty + * @return plain {@link Supplier} that either unwraps {@link Optional} or falls back to {@code source} + * @see #orElse(Object) + * @see Optional#orElseGet(Supplier) + */ + default Supplier orElseGet(Supplier source) { + return new FallbackSupplier(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalToDoubleBiFunction.java b/src/main/java/com/machinezoo/noexception/optional/OptionalToDoubleBiFunction.java index 6900ff7..835f783 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalToDoubleBiFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalToDoubleBiFunction.java @@ -21,49 +21,49 @@ */ @FunctionalInterface public interface OptionalToDoubleBiFunction extends BiFunction { - /** - * Variation of {@link ToDoubleBiFunction#applyAsDouble(Object, Object)} that returns {@link OptionalDouble}. - * If this {@code OptionalToDoubleBiFunction} is obtained from {@link ExceptionHandler#fromToDoubleBiFunction(ToDoubleBiFunction)}, - * the {@link OptionalDouble} will be empty only if the underlying {@link ToDoubleBiFunction} throws. - * Otherwise the returned {@link OptionalDouble} just wraps the return value of underlying {@link ToDoubleBiFunction}. - * - * @param t - * see {@link ToDoubleBiFunction#applyAsDouble(Object, Object)} - * @param u - * see {@link ToDoubleBiFunction#applyAsDouble(Object, Object)} - * @return {@link OptionalDouble} typically wrapping return value of {@link ToDoubleBiFunction#applyAsDouble(Object, Object)}, - * or an empty {@link OptionalDouble} (typically signifying an exception) - * @see ExceptionHandler#fromToDoubleBiFunction(ToDoubleBiFunction) - * @see ToDoubleBiFunction#applyAsDouble(Object, Object) - */ - @Override - OptionalDouble apply(T t, U u); - /** - * Converts this {@code OptionalToDoubleBiFunction} to plain {@link ToDoubleBiFunction} using default value. - * The returned {@link ToDoubleBiFunction} will unwrap present value from the {@link OptionalDouble} if possible, - * or return {@code result} if the {@link OptionalDouble} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalDouble} - * @return plain {@link ToDoubleBiFunction} that either unwraps {@link OptionalDouble} or returns default value - * @see #orElseGet(DoubleSupplier) - * @see OptionalDouble#orElse(double) - */ - default ToDoubleBiFunction orElse(double result) { - return new DefaultToDoubleBiFunction(this, result); - } - /** - * Converts this {@code OptionalToDoubleBiFunction} to plain {@link ToDoubleBiFunction} using fallback {@link DoubleSupplier}. - * The returned {@link ToDoubleBiFunction} will unwrap present value from the {@link OptionalDouble} if possible, - * or fall back to calling {@code source} if the {@link OptionalDouble} is empty. - * - * @param source - * {@link DoubleSupplier} to query for fallback value when {@link OptionalDouble} is empty - * @return plain {@link ToDoubleBiFunction} that either unwraps {@link OptionalDouble} or falls back to {@code source} - * @see #orElse(double) - * @see OptionalDouble#orElseGet(DoubleSupplier) - */ - default ToDoubleBiFunction orElseGet(DoubleSupplier source) { - return new FallbackToDoubleBiFunction(this, source); - } + /** + * Variation of {@link ToDoubleBiFunction#applyAsDouble(Object, Object)} that returns {@link OptionalDouble}. + * If this {@code OptionalToDoubleBiFunction} is obtained from {@link ExceptionHandler#fromToDoubleBiFunction(ToDoubleBiFunction)}, + * the {@link OptionalDouble} will be empty only if the underlying {@link ToDoubleBiFunction} throws. + * Otherwise the returned {@link OptionalDouble} just wraps the return value of underlying {@link ToDoubleBiFunction}. + * + * @param t + * see {@link ToDoubleBiFunction#applyAsDouble(Object, Object)} + * @param u + * see {@link ToDoubleBiFunction#applyAsDouble(Object, Object)} + * @return {@link OptionalDouble} typically wrapping return value of {@link ToDoubleBiFunction#applyAsDouble(Object, Object)}, + * or an empty {@link OptionalDouble} (typically signifying an exception) + * @see ExceptionHandler#fromToDoubleBiFunction(ToDoubleBiFunction) + * @see ToDoubleBiFunction#applyAsDouble(Object, Object) + */ + @Override + OptionalDouble apply(T t, U u); + /** + * Converts this {@code OptionalToDoubleBiFunction} to plain {@link ToDoubleBiFunction} using default value. + * The returned {@link ToDoubleBiFunction} will unwrap present value from the {@link OptionalDouble} if possible, + * or return {@code result} if the {@link OptionalDouble} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalDouble} + * @return plain {@link ToDoubleBiFunction} that either unwraps {@link OptionalDouble} or returns default value + * @see #orElseGet(DoubleSupplier) + * @see OptionalDouble#orElse(double) + */ + default ToDoubleBiFunction orElse(double result) { + return new DefaultToDoubleBiFunction(this, result); + } + /** + * Converts this {@code OptionalToDoubleBiFunction} to plain {@link ToDoubleBiFunction} using fallback {@link DoubleSupplier}. + * The returned {@link ToDoubleBiFunction} will unwrap present value from the {@link OptionalDouble} if possible, + * or fall back to calling {@code source} if the {@link OptionalDouble} is empty. + * + * @param source + * {@link DoubleSupplier} to query for fallback value when {@link OptionalDouble} is empty + * @return plain {@link ToDoubleBiFunction} that either unwraps {@link OptionalDouble} or falls back to {@code source} + * @see #orElse(double) + * @see OptionalDouble#orElseGet(DoubleSupplier) + */ + default ToDoubleBiFunction orElseGet(DoubleSupplier source) { + return new FallbackToDoubleBiFunction(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalToDoubleFunction.java b/src/main/java/com/machinezoo/noexception/optional/OptionalToDoubleFunction.java index 4da76f1..2c38a4b 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalToDoubleFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalToDoubleFunction.java @@ -19,47 +19,47 @@ */ @FunctionalInterface public interface OptionalToDoubleFunction extends Function { - /** - * Variation of {@link ToDoubleFunction#applyAsDouble(Object)} that returns {@link OptionalDouble}. - * If this {@code OptionalToDoubleFunction} is obtained from {@link ExceptionHandler#fromToDoubleFunction(ToDoubleFunction)}, - * the {@link OptionalDouble} will be empty only if the underlying {@link ToDoubleFunction} throws. - * Otherwise the returned {@link OptionalDouble} just wraps the return value of underlying {@link ToDoubleFunction}. - * - * @param value - * see {@link ToDoubleFunction#applyAsDouble(Object)} - * @return {@link OptionalDouble} typically wrapping return value of {@link ToDoubleFunction#applyAsDouble(Object)}, - * or an empty {@link OptionalDouble} (typically signifying an exception) - * @see ExceptionHandler#fromToDoubleFunction(ToDoubleFunction) - * @see ToDoubleFunction#applyAsDouble(Object) - */ - @Override - OptionalDouble apply(T value); - /** - * Converts this {@code OptionalToDoubleFunction} to plain {@link ToDoubleFunction} using default value. - * The returned {@link ToDoubleFunction} will unwrap present value from the {@link OptionalDouble} if possible, - * or return {@code result} if the {@link OptionalDouble} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalDouble} - * @return plain {@link ToDoubleFunction} that either unwraps {@link OptionalDouble} or returns default value - * @see #orElseGet(DoubleSupplier) - * @see OptionalDouble#orElse(double) - */ - default ToDoubleFunction orElse(double result) { - return new DefaultToDoubleFunction(this, result); - } - /** - * Converts this {@code OptionalToDoubleFunction} to plain {@link ToDoubleFunction} using fallback {@link DoubleSupplier}. - * The returned {@link ToDoubleFunction} will unwrap present value from the {@link OptionalDouble} if possible, - * or fall back to calling {@code source} if the {@link OptionalDouble} is empty. - * - * @param source - * {@link DoubleSupplier} to query for fallback value when {@link OptionalDouble} is empty - * @return plain {@link ToDoubleFunction} that either unwraps {@link OptionalDouble} or falls back to {@code source} - * @see #orElse(double) - * @see OptionalDouble#orElseGet(DoubleSupplier) - */ - default ToDoubleFunction orElseGet(DoubleSupplier source) { - return new FallbackToDoubleFunction(this, source); - } + /** + * Variation of {@link ToDoubleFunction#applyAsDouble(Object)} that returns {@link OptionalDouble}. + * If this {@code OptionalToDoubleFunction} is obtained from {@link ExceptionHandler#fromToDoubleFunction(ToDoubleFunction)}, + * the {@link OptionalDouble} will be empty only if the underlying {@link ToDoubleFunction} throws. + * Otherwise the returned {@link OptionalDouble} just wraps the return value of underlying {@link ToDoubleFunction}. + * + * @param value + * see {@link ToDoubleFunction#applyAsDouble(Object)} + * @return {@link OptionalDouble} typically wrapping return value of {@link ToDoubleFunction#applyAsDouble(Object)}, + * or an empty {@link OptionalDouble} (typically signifying an exception) + * @see ExceptionHandler#fromToDoubleFunction(ToDoubleFunction) + * @see ToDoubleFunction#applyAsDouble(Object) + */ + @Override + OptionalDouble apply(T value); + /** + * Converts this {@code OptionalToDoubleFunction} to plain {@link ToDoubleFunction} using default value. + * The returned {@link ToDoubleFunction} will unwrap present value from the {@link OptionalDouble} if possible, + * or return {@code result} if the {@link OptionalDouble} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalDouble} + * @return plain {@link ToDoubleFunction} that either unwraps {@link OptionalDouble} or returns default value + * @see #orElseGet(DoubleSupplier) + * @see OptionalDouble#orElse(double) + */ + default ToDoubleFunction orElse(double result) { + return new DefaultToDoubleFunction(this, result); + } + /** + * Converts this {@code OptionalToDoubleFunction} to plain {@link ToDoubleFunction} using fallback {@link DoubleSupplier}. + * The returned {@link ToDoubleFunction} will unwrap present value from the {@link OptionalDouble} if possible, + * or fall back to calling {@code source} if the {@link OptionalDouble} is empty. + * + * @param source + * {@link DoubleSupplier} to query for fallback value when {@link OptionalDouble} is empty + * @return plain {@link ToDoubleFunction} that either unwraps {@link OptionalDouble} or falls back to {@code source} + * @see #orElse(double) + * @see OptionalDouble#orElseGet(DoubleSupplier) + */ + default ToDoubleFunction orElseGet(DoubleSupplier source) { + return new FallbackToDoubleFunction(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalToIntBiFunction.java b/src/main/java/com/machinezoo/noexception/optional/OptionalToIntBiFunction.java index e19df9b..b47db16 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalToIntBiFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalToIntBiFunction.java @@ -21,49 +21,49 @@ */ @FunctionalInterface public interface OptionalToIntBiFunction extends BiFunction { - /** - * Variation of {@link ToIntBiFunction#applyAsInt(Object, Object)} that returns {@link OptionalInt}. - * If this {@code OptionalToIntBiFunction} is obtained from {@link ExceptionHandler#fromToIntBiFunction(ToIntBiFunction)}, - * the {@link OptionalInt} will be empty only if the underlying {@link ToIntBiFunction} throws. - * Otherwise the returned {@link OptionalInt} just wraps the return value of underlying {@link ToIntBiFunction}. - * - * @param t - * see {@link ToIntBiFunction#applyAsInt(Object, Object)} - * @param u - * see {@link ToIntBiFunction#applyAsInt(Object, Object)} - * @return {@link OptionalInt} typically wrapping return value of {@link ToIntBiFunction#applyAsInt(Object, Object)}, - * or an empty {@link OptionalInt} (typically signifying an exception) - * @see ExceptionHandler#fromToIntBiFunction(ToIntBiFunction) - * @see ToIntBiFunction#applyAsInt(Object, Object) - */ - @Override - OptionalInt apply(T t, U u); - /** - * Converts this {@code OptionalToIntBiFunction} to plain {@link ToIntBiFunction} using default value. - * The returned {@link ToIntBiFunction} will unwrap present value from the {@link OptionalInt} if possible, - * or return {@code result} if the {@link OptionalInt} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalInt} - * @return plain {@link ToIntBiFunction} that either unwraps {@link OptionalInt} or returns default value - * @see #orElseGet(IntSupplier) - * @see OptionalInt#orElse(int) - */ - default ToIntBiFunction orElse(int result) { - return new DefaultToIntBiFunction(this, result); - } - /** - * Converts this {@code OptionalToIntBiFunction} to plain {@link ToIntBiFunction} using fallback {@link IntSupplier}. - * The returned {@link ToIntBiFunction} will unwrap present value from the {@link OptionalInt} if possible, - * or fall back to calling {@code source} if the {@link OptionalInt} is empty. - * - * @param source - * {@link IntSupplier} to query for fallback value when {@link OptionalInt} is empty - * @return plain {@link ToIntBiFunction} that either unwraps {@link OptionalInt} or falls back to {@code source} - * @see #orElse(int) - * @see OptionalInt#orElseGet(IntSupplier) - */ - default ToIntBiFunction orElseGet(IntSupplier source) { - return new FallbackToIntBiFunction(this, source); - } + /** + * Variation of {@link ToIntBiFunction#applyAsInt(Object, Object)} that returns {@link OptionalInt}. + * If this {@code OptionalToIntBiFunction} is obtained from {@link ExceptionHandler#fromToIntBiFunction(ToIntBiFunction)}, + * the {@link OptionalInt} will be empty only if the underlying {@link ToIntBiFunction} throws. + * Otherwise the returned {@link OptionalInt} just wraps the return value of underlying {@link ToIntBiFunction}. + * + * @param t + * see {@link ToIntBiFunction#applyAsInt(Object, Object)} + * @param u + * see {@link ToIntBiFunction#applyAsInt(Object, Object)} + * @return {@link OptionalInt} typically wrapping return value of {@link ToIntBiFunction#applyAsInt(Object, Object)}, + * or an empty {@link OptionalInt} (typically signifying an exception) + * @see ExceptionHandler#fromToIntBiFunction(ToIntBiFunction) + * @see ToIntBiFunction#applyAsInt(Object, Object) + */ + @Override + OptionalInt apply(T t, U u); + /** + * Converts this {@code OptionalToIntBiFunction} to plain {@link ToIntBiFunction} using default value. + * The returned {@link ToIntBiFunction} will unwrap present value from the {@link OptionalInt} if possible, + * or return {@code result} if the {@link OptionalInt} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalInt} + * @return plain {@link ToIntBiFunction} that either unwraps {@link OptionalInt} or returns default value + * @see #orElseGet(IntSupplier) + * @see OptionalInt#orElse(int) + */ + default ToIntBiFunction orElse(int result) { + return new DefaultToIntBiFunction(this, result); + } + /** + * Converts this {@code OptionalToIntBiFunction} to plain {@link ToIntBiFunction} using fallback {@link IntSupplier}. + * The returned {@link ToIntBiFunction} will unwrap present value from the {@link OptionalInt} if possible, + * or fall back to calling {@code source} if the {@link OptionalInt} is empty. + * + * @param source + * {@link IntSupplier} to query for fallback value when {@link OptionalInt} is empty + * @return plain {@link ToIntBiFunction} that either unwraps {@link OptionalInt} or falls back to {@code source} + * @see #orElse(int) + * @see OptionalInt#orElseGet(IntSupplier) + */ + default ToIntBiFunction orElseGet(IntSupplier source) { + return new FallbackToIntBiFunction(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalToIntFunction.java b/src/main/java/com/machinezoo/noexception/optional/OptionalToIntFunction.java index 82bbb76..15b1f39 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalToIntFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalToIntFunction.java @@ -19,47 +19,47 @@ */ @FunctionalInterface public interface OptionalToIntFunction extends Function { - /** - * Variation of {@link ToIntFunction#applyAsInt(Object)} that returns {@link OptionalInt}. - * If this {@code OptionalToIntFunction} is obtained from {@link ExceptionHandler#fromToIntFunction(ToIntFunction)}, - * the {@link OptionalInt} will be empty only if the underlying {@link ToIntFunction} throws. - * Otherwise the returned {@link OptionalInt} just wraps the return value of underlying {@link ToIntFunction}. - * - * @param value - * see {@link ToIntFunction#applyAsInt(Object)} - * @return {@link OptionalInt} typically wrapping return value of {@link ToIntFunction#applyAsInt(Object)}, - * or an empty {@link OptionalInt} (typically signifying an exception) - * @see ExceptionHandler#fromToIntFunction(ToIntFunction) - * @see ToIntFunction#applyAsInt(Object) - */ - @Override - OptionalInt apply(T value); - /** - * Converts this {@code OptionalToIntFunction} to plain {@link ToIntFunction} using default value. - * The returned {@link ToIntFunction} will unwrap present value from the {@link OptionalInt} if possible, - * or return {@code result} if the {@link OptionalInt} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalInt} - * @return plain {@link ToIntFunction} that either unwraps {@link OptionalInt} or returns default value - * @see #orElseGet(IntSupplier) - * @see OptionalInt#orElse(int) - */ - default ToIntFunction orElse(int result) { - return new DefaultToIntFunction(this, result); - } - /** - * Converts this {@code OptionalToIntFunction} to plain {@link ToIntFunction} using fallback {@link IntSupplier}. - * The returned {@link ToIntFunction} will unwrap present value from the {@link OptionalInt} if possible, - * or fall back to calling {@code source} if the {@link OptionalInt} is empty. - * - * @param source - * {@link IntSupplier} to query for fallback value when {@link OptionalInt} is empty - * @return plain {@link ToIntFunction} that either unwraps {@link OptionalInt} or falls back to {@code source} - * @see #orElse(int) - * @see OptionalInt#orElseGet(IntSupplier) - */ - default ToIntFunction orElseGet(IntSupplier source) { - return new FallbackToIntFunction(this, source); - } + /** + * Variation of {@link ToIntFunction#applyAsInt(Object)} that returns {@link OptionalInt}. + * If this {@code OptionalToIntFunction} is obtained from {@link ExceptionHandler#fromToIntFunction(ToIntFunction)}, + * the {@link OptionalInt} will be empty only if the underlying {@link ToIntFunction} throws. + * Otherwise the returned {@link OptionalInt} just wraps the return value of underlying {@link ToIntFunction}. + * + * @param value + * see {@link ToIntFunction#applyAsInt(Object)} + * @return {@link OptionalInt} typically wrapping return value of {@link ToIntFunction#applyAsInt(Object)}, + * or an empty {@link OptionalInt} (typically signifying an exception) + * @see ExceptionHandler#fromToIntFunction(ToIntFunction) + * @see ToIntFunction#applyAsInt(Object) + */ + @Override + OptionalInt apply(T value); + /** + * Converts this {@code OptionalToIntFunction} to plain {@link ToIntFunction} using default value. + * The returned {@link ToIntFunction} will unwrap present value from the {@link OptionalInt} if possible, + * or return {@code result} if the {@link OptionalInt} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalInt} + * @return plain {@link ToIntFunction} that either unwraps {@link OptionalInt} or returns default value + * @see #orElseGet(IntSupplier) + * @see OptionalInt#orElse(int) + */ + default ToIntFunction orElse(int result) { + return new DefaultToIntFunction(this, result); + } + /** + * Converts this {@code OptionalToIntFunction} to plain {@link ToIntFunction} using fallback {@link IntSupplier}. + * The returned {@link ToIntFunction} will unwrap present value from the {@link OptionalInt} if possible, + * or fall back to calling {@code source} if the {@link OptionalInt} is empty. + * + * @param source + * {@link IntSupplier} to query for fallback value when {@link OptionalInt} is empty + * @return plain {@link ToIntFunction} that either unwraps {@link OptionalInt} or falls back to {@code source} + * @see #orElse(int) + * @see OptionalInt#orElseGet(IntSupplier) + */ + default ToIntFunction orElseGet(IntSupplier source) { + return new FallbackToIntFunction(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalToLongBiFunction.java b/src/main/java/com/machinezoo/noexception/optional/OptionalToLongBiFunction.java index 1604a4c..20eca99 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalToLongBiFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalToLongBiFunction.java @@ -21,49 +21,49 @@ */ @FunctionalInterface public interface OptionalToLongBiFunction extends BiFunction { - /** - * Variation of {@link ToLongBiFunction#applyAsLong(Object, Object)} that returns {@link OptionalLong}. - * If this {@code OptionalToLongBiFunction} is obtained from {@link ExceptionHandler#fromToLongBiFunction(ToLongBiFunction)}, - * the {@link OptionalLong} will be empty only if the underlying {@link ToLongBiFunction} throws. - * Otherwise the returned {@link OptionalLong} just wraps the return value of underlying {@link ToLongBiFunction}. - * - * @param t - * see {@link ToLongBiFunction#applyAsLong(Object, Object)} - * @param u - * see {@link ToLongBiFunction#applyAsLong(Object, Object)} - * @return {@link OptionalLong} typically wrapping return value of {@link ToLongBiFunction#applyAsLong(Object, Object)}, - * or an empty {@link OptionalLong} (typically signifying an exception) - * @see ExceptionHandler#fromToLongBiFunction(ToLongBiFunction) - * @see ToLongBiFunction#applyAsLong(Object, Object) - */ - @Override - OptionalLong apply(T t, U u); - /** - * Converts this {@code OptionalToLongBiFunction} to plain {@link ToLongBiFunction} using default value. - * The returned {@link ToLongBiFunction} will unwrap present value from the {@link OptionalLong} if possible, - * or return {@code result} if the {@link OptionalLong} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalLong} - * @return plain {@link ToLongBiFunction} that either unwraps {@link OptionalLong} or returns default value - * @see #orElseGet(LongSupplier) - * @see OptionalLong#orElse(long) - */ - default ToLongBiFunction orElse(long result) { - return new DefaultToLongBiFunction(this, result); - } - /** - * Converts this {@code OptionalToLongBiFunction} to plain {@link ToLongBiFunction} using fallback {@link LongSupplier}. - * The returned {@link ToLongBiFunction} will unwrap present value from the {@link OptionalLong} if possible, - * or fall back to calling {@code source} if the {@link OptionalLong} is empty. - * - * @param source - * {@link LongSupplier} to query for fallback value when {@link OptionalLong} is empty - * @return plain {@link ToLongBiFunction} that either unwraps {@link OptionalLong} or falls back to {@code source} - * @see #orElse(long) - * @see OptionalLong#orElseGet(LongSupplier) - */ - default ToLongBiFunction orElseGet(LongSupplier source) { - return new FallbackToLongBiFunction(this, source); - } + /** + * Variation of {@link ToLongBiFunction#applyAsLong(Object, Object)} that returns {@link OptionalLong}. + * If this {@code OptionalToLongBiFunction} is obtained from {@link ExceptionHandler#fromToLongBiFunction(ToLongBiFunction)}, + * the {@link OptionalLong} will be empty only if the underlying {@link ToLongBiFunction} throws. + * Otherwise the returned {@link OptionalLong} just wraps the return value of underlying {@link ToLongBiFunction}. + * + * @param t + * see {@link ToLongBiFunction#applyAsLong(Object, Object)} + * @param u + * see {@link ToLongBiFunction#applyAsLong(Object, Object)} + * @return {@link OptionalLong} typically wrapping return value of {@link ToLongBiFunction#applyAsLong(Object, Object)}, + * or an empty {@link OptionalLong} (typically signifying an exception) + * @see ExceptionHandler#fromToLongBiFunction(ToLongBiFunction) + * @see ToLongBiFunction#applyAsLong(Object, Object) + */ + @Override + OptionalLong apply(T t, U u); + /** + * Converts this {@code OptionalToLongBiFunction} to plain {@link ToLongBiFunction} using default value. + * The returned {@link ToLongBiFunction} will unwrap present value from the {@link OptionalLong} if possible, + * or return {@code result} if the {@link OptionalLong} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalLong} + * @return plain {@link ToLongBiFunction} that either unwraps {@link OptionalLong} or returns default value + * @see #orElseGet(LongSupplier) + * @see OptionalLong#orElse(long) + */ + default ToLongBiFunction orElse(long result) { + return new DefaultToLongBiFunction(this, result); + } + /** + * Converts this {@code OptionalToLongBiFunction} to plain {@link ToLongBiFunction} using fallback {@link LongSupplier}. + * The returned {@link ToLongBiFunction} will unwrap present value from the {@link OptionalLong} if possible, + * or fall back to calling {@code source} if the {@link OptionalLong} is empty. + * + * @param source + * {@link LongSupplier} to query for fallback value when {@link OptionalLong} is empty + * @return plain {@link ToLongBiFunction} that either unwraps {@link OptionalLong} or falls back to {@code source} + * @see #orElse(long) + * @see OptionalLong#orElseGet(LongSupplier) + */ + default ToLongBiFunction orElseGet(LongSupplier source) { + return new FallbackToLongBiFunction(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalToLongFunction.java b/src/main/java/com/machinezoo/noexception/optional/OptionalToLongFunction.java index eca099c..8f3a3e6 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalToLongFunction.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalToLongFunction.java @@ -19,47 +19,47 @@ */ @FunctionalInterface public interface OptionalToLongFunction extends Function { - /** - * Variation of {@link ToLongFunction#applyAsLong(Object)} that returns {@link OptionalLong}. - * If this {@code OptionalToLongFunction} is obtained from {@link ExceptionHandler#fromToLongFunction(ToLongFunction)}, - * the {@link OptionalLong} will be empty only if the underlying {@link ToLongFunction} throws. - * Otherwise the returned {@link OptionalLong} just wraps the return value of underlying {@link ToLongFunction}. - * - * @param value - * see {@link ToLongFunction#applyAsLong(Object)} - * @return {@link OptionalLong} typically wrapping return value of {@link ToLongFunction#applyAsLong(Object)}, - * or an empty {@link OptionalLong} (typically signifying an exception) - * @see ExceptionHandler#fromToLongFunction(ToLongFunction) - * @see ToLongFunction#applyAsLong(Object) - */ - @Override - OptionalLong apply(T value); - /** - * Converts this {@code OptionalToLongFunction} to plain {@link ToLongFunction} using default value. - * The returned {@link ToLongFunction} will unwrap present value from the {@link OptionalLong} if possible, - * or return {@code result} if the {@link OptionalLong} is empty. - * - * @param result - * default value to return instead of an empty {@link OptionalLong} - * @return plain {@link ToLongFunction} that either unwraps {@link OptionalLong} or returns default value - * @see #orElseGet(LongSupplier) - * @see OptionalLong#orElse(long) - */ - default ToLongFunction orElse(long result) { - return new DefaultToLongFunction(this, result); - } - /** - * Converts this {@code OptionalToLongFunction} to plain {@link ToLongFunction} using fallback {@link LongSupplier}. - * The returned {@link ToLongFunction} will unwrap present value from the {@link OptionalLong} if possible, - * or fall back to calling {@code source} if the {@link OptionalLong} is empty. - * - * @param source - * {@link LongSupplier} to query for fallback value when {@link OptionalLong} is empty - * @return plain {@link ToLongFunction} that either unwraps {@link OptionalLong} or falls back to {@code source} - * @see #orElse(long) - * @see OptionalLong#orElseGet(LongSupplier) - */ - default ToLongFunction orElseGet(LongSupplier source) { - return new FallbackToLongFunction(this, source); - } + /** + * Variation of {@link ToLongFunction#applyAsLong(Object)} that returns {@link OptionalLong}. + * If this {@code OptionalToLongFunction} is obtained from {@link ExceptionHandler#fromToLongFunction(ToLongFunction)}, + * the {@link OptionalLong} will be empty only if the underlying {@link ToLongFunction} throws. + * Otherwise the returned {@link OptionalLong} just wraps the return value of underlying {@link ToLongFunction}. + * + * @param value + * see {@link ToLongFunction#applyAsLong(Object)} + * @return {@link OptionalLong} typically wrapping return value of {@link ToLongFunction#applyAsLong(Object)}, + * or an empty {@link OptionalLong} (typically signifying an exception) + * @see ExceptionHandler#fromToLongFunction(ToLongFunction) + * @see ToLongFunction#applyAsLong(Object) + */ + @Override + OptionalLong apply(T value); + /** + * Converts this {@code OptionalToLongFunction} to plain {@link ToLongFunction} using default value. + * The returned {@link ToLongFunction} will unwrap present value from the {@link OptionalLong} if possible, + * or return {@code result} if the {@link OptionalLong} is empty. + * + * @param result + * default value to return instead of an empty {@link OptionalLong} + * @return plain {@link ToLongFunction} that either unwraps {@link OptionalLong} or returns default value + * @see #orElseGet(LongSupplier) + * @see OptionalLong#orElse(long) + */ + default ToLongFunction orElse(long result) { + return new DefaultToLongFunction(this, result); + } + /** + * Converts this {@code OptionalToLongFunction} to plain {@link ToLongFunction} using fallback {@link LongSupplier}. + * The returned {@link ToLongFunction} will unwrap present value from the {@link OptionalLong} if possible, + * or fall back to calling {@code source} if the {@link OptionalLong} is empty. + * + * @param source + * {@link LongSupplier} to query for fallback value when {@link OptionalLong} is empty + * @return plain {@link ToLongFunction} that either unwraps {@link OptionalLong} or falls back to {@code source} + * @see #orElse(long) + * @see OptionalLong#orElseGet(LongSupplier) + */ + default ToLongFunction orElseGet(LongSupplier source) { + return new FallbackToLongFunction(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/optional/OptionalUnaryOperator.java b/src/main/java/com/machinezoo/noexception/optional/OptionalUnaryOperator.java index 8fcaf94..d323359 100644 --- a/src/main/java/com/machinezoo/noexception/optional/OptionalUnaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/optional/OptionalUnaryOperator.java @@ -19,47 +19,47 @@ */ @FunctionalInterface public interface OptionalUnaryOperator extends Function> { - /** - * Variation of {@link UnaryOperator#apply(Object)} that returns {@link Optional}. - * If this {@code OptionalUnaryOperator} is obtained from {@link ExceptionHandler#fromUnaryOperator(UnaryOperator)}, - * the {@link Optional} will be empty only if the underlying {@link UnaryOperator} throws. - * Otherwise the returned {@link Optional} just wraps the return value of underlying {@link UnaryOperator} (possibly {@code null}). - * - * @param operand - * see {@link UnaryOperator#apply(Object)} - * @return {@link Optional} typically wrapping return value of {@link UnaryOperator#apply(Object)}, - * or an empty {@link Optional} (typically signifying an exception) - * @see ExceptionHandler#fromUnaryOperator(UnaryOperator) - * @see UnaryOperator#apply(Object) - */ - @Override - Optional apply(T operand); - /** - * Converts this {@code OptionalUnaryOperator} to plain {@link UnaryOperator} using default value. - * The returned {@link UnaryOperator} will unwrap present value from the {@link Optional} if possible, - * or return {@code result} if the {@link Optional} is empty. - * - * @param result - * default value to return instead of an empty {@link Optional} - * @return plain {@link UnaryOperator} that either unwraps {@link Optional} or returns default value - * @see #orElseGet(Supplier) - * @see Optional#orElse(Object) - */ - default UnaryOperator orElse(T result) { - return new DefaultUnaryOperator(this, result); - } - /** - * Converts this {@code OptionalUnaryOperator} to plain {@link UnaryOperator} using fallback {@link Supplier}. - * The returned {@link UnaryOperator} will unwrap present value from the {@link Optional} if possible, - * or fall back to calling {@code source} if the {@link Optional} is empty. - * - * @param source - * {@link Supplier} to query for fallback value when {@link Optional} is empty - * @return plain {@link UnaryOperator} that either unwraps {@link Optional} or falls back to {@code source} - * @see #orElse(Object) - * @see Optional#orElseGet(Supplier) - */ - default UnaryOperator orElseGet(Supplier source) { - return new FallbackUnaryOperator(this, source); - } + /** + * Variation of {@link UnaryOperator#apply(Object)} that returns {@link Optional}. + * If this {@code OptionalUnaryOperator} is obtained from {@link ExceptionHandler#fromUnaryOperator(UnaryOperator)}, + * the {@link Optional} will be empty only if the underlying {@link UnaryOperator} throws. + * Otherwise the returned {@link Optional} just wraps the return value of underlying {@link UnaryOperator} (possibly {@code null}). + * + * @param operand + * see {@link UnaryOperator#apply(Object)} + * @return {@link Optional} typically wrapping return value of {@link UnaryOperator#apply(Object)}, + * or an empty {@link Optional} (typically signifying an exception) + * @see ExceptionHandler#fromUnaryOperator(UnaryOperator) + * @see UnaryOperator#apply(Object) + */ + @Override + Optional apply(T operand); + /** + * Converts this {@code OptionalUnaryOperator} to plain {@link UnaryOperator} using default value. + * The returned {@link UnaryOperator} will unwrap present value from the {@link Optional} if possible, + * or return {@code result} if the {@link Optional} is empty. + * + * @param result + * default value to return instead of an empty {@link Optional} + * @return plain {@link UnaryOperator} that either unwraps {@link Optional} or returns default value + * @see #orElseGet(Supplier) + * @see Optional#orElse(Object) + */ + default UnaryOperator orElse(T result) { + return new DefaultUnaryOperator(this, result); + } + /** + * Converts this {@code OptionalUnaryOperator} to plain {@link UnaryOperator} using fallback {@link Supplier}. + * The returned {@link UnaryOperator} will unwrap present value from the {@link Optional} if possible, + * or fall back to calling {@code source} if the {@link Optional} is empty. + * + * @param source + * {@link Supplier} to query for fallback value when {@link Optional} is empty + * @return plain {@link UnaryOperator} that either unwraps {@link Optional} or falls back to {@code source} + * @see #orElse(Object) + * @see Optional#orElseGet(Supplier) + */ + default UnaryOperator orElseGet(Supplier source) { + return new FallbackUnaryOperator(this, source); + } } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingBiConsumer.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingBiConsumer.java index d6fcdd7..91912ee 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingBiConsumer.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingBiConsumer.java @@ -20,17 +20,17 @@ */ @FunctionalInterface public interface ThrowingBiConsumer { - /** - * Variation of {@link BiConsumer#accept(Object, Object)} that allows throwing checked exceptions. - * - * @param t - * see {@link BiConsumer#accept(Object, Object)} - * @param u - * see {@link BiConsumer#accept(Object, Object)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromBiConsumer(ThrowingBiConsumer) - * @see BiConsumer#accept(Object, Object) - */ - void accept(T t, U u) throws Throwable; + /** + * Variation of {@link BiConsumer#accept(Object, Object)} that allows throwing checked exceptions. + * + * @param t + * see {@link BiConsumer#accept(Object, Object)} + * @param u + * see {@link BiConsumer#accept(Object, Object)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromBiConsumer(ThrowingBiConsumer) + * @see BiConsumer#accept(Object, Object) + */ + void accept(T t, U u) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingBiFunction.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingBiFunction.java index 513212f..1723ca3 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingBiFunction.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingBiFunction.java @@ -22,18 +22,18 @@ */ @FunctionalInterface public interface ThrowingBiFunction { - /** - * Variation of {@link BiFunction#apply(Object, Object)} that allows throwing checked exceptions. - * - * @param t - * see {@link BiFunction#apply(Object, Object)} - * @param u - * see {@link BiFunction#apply(Object, Object)} - * @return see {@link BiFunction#apply(Object, Object)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromBiFunction(ThrowingBiFunction) - * @see BiFunction#apply(Object, Object) - */ - R apply(T t, U u) throws Throwable; + /** + * Variation of {@link BiFunction#apply(Object, Object)} that allows throwing checked exceptions. + * + * @param t + * see {@link BiFunction#apply(Object, Object)} + * @param u + * see {@link BiFunction#apply(Object, Object)} + * @return see {@link BiFunction#apply(Object, Object)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromBiFunction(ThrowingBiFunction) + * @see BiFunction#apply(Object, Object) + */ + R apply(T t, U u) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingBiPredicate.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingBiPredicate.java index 5eba65d..f0c3dca 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingBiPredicate.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingBiPredicate.java @@ -20,18 +20,18 @@ */ @FunctionalInterface public interface ThrowingBiPredicate { - /** - * Variation of {@link BiPredicate#test(Object, Object)} that allows throwing checked exceptions. - * - * @param t - * see {@link BiPredicate#test(Object, Object)} - * @param u - * see {@link BiPredicate#test(Object, Object)} - * @return see {@link BiPredicate#test(Object, Object)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromBiPredicate(ThrowingBiPredicate) - * @see BiPredicate#test(Object, Object) - */ - boolean test(T t, U u) throws Throwable; + /** + * Variation of {@link BiPredicate#test(Object, Object)} that allows throwing checked exceptions. + * + * @param t + * see {@link BiPredicate#test(Object, Object)} + * @param u + * see {@link BiPredicate#test(Object, Object)} + * @return see {@link BiPredicate#test(Object, Object)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromBiPredicate(ThrowingBiPredicate) + * @see BiPredicate#test(Object, Object) + */ + boolean test(T t, U u) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingBooleanSupplier.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingBooleanSupplier.java index 6e444f2..67b3d9e 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingBooleanSupplier.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingBooleanSupplier.java @@ -16,14 +16,14 @@ */ @FunctionalInterface public interface ThrowingBooleanSupplier { - /** - * Variation of {@link BooleanSupplier#getAsBoolean()} that allows throwing checked exceptions. - * - * @return see {@link BooleanSupplier#getAsBoolean()} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromBooleanSupplier(ThrowingBooleanSupplier) - * @see BooleanSupplier#getAsBoolean() - */ - boolean getAsBoolean() throws Throwable; + /** + * Variation of {@link BooleanSupplier#getAsBoolean()} that allows throwing checked exceptions. + * + * @return see {@link BooleanSupplier#getAsBoolean()} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromBooleanSupplier(ThrowingBooleanSupplier) + * @see BooleanSupplier#getAsBoolean() + */ + boolean getAsBoolean() throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingComparator.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingComparator.java index c55c4e3..48cd05b 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingComparator.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingComparator.java @@ -18,18 +18,18 @@ */ @FunctionalInterface public interface ThrowingComparator { - /** - * Variation of {@link Comparator#compare(Object, Object)} that allows throwing checked exceptions. - * - * @param left - * see {@link Comparator#compare(Object, Object)} - * @param right - * see {@link Comparator#compare(Object, Object)} - * @return see {@link Comparator#compare(Object, Object)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#comparator(ThrowingComparator) - * @see Comparator#compare(Object, Object) - */ - int compare(T left, T right) throws Throwable; + /** + * Variation of {@link Comparator#compare(Object, Object)} that allows throwing checked exceptions. + * + * @param left + * see {@link Comparator#compare(Object, Object)} + * @param right + * see {@link Comparator#compare(Object, Object)} + * @return see {@link Comparator#compare(Object, Object)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#comparator(ThrowingComparator) + * @see Comparator#compare(Object, Object) + */ + int compare(T left, T right) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingConsumer.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingConsumer.java index bcaf569..19443d8 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingConsumer.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingConsumer.java @@ -18,15 +18,15 @@ */ @FunctionalInterface public interface ThrowingConsumer { - /** - * Variation of {@link Consumer#accept(Object)} that allows throwing checked exceptions. - * - * @param t - * see {@link Consumer#accept(Object)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#consumer(ThrowingConsumer) - * @see Consumer#accept(Object) - */ - void accept(T t) throws Throwable; + /** + * Variation of {@link Consumer#accept(Object)} that allows throwing checked exceptions. + * + * @param t + * see {@link Consumer#accept(Object)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#consumer(ThrowingConsumer) + * @see Consumer#accept(Object) + */ + void accept(T t) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleBinaryOperator.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleBinaryOperator.java index 39879ae..b8dfe72 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleBinaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleBinaryOperator.java @@ -16,18 +16,18 @@ */ @FunctionalInterface public interface ThrowingDoubleBinaryOperator { - /** - * Variation of {@link DoubleBinaryOperator#applyAsDouble(double, double)} that allows throwing checked exceptions. - * - * @param left - * see {@link DoubleBinaryOperator#applyAsDouble(double, double)} - * @param right - * see {@link DoubleBinaryOperator#applyAsDouble(double, double)} - * @return see {@link DoubleBinaryOperator#applyAsDouble(double, double)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromDoubleBinaryOperator(ThrowingDoubleBinaryOperator) - * @see DoubleBinaryOperator#applyAsDouble(double, double) - */ - double applyAsDouble(double left, double right) throws Throwable; + /** + * Variation of {@link DoubleBinaryOperator#applyAsDouble(double, double)} that allows throwing checked exceptions. + * + * @param left + * see {@link DoubleBinaryOperator#applyAsDouble(double, double)} + * @param right + * see {@link DoubleBinaryOperator#applyAsDouble(double, double)} + * @return see {@link DoubleBinaryOperator#applyAsDouble(double, double)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromDoubleBinaryOperator(ThrowingDoubleBinaryOperator) + * @see DoubleBinaryOperator#applyAsDouble(double, double) + */ + double applyAsDouble(double left, double right) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleConsumer.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleConsumer.java index 99d3618..dd47601 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleConsumer.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleConsumer.java @@ -16,15 +16,15 @@ */ @FunctionalInterface public interface ThrowingDoubleConsumer { - /** - * Variation of {@link DoubleConsumer#accept(double)} that allows throwing checked exceptions. - * - * @param value - * see {@link DoubleConsumer#accept(double)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromDoubleConsumer(ThrowingDoubleConsumer) - * @see DoubleConsumer#accept(double) - */ - void accept(double value) throws Throwable; + /** + * Variation of {@link DoubleConsumer#accept(double)} that allows throwing checked exceptions. + * + * @param value + * see {@link DoubleConsumer#accept(double)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromDoubleConsumer(ThrowingDoubleConsumer) + * @see DoubleConsumer#accept(double) + */ + void accept(double value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleFunction.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleFunction.java index b7ad1d0..3094797 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleFunction.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleFunction.java @@ -18,16 +18,16 @@ */ @FunctionalInterface public interface ThrowingDoubleFunction { - /** - * Variation of {@link DoubleFunction#apply(double)} that allows throwing checked exceptions. - * - * @param value - * see {@link DoubleFunction#apply(double)} - * @return see {@link DoubleFunction#apply(double)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromDoubleFunction(ThrowingDoubleFunction) - * @see DoubleFunction#apply(double) - */ - R apply(double value) throws Throwable; + /** + * Variation of {@link DoubleFunction#apply(double)} that allows throwing checked exceptions. + * + * @param value + * see {@link DoubleFunction#apply(double)} + * @return see {@link DoubleFunction#apply(double)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromDoubleFunction(ThrowingDoubleFunction) + * @see DoubleFunction#apply(double) + */ + R apply(double value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoublePredicate.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoublePredicate.java index b6e7727..e73f652 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoublePredicate.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoublePredicate.java @@ -16,16 +16,16 @@ */ @FunctionalInterface public interface ThrowingDoublePredicate { - /** - * Variation of {@link DoublePredicate#test(double)} that allows throwing checked exceptions. - * - * @param value - * see {@link DoublePredicate#test(double)} - * @return see {@link DoublePredicate#test(double)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromDoublePredicate(ThrowingDoublePredicate) - * @see DoublePredicate#test(double) - */ - boolean test(double value) throws Throwable; + /** + * Variation of {@link DoublePredicate#test(double)} that allows throwing checked exceptions. + * + * @param value + * see {@link DoublePredicate#test(double)} + * @return see {@link DoublePredicate#test(double)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromDoublePredicate(ThrowingDoublePredicate) + * @see DoublePredicate#test(double) + */ + boolean test(double value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleSupplier.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleSupplier.java index 6dda9bf..3fe3967 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleSupplier.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleSupplier.java @@ -16,14 +16,14 @@ */ @FunctionalInterface public interface ThrowingDoubleSupplier { - /** - * Variation of {@link DoubleSupplier#getAsDouble()} that allows throwing checked exceptions. - * - * @return see {@link DoubleSupplier#getAsDouble()} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromDoubleSupplier(ThrowingDoubleSupplier) - * @see DoubleSupplier#getAsDouble() - */ - double getAsDouble() throws Throwable; + /** + * Variation of {@link DoubleSupplier#getAsDouble()} that allows throwing checked exceptions. + * + * @return see {@link DoubleSupplier#getAsDouble()} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromDoubleSupplier(ThrowingDoubleSupplier) + * @see DoubleSupplier#getAsDouble() + */ + double getAsDouble() throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleToIntFunction.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleToIntFunction.java index 84ff2c3..5a05708 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleToIntFunction.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleToIntFunction.java @@ -16,16 +16,16 @@ */ @FunctionalInterface public interface ThrowingDoubleToIntFunction { - /** - * Variation of {@link DoubleToIntFunction#applyAsInt(double)} that allows throwing checked exceptions. - * - * @param value - * see {@link DoubleToIntFunction#applyAsInt(double)} - * @return see {@link DoubleToIntFunction#applyAsInt(double)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromDoubleToIntFunction(ThrowingDoubleToIntFunction) - * @see DoubleToIntFunction#applyAsInt(double) - */ - int applyAsInt(double value) throws Throwable; + /** + * Variation of {@link DoubleToIntFunction#applyAsInt(double)} that allows throwing checked exceptions. + * + * @param value + * see {@link DoubleToIntFunction#applyAsInt(double)} + * @return see {@link DoubleToIntFunction#applyAsInt(double)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromDoubleToIntFunction(ThrowingDoubleToIntFunction) + * @see DoubleToIntFunction#applyAsInt(double) + */ + int applyAsInt(double value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleToLongFunction.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleToLongFunction.java index 8081366..7a757ae 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleToLongFunction.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleToLongFunction.java @@ -16,16 +16,16 @@ */ @FunctionalInterface public interface ThrowingDoubleToLongFunction { - /** - * Variation of {@link DoubleToLongFunction#applyAsLong(double)} that allows throwing checked exceptions. - * - * @param value - * see {@link DoubleToLongFunction#applyAsLong(double)} - * @return see {@link DoubleToLongFunction#applyAsLong(double)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromDoubleToLongFunction(ThrowingDoubleToLongFunction) - * @see DoubleToLongFunction#applyAsLong(double) - */ - long applyAsLong(double value) throws Throwable; + /** + * Variation of {@link DoubleToLongFunction#applyAsLong(double)} that allows throwing checked exceptions. + * + * @param value + * see {@link DoubleToLongFunction#applyAsLong(double)} + * @return see {@link DoubleToLongFunction#applyAsLong(double)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromDoubleToLongFunction(ThrowingDoubleToLongFunction) + * @see DoubleToLongFunction#applyAsLong(double) + */ + long applyAsLong(double value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleUnaryOperator.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleUnaryOperator.java index e3d10c2..0bef0c2 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleUnaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingDoubleUnaryOperator.java @@ -16,16 +16,16 @@ */ @FunctionalInterface public interface ThrowingDoubleUnaryOperator { - /** - * Variation of {@link DoubleUnaryOperator#applyAsDouble(double)} that allows throwing checked exceptions. - * - * @param operand - * see {@link DoubleUnaryOperator#applyAsDouble(double)} - * @return see {@link DoubleUnaryOperator#applyAsDouble(double)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromDoubleUnaryOperator(ThrowingDoubleUnaryOperator) - * @see DoubleUnaryOperator#applyAsDouble(double) - */ - double applyAsDouble(double operand) throws Throwable; + /** + * Variation of {@link DoubleUnaryOperator#applyAsDouble(double)} that allows throwing checked exceptions. + * + * @param operand + * see {@link DoubleUnaryOperator#applyAsDouble(double)} + * @return see {@link DoubleUnaryOperator#applyAsDouble(double)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromDoubleUnaryOperator(ThrowingDoubleUnaryOperator) + * @see DoubleUnaryOperator#applyAsDouble(double) + */ + double applyAsDouble(double operand) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingFunction.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingFunction.java index 2e47362..f6aa967 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingFunction.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingFunction.java @@ -20,16 +20,16 @@ */ @FunctionalInterface public interface ThrowingFunction { - /** - * Variation of {@link Function#apply(Object)} that allows throwing checked exceptions. - * - * @param t - * see {@link Function#apply(Object)} - * @return see {@link Function#apply(Object)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#function(ThrowingFunction) - * @see Function#apply(Object) - */ - R apply(T t) throws Throwable; + /** + * Variation of {@link Function#apply(Object)} that allows throwing checked exceptions. + * + * @param t + * see {@link Function#apply(Object)} + * @return see {@link Function#apply(Object)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#function(ThrowingFunction) + * @see Function#apply(Object) + */ + R apply(T t) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntBinaryOperator.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntBinaryOperator.java index 3bf52b8..adc25f3 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntBinaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntBinaryOperator.java @@ -16,18 +16,18 @@ */ @FunctionalInterface public interface ThrowingIntBinaryOperator { - /** - * Variation of {@link IntBinaryOperator#applyAsInt(int, int)} that allows throwing checked exceptions. - * - * @param left - * see {@link IntBinaryOperator#applyAsInt(int, int)} - * @param right - * see {@link IntBinaryOperator#applyAsInt(int, int)} - * @return see {@link IntBinaryOperator#applyAsInt(int, int)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromIntBinaryOperator(ThrowingIntBinaryOperator) - * @see IntBinaryOperator#applyAsInt(int, int) - */ - int applyAsInt(int left, int right) throws Throwable; + /** + * Variation of {@link IntBinaryOperator#applyAsInt(int, int)} that allows throwing checked exceptions. + * + * @param left + * see {@link IntBinaryOperator#applyAsInt(int, int)} + * @param right + * see {@link IntBinaryOperator#applyAsInt(int, int)} + * @return see {@link IntBinaryOperator#applyAsInt(int, int)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromIntBinaryOperator(ThrowingIntBinaryOperator) + * @see IntBinaryOperator#applyAsInt(int, int) + */ + int applyAsInt(int left, int right) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntConsumer.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntConsumer.java index 5723afd..0f7adab 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntConsumer.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntConsumer.java @@ -16,15 +16,15 @@ */ @FunctionalInterface public interface ThrowingIntConsumer { - /** - * Variation of {@link IntConsumer#accept(int)} that allows throwing checked exceptions. - * - * @param value - * see {@link IntConsumer#accept(int)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromIntConsumer(ThrowingIntConsumer) - * @see IntConsumer#accept(int) - */ - void accept(int value) throws Throwable; + /** + * Variation of {@link IntConsumer#accept(int)} that allows throwing checked exceptions. + * + * @param value + * see {@link IntConsumer#accept(int)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromIntConsumer(ThrowingIntConsumer) + * @see IntConsumer#accept(int) + */ + void accept(int value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntFunction.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntFunction.java index 9f2a474..6700adf 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntFunction.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntFunction.java @@ -18,16 +18,16 @@ */ @FunctionalInterface public interface ThrowingIntFunction { - /** - * Variation of {@link IntFunction#apply(int)} that allows throwing checked exceptions. - * - * @param value - * see {@link IntFunction#apply(int)} - * @return see {@link IntFunction#apply(int)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromIntFunction(ThrowingIntFunction) - * @see IntFunction#apply(int) - */ - R apply(int value) throws Throwable; + /** + * Variation of {@link IntFunction#apply(int)} that allows throwing checked exceptions. + * + * @param value + * see {@link IntFunction#apply(int)} + * @return see {@link IntFunction#apply(int)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromIntFunction(ThrowingIntFunction) + * @see IntFunction#apply(int) + */ + R apply(int value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntPredicate.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntPredicate.java index 0c5060e..ec3b82f 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntPredicate.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntPredicate.java @@ -16,16 +16,16 @@ */ @FunctionalInterface public interface ThrowingIntPredicate { - /** - * Variation of {@link IntPredicate#test(int)} that allows throwing checked exceptions. - * - * @param value - * see {@link IntPredicate#test(int)} - * @return see {@link IntPredicate#test(int)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromIntPredicate(ThrowingIntPredicate) - * @see IntPredicate#test(int) - */ - boolean test(int value) throws Throwable; + /** + * Variation of {@link IntPredicate#test(int)} that allows throwing checked exceptions. + * + * @param value + * see {@link IntPredicate#test(int)} + * @return see {@link IntPredicate#test(int)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromIntPredicate(ThrowingIntPredicate) + * @see IntPredicate#test(int) + */ + boolean test(int value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntSupplier.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntSupplier.java index 8056bb0..021f258 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntSupplier.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntSupplier.java @@ -16,14 +16,14 @@ */ @FunctionalInterface public interface ThrowingIntSupplier { - /** - * Variation of {@link IntSupplier#getAsInt()} that allows throwing checked exceptions. - * - * @return see {@link IntSupplier#getAsInt()} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromIntSupplier(ThrowingIntSupplier) - * @see IntSupplier#getAsInt() - */ - int getAsInt() throws Throwable; + /** + * Variation of {@link IntSupplier#getAsInt()} that allows throwing checked exceptions. + * + * @return see {@link IntSupplier#getAsInt()} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromIntSupplier(ThrowingIntSupplier) + * @see IntSupplier#getAsInt() + */ + int getAsInt() throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntToDoubleFunction.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntToDoubleFunction.java index 200c57a..8967d6a 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntToDoubleFunction.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntToDoubleFunction.java @@ -16,16 +16,16 @@ */ @FunctionalInterface public interface ThrowingIntToDoubleFunction { - /** - * Variation of {@link IntToDoubleFunction#applyAsDouble(int)} that allows throwing checked exceptions. - * - * @param value - * see {@link IntToDoubleFunction#applyAsDouble(int)} - * @return see {@link IntToDoubleFunction#applyAsDouble(int)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromIntToDoubleFunction(ThrowingIntToDoubleFunction) - * @see IntToDoubleFunction#applyAsDouble(int) - */ - double applyAsDouble(int value) throws Throwable; + /** + * Variation of {@link IntToDoubleFunction#applyAsDouble(int)} that allows throwing checked exceptions. + * + * @param value + * see {@link IntToDoubleFunction#applyAsDouble(int)} + * @return see {@link IntToDoubleFunction#applyAsDouble(int)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromIntToDoubleFunction(ThrowingIntToDoubleFunction) + * @see IntToDoubleFunction#applyAsDouble(int) + */ + double applyAsDouble(int value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntToLongFunction.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntToLongFunction.java index 660daac..6b95c24 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntToLongFunction.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntToLongFunction.java @@ -16,16 +16,16 @@ */ @FunctionalInterface public interface ThrowingIntToLongFunction { - /** - * Variation of {@link IntToLongFunction#applyAsLong(int)} that allows throwing checked exceptions. - * - * @param value - * see {@link IntToLongFunction#applyAsLong(int)} - * @return see {@link IntToLongFunction#applyAsLong(int)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromIntToLongFunction(ThrowingIntToLongFunction) - * @see IntToLongFunction#applyAsLong(int) - */ - long applyAsLong(int value) throws Throwable; + /** + * Variation of {@link IntToLongFunction#applyAsLong(int)} that allows throwing checked exceptions. + * + * @param value + * see {@link IntToLongFunction#applyAsLong(int)} + * @return see {@link IntToLongFunction#applyAsLong(int)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromIntToLongFunction(ThrowingIntToLongFunction) + * @see IntToLongFunction#applyAsLong(int) + */ + long applyAsLong(int value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntUnaryOperator.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntUnaryOperator.java index 0494321..91b972a 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntUnaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingIntUnaryOperator.java @@ -16,16 +16,16 @@ */ @FunctionalInterface public interface ThrowingIntUnaryOperator { - /** - * Variation of {@link IntUnaryOperator#applyAsInt(int)} that allows throwing checked exceptions. - * - * @param operand - * see {@link IntUnaryOperator#applyAsInt(int)} - * @return see {@link IntUnaryOperator#applyAsInt(int)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromIntUnaryOperator(ThrowingIntUnaryOperator) - * @see IntUnaryOperator#applyAsInt(int) - */ - int applyAsInt(int operand) throws Throwable; + /** + * Variation of {@link IntUnaryOperator#applyAsInt(int)} that allows throwing checked exceptions. + * + * @param operand + * see {@link IntUnaryOperator#applyAsInt(int)} + * @return see {@link IntUnaryOperator#applyAsInt(int)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromIntUnaryOperator(ThrowingIntUnaryOperator) + * @see IntUnaryOperator#applyAsInt(int) + */ + int applyAsInt(int operand) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongBinaryOperator.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongBinaryOperator.java index da76f50..387e7e0 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongBinaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongBinaryOperator.java @@ -16,18 +16,18 @@ */ @FunctionalInterface public interface ThrowingLongBinaryOperator { - /** - * Variation of {@link LongBinaryOperator#applyAsLong(long, long)} that allows throwing checked exceptions. - * - * @param left - * see {@link LongBinaryOperator#applyAsLong(long, long)} - * @param right - * see {@link LongBinaryOperator#applyAsLong(long, long)} - * @return see {@link LongBinaryOperator#applyAsLong(long, long)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromLongBinaryOperator(ThrowingLongBinaryOperator) - * @see LongBinaryOperator#applyAsLong(long, long) - */ - long applyAsLong(long left, long right) throws Throwable; + /** + * Variation of {@link LongBinaryOperator#applyAsLong(long, long)} that allows throwing checked exceptions. + * + * @param left + * see {@link LongBinaryOperator#applyAsLong(long, long)} + * @param right + * see {@link LongBinaryOperator#applyAsLong(long, long)} + * @return see {@link LongBinaryOperator#applyAsLong(long, long)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromLongBinaryOperator(ThrowingLongBinaryOperator) + * @see LongBinaryOperator#applyAsLong(long, long) + */ + long applyAsLong(long left, long right) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongConsumer.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongConsumer.java index d039ccb..a685d24 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongConsumer.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongConsumer.java @@ -16,15 +16,15 @@ */ @FunctionalInterface public interface ThrowingLongConsumer { - /** - * Variation of {@link LongConsumer#accept(long)} that allows throwing checked exceptions. - * - * @param value - * see {@link LongConsumer#accept(long)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromLongConsumer(ThrowingLongConsumer) - * @see LongConsumer#accept(long) - */ - void accept(long value) throws Throwable; + /** + * Variation of {@link LongConsumer#accept(long)} that allows throwing checked exceptions. + * + * @param value + * see {@link LongConsumer#accept(long)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromLongConsumer(ThrowingLongConsumer) + * @see LongConsumer#accept(long) + */ + void accept(long value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongFunction.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongFunction.java index 7eff8a0..81cb8d0 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongFunction.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongFunction.java @@ -18,16 +18,16 @@ */ @FunctionalInterface public interface ThrowingLongFunction { - /** - * Variation of {@link LongFunction#apply(long)} that allows throwing checked exceptions. - * - * @param value - * see {@link LongFunction#apply(long)} - * @return see {@link LongFunction#apply(long)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromLongFunction(ThrowingLongFunction) - * @see LongFunction#apply(long) - */ - R apply(long value) throws Throwable; + /** + * Variation of {@link LongFunction#apply(long)} that allows throwing checked exceptions. + * + * @param value + * see {@link LongFunction#apply(long)} + * @return see {@link LongFunction#apply(long)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromLongFunction(ThrowingLongFunction) + * @see LongFunction#apply(long) + */ + R apply(long value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongPredicate.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongPredicate.java index 22dd128..bfe1371 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongPredicate.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongPredicate.java @@ -16,16 +16,16 @@ */ @FunctionalInterface public interface ThrowingLongPredicate { - /** - * Variation of {@link LongPredicate#test(long)} that allows throwing checked exceptions. - * - * @param value - * see {@link LongPredicate#test(long)} - * @return see {@link LongPredicate#test(long)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromLongPredicate(ThrowingLongPredicate) - * @see LongPredicate#test(long) - */ - boolean test(long value) throws Throwable; + /** + * Variation of {@link LongPredicate#test(long)} that allows throwing checked exceptions. + * + * @param value + * see {@link LongPredicate#test(long)} + * @return see {@link LongPredicate#test(long)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromLongPredicate(ThrowingLongPredicate) + * @see LongPredicate#test(long) + */ + boolean test(long value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongSupplier.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongSupplier.java index 5292e0d..b684a71 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongSupplier.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongSupplier.java @@ -16,14 +16,14 @@ */ @FunctionalInterface public interface ThrowingLongSupplier { - /** - * Variation of {@link LongSupplier#getAsLong()} that allows throwing checked exceptions. - * - * @return see {@link LongSupplier#getAsLong()} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromLongSupplier(ThrowingLongSupplier) - * @see LongSupplier#getAsLong() - */ - long getAsLong() throws Throwable; + /** + * Variation of {@link LongSupplier#getAsLong()} that allows throwing checked exceptions. + * + * @return see {@link LongSupplier#getAsLong()} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromLongSupplier(ThrowingLongSupplier) + * @see LongSupplier#getAsLong() + */ + long getAsLong() throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongToDoubleFunction.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongToDoubleFunction.java index a3fa4d5..56626d5 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongToDoubleFunction.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongToDoubleFunction.java @@ -16,16 +16,16 @@ */ @FunctionalInterface public interface ThrowingLongToDoubleFunction { - /** - * Variation of {@link LongToDoubleFunction#applyAsDouble(long)} that allows throwing checked exceptions. - * - * @param value - * see {@link LongToDoubleFunction#applyAsDouble(long)} - * @return see {@link LongToDoubleFunction#applyAsDouble(long)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromLongToDoubleFunction(ThrowingLongToDoubleFunction) - * @see LongToDoubleFunction#applyAsDouble(long) - */ - double applyAsDouble(long value) throws Throwable; + /** + * Variation of {@link LongToDoubleFunction#applyAsDouble(long)} that allows throwing checked exceptions. + * + * @param value + * see {@link LongToDoubleFunction#applyAsDouble(long)} + * @return see {@link LongToDoubleFunction#applyAsDouble(long)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromLongToDoubleFunction(ThrowingLongToDoubleFunction) + * @see LongToDoubleFunction#applyAsDouble(long) + */ + double applyAsDouble(long value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongToIntFunction.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongToIntFunction.java index bfdcad7..5cf540e 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongToIntFunction.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongToIntFunction.java @@ -16,16 +16,16 @@ */ @FunctionalInterface public interface ThrowingLongToIntFunction { - /** - * Variation of {@link LongToIntFunction#applyAsInt(long)} that allows throwing checked exceptions. - * - * @param value - * see {@link LongToIntFunction#applyAsInt(long)} - * @return see {@link LongToIntFunction#applyAsInt(long)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromLongToIntFunction(ThrowingLongToIntFunction) - * @see LongToIntFunction#applyAsInt(long) - */ - int applyAsInt(long value) throws Throwable; + /** + * Variation of {@link LongToIntFunction#applyAsInt(long)} that allows throwing checked exceptions. + * + * @param value + * see {@link LongToIntFunction#applyAsInt(long)} + * @return see {@link LongToIntFunction#applyAsInt(long)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromLongToIntFunction(ThrowingLongToIntFunction) + * @see LongToIntFunction#applyAsInt(long) + */ + int applyAsInt(long value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongUnaryOperator.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongUnaryOperator.java index e1405d3..fb5808b 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongUnaryOperator.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingLongUnaryOperator.java @@ -16,16 +16,16 @@ */ @FunctionalInterface public interface ThrowingLongUnaryOperator { - /** - * Variation of {@link LongUnaryOperator#applyAsLong(long)} that allows throwing checked exceptions. - * - * @param operand - * see {@link LongUnaryOperator#applyAsLong(long)} - * @return see {@link LongUnaryOperator#applyAsLong(long)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromLongUnaryOperator(ThrowingLongUnaryOperator) - * @see LongUnaryOperator#applyAsLong(long) - */ - long applyAsLong(long operand) throws Throwable; + /** + * Variation of {@link LongUnaryOperator#applyAsLong(long)} that allows throwing checked exceptions. + * + * @param operand + * see {@link LongUnaryOperator#applyAsLong(long)} + * @return see {@link LongUnaryOperator#applyAsLong(long)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromLongUnaryOperator(ThrowingLongUnaryOperator) + * @see LongUnaryOperator#applyAsLong(long) + */ + long applyAsLong(long operand) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingObjDoubleConsumer.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingObjDoubleConsumer.java index fd0d072..74fcd06 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingObjDoubleConsumer.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingObjDoubleConsumer.java @@ -18,17 +18,17 @@ */ @FunctionalInterface public interface ThrowingObjDoubleConsumer { - /** - * Variation of {@link ObjDoubleConsumer#accept(Object, double)} that allows throwing checked exceptions. - * - * @param t - * see {@link ObjDoubleConsumer#accept(Object, double)} - * @param value - * see {@link ObjDoubleConsumer#accept(Object, double)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromObjDoubleConsumer(ThrowingObjDoubleConsumer) - * @see ObjDoubleConsumer#accept(Object, double) - */ - void accept(T t, double value) throws Throwable; + /** + * Variation of {@link ObjDoubleConsumer#accept(Object, double)} that allows throwing checked exceptions. + * + * @param t + * see {@link ObjDoubleConsumer#accept(Object, double)} + * @param value + * see {@link ObjDoubleConsumer#accept(Object, double)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromObjDoubleConsumer(ThrowingObjDoubleConsumer) + * @see ObjDoubleConsumer#accept(Object, double) + */ + void accept(T t, double value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingObjIntConsumer.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingObjIntConsumer.java index f0cd9a1..8dd0381 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingObjIntConsumer.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingObjIntConsumer.java @@ -18,17 +18,17 @@ */ @FunctionalInterface public interface ThrowingObjIntConsumer { - /** - * Variation of {@link ObjIntConsumer#accept(Object, int)} that allows throwing checked exceptions. - * - * @param t - * see {@link ObjIntConsumer#accept(Object, int)} - * @param value - * see {@link ObjIntConsumer#accept(Object, int)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromObjIntConsumer(ThrowingObjIntConsumer) - * @see ObjIntConsumer#accept(Object, int) - */ - void accept(T t, int value) throws Throwable; + /** + * Variation of {@link ObjIntConsumer#accept(Object, int)} that allows throwing checked exceptions. + * + * @param t + * see {@link ObjIntConsumer#accept(Object, int)} + * @param value + * see {@link ObjIntConsumer#accept(Object, int)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromObjIntConsumer(ThrowingObjIntConsumer) + * @see ObjIntConsumer#accept(Object, int) + */ + void accept(T t, int value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingObjLongConsumer.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingObjLongConsumer.java index 0e0a67f..30dcc67 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingObjLongConsumer.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingObjLongConsumer.java @@ -18,17 +18,17 @@ */ @FunctionalInterface public interface ThrowingObjLongConsumer { - /** - * Variation of {@link ObjLongConsumer#accept(Object, long)} that allows throwing checked exceptions. - * - * @param t - * see {@link ObjLongConsumer#accept(Object, long)} - * @param value - * see {@link ObjLongConsumer#accept(Object, long)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromObjLongConsumer(ThrowingObjLongConsumer) - * @see ObjLongConsumer#accept(Object, long) - */ - void accept(T t, long value) throws Throwable; + /** + * Variation of {@link ObjLongConsumer#accept(Object, long)} that allows throwing checked exceptions. + * + * @param t + * see {@link ObjLongConsumer#accept(Object, long)} + * @param value + * see {@link ObjLongConsumer#accept(Object, long)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromObjLongConsumer(ThrowingObjLongConsumer) + * @see ObjLongConsumer#accept(Object, long) + */ + void accept(T t, long value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingPredicate.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingPredicate.java index 8d86253..06ef07f 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingPredicate.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingPredicate.java @@ -18,16 +18,16 @@ */ @FunctionalInterface public interface ThrowingPredicate { - /** - * Variation of {@link Predicate#test(Object)} that allows throwing checked exceptions. - * - * @param t - * see {@link Predicate#test(Object)} - * @return see {@link Predicate#test(Object)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#predicate(ThrowingPredicate) - * @see Predicate#test(Object) - */ - boolean test(T t) throws Throwable; + /** + * Variation of {@link Predicate#test(Object)} that allows throwing checked exceptions. + * + * @param t + * see {@link Predicate#test(Object)} + * @return see {@link Predicate#test(Object)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#predicate(ThrowingPredicate) + * @see Predicate#test(Object) + */ + boolean test(T t) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingRunnable.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingRunnable.java index b33b6e9..93e350e 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingRunnable.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingRunnable.java @@ -15,13 +15,13 @@ */ @FunctionalInterface public interface ThrowingRunnable { - /** - * Variation of {@link Runnable#run()} that allows throwing checked exceptions. - * - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#runnable(ThrowingRunnable) - * @see Runnable#run() - */ - void run() throws Throwable; + /** + * Variation of {@link Runnable#run()} that allows throwing checked exceptions. + * + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#runnable(ThrowingRunnable) + * @see Runnable#run() + */ + void run() throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingSupplier.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingSupplier.java index 5fd81a5..e8680b0 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingSupplier.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingSupplier.java @@ -18,14 +18,14 @@ */ @FunctionalInterface public interface ThrowingSupplier { - /** - * Variation of {@link Supplier#get()} that allows throwing checked exceptions. - * - * @return see {@link Supplier#get()} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#supplier(ThrowingSupplier) - * @see Supplier#get() - */ - T get() throws Throwable; + /** + * Variation of {@link Supplier#get()} that allows throwing checked exceptions. + * + * @return see {@link Supplier#get()} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#supplier(ThrowingSupplier) + * @see Supplier#get() + */ + T get() throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingToDoubleBiFunction.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingToDoubleBiFunction.java index a76f245..cc9a946 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingToDoubleBiFunction.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingToDoubleBiFunction.java @@ -20,18 +20,18 @@ */ @FunctionalInterface public interface ThrowingToDoubleBiFunction { - /** - * Variation of {@link ToDoubleBiFunction#applyAsDouble(Object, Object)} that allows throwing checked exceptions. - * - * @param t - * see {@link ToDoubleBiFunction#applyAsDouble(Object, Object)} - * @param u - * see {@link ToDoubleBiFunction#applyAsDouble(Object, Object)} - * @return see {@link ToDoubleBiFunction#applyAsDouble(Object, Object)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromToDoubleBiFunction(ThrowingToDoubleBiFunction) - * @see ToDoubleBiFunction#applyAsDouble(Object, Object) - */ - double applyAsDouble(T t, U u) throws Throwable; + /** + * Variation of {@link ToDoubleBiFunction#applyAsDouble(Object, Object)} that allows throwing checked exceptions. + * + * @param t + * see {@link ToDoubleBiFunction#applyAsDouble(Object, Object)} + * @param u + * see {@link ToDoubleBiFunction#applyAsDouble(Object, Object)} + * @return see {@link ToDoubleBiFunction#applyAsDouble(Object, Object)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromToDoubleBiFunction(ThrowingToDoubleBiFunction) + * @see ToDoubleBiFunction#applyAsDouble(Object, Object) + */ + double applyAsDouble(T t, U u) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingToDoubleFunction.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingToDoubleFunction.java index b9aa1a4..729fa54 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingToDoubleFunction.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingToDoubleFunction.java @@ -18,16 +18,16 @@ */ @FunctionalInterface public interface ThrowingToDoubleFunction { - /** - * Variation of {@link ToDoubleFunction#applyAsDouble(Object)} that allows throwing checked exceptions. - * - * @param value - * see {@link ToDoubleFunction#applyAsDouble(Object)} - * @return see {@link ToDoubleFunction#applyAsDouble(Object)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromToDoubleFunction(ThrowingToDoubleFunction) - * @see ToDoubleFunction#applyAsDouble(Object) - */ - double applyAsDouble(T value) throws Throwable; + /** + * Variation of {@link ToDoubleFunction#applyAsDouble(Object)} that allows throwing checked exceptions. + * + * @param value + * see {@link ToDoubleFunction#applyAsDouble(Object)} + * @return see {@link ToDoubleFunction#applyAsDouble(Object)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromToDoubleFunction(ThrowingToDoubleFunction) + * @see ToDoubleFunction#applyAsDouble(Object) + */ + double applyAsDouble(T value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingToIntBiFunction.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingToIntBiFunction.java index bfbfe19..f188183 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingToIntBiFunction.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingToIntBiFunction.java @@ -20,18 +20,18 @@ */ @FunctionalInterface public interface ThrowingToIntBiFunction { - /** - * Variation of {@link ToIntBiFunction#applyAsInt(Object, Object)} that allows throwing checked exceptions. - * - * @param t - * see {@link ToIntBiFunction#applyAsInt(Object, Object)} - * @param u - * see {@link ToIntBiFunction#applyAsInt(Object, Object)} - * @return see {@link ToIntBiFunction#applyAsInt(Object, Object)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromToIntBiFunction(ThrowingToIntBiFunction) - * @see ToIntBiFunction#applyAsInt(Object, Object) - */ - int applyAsInt(T t, U u) throws Throwable; + /** + * Variation of {@link ToIntBiFunction#applyAsInt(Object, Object)} that allows throwing checked exceptions. + * + * @param t + * see {@link ToIntBiFunction#applyAsInt(Object, Object)} + * @param u + * see {@link ToIntBiFunction#applyAsInt(Object, Object)} + * @return see {@link ToIntBiFunction#applyAsInt(Object, Object)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromToIntBiFunction(ThrowingToIntBiFunction) + * @see ToIntBiFunction#applyAsInt(Object, Object) + */ + int applyAsInt(T t, U u) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingToIntFunction.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingToIntFunction.java index 26aba9d..681d8d4 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingToIntFunction.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingToIntFunction.java @@ -18,16 +18,16 @@ */ @FunctionalInterface public interface ThrowingToIntFunction { - /** - * Variation of {@link ToIntFunction#applyAsInt(Object)} that allows throwing checked exceptions. - * - * @param value - * see {@link ToIntFunction#applyAsInt(Object)} - * @return see {@link ToIntFunction#applyAsInt(Object)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromToIntFunction(ThrowingToIntFunction) - * @see ToIntFunction#applyAsInt(Object) - */ - int applyAsInt(T value) throws Throwable; + /** + * Variation of {@link ToIntFunction#applyAsInt(Object)} that allows throwing checked exceptions. + * + * @param value + * see {@link ToIntFunction#applyAsInt(Object)} + * @return see {@link ToIntFunction#applyAsInt(Object)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromToIntFunction(ThrowingToIntFunction) + * @see ToIntFunction#applyAsInt(Object) + */ + int applyAsInt(T value) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingToLongBiFunction.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingToLongBiFunction.java index de174b4..9665bb4 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingToLongBiFunction.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingToLongBiFunction.java @@ -20,18 +20,18 @@ */ @FunctionalInterface public interface ThrowingToLongBiFunction { - /** - * Variation of {@link ToLongBiFunction#applyAsLong(Object, Object)} that allows throwing checked exceptions. - * - * @param t - * see {@link ToLongBiFunction#applyAsLong(Object, Object)} - * @param u - * see {@link ToLongBiFunction#applyAsLong(Object, Object)} - * @return see {@link ToLongBiFunction#applyAsLong(Object, Object)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromToLongBiFunction(ThrowingToLongBiFunction) - * @see ToLongBiFunction#applyAsLong(Object, Object) - */ - long applyAsLong(T t, U u) throws Throwable; + /** + * Variation of {@link ToLongBiFunction#applyAsLong(Object, Object)} that allows throwing checked exceptions. + * + * @param t + * see {@link ToLongBiFunction#applyAsLong(Object, Object)} + * @param u + * see {@link ToLongBiFunction#applyAsLong(Object, Object)} + * @return see {@link ToLongBiFunction#applyAsLong(Object, Object)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromToLongBiFunction(ThrowingToLongBiFunction) + * @see ToLongBiFunction#applyAsLong(Object, Object) + */ + long applyAsLong(T t, U u) throws Throwable; } diff --git a/src/main/java/com/machinezoo/noexception/throwing/ThrowingToLongFunction.java b/src/main/java/com/machinezoo/noexception/throwing/ThrowingToLongFunction.java index f44884d..e846cad 100644 --- a/src/main/java/com/machinezoo/noexception/throwing/ThrowingToLongFunction.java +++ b/src/main/java/com/machinezoo/noexception/throwing/ThrowingToLongFunction.java @@ -18,16 +18,16 @@ */ @FunctionalInterface public interface ThrowingToLongFunction { - /** - * Variation of {@link ToLongFunction#applyAsLong(Object)} that allows throwing checked exceptions. - * - * @param value - * see {@link ToLongFunction#applyAsLong(Object)} - * @return see {@link ToLongFunction#applyAsLong(Object)} - * @throws Throwable - * if unable to complete - * @see CheckedExceptionHandler#fromToLongFunction(ThrowingToLongFunction) - * @see ToLongFunction#applyAsLong(Object) - */ - long applyAsLong(T value) throws Throwable; + /** + * Variation of {@link ToLongFunction#applyAsLong(Object)} that allows throwing checked exceptions. + * + * @param value + * see {@link ToLongFunction#applyAsLong(Object)} + * @return see {@link ToLongFunction#applyAsLong(Object)} + * @throws Throwable + * if unable to complete + * @see CheckedExceptionHandler#fromToLongFunction(ThrowingToLongFunction) + * @see ToLongFunction#applyAsLong(Object) + */ + long applyAsLong(T value) throws Throwable; } diff --git a/src/test/java/com/machinezoo/noexception/CheckedExceptionHandlerTest.java b/src/test/java/com/machinezoo/noexception/CheckedExceptionHandlerTest.java index d871b7f..1fcdf80 100644 --- a/src/test/java/com/machinezoo/noexception/CheckedExceptionHandlerTest.java +++ b/src/test/java/com/machinezoo/noexception/CheckedExceptionHandlerTest.java @@ -12,1501 +12,1501 @@ import com.machinezoo.noexception.throwing.*; public class CheckedExceptionHandlerTest { - @Test - public void runnable_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingRunnable lambda = mock(ThrowingRunnable.class); - collector.runnable(lambda).run(); - verify(lambda, only()).run(); - assertTrue(collector.empty()); - } - @Test - public void runnable_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.runnable(() -> { - throw new DataFormatException(); - }).run()); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void runnable_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().runnable(() -> { - throw new NumberFormatException(); - }).run()); - } - @Test - public void runnable_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().runnable(() -> { - throw new ServiceConfigurationError(""); - }).run()); - } - @Test - public void supplier_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingSupplier lambda = mock(ThrowingSupplier.class); - when(lambda.get()).thenReturn("value"); - assertEquals("value", collector.supplier(lambda).get()); - verify(lambda, only()).get(); - assertTrue(collector.empty()); - } - @Test - public void supplier_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.supplier(() -> { - throw new DataFormatException(); - }).get()); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void supplier_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().supplier(() -> { - throw new NumberFormatException(); - }).get()); - } - @Test - public void supplier_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().supplier(() -> { - throw new ServiceConfigurationError(""); - }).get()); - } - @Test - public void fromIntSupplier_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingIntSupplier lambda = mock(ThrowingIntSupplier.class); - when(lambda.getAsInt()).thenReturn(2); - assertEquals(2, collector.fromIntSupplier(lambda).getAsInt()); - verify(lambda, only()).getAsInt(); - assertTrue(collector.empty()); - } - @Test - public void fromIntSupplier_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromIntSupplier(() -> { - throw new DataFormatException(); - }).getAsInt()); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromIntSupplier_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromIntSupplier(() -> { - throw new NumberFormatException(); - }).getAsInt()); - } - @Test - public void fromIntSupplier_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromIntSupplier(() -> { - throw new ServiceConfigurationError(""); - }).getAsInt()); - } - @Test - public void fromLongSupplier_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingLongSupplier lambda = mock(ThrowingLongSupplier.class); - when(lambda.getAsLong()).thenReturn(2L); - assertEquals(2L, collector.fromLongSupplier(lambda).getAsLong()); - verify(lambda, only()).getAsLong(); - assertTrue(collector.empty()); - } - @Test - public void fromLongSupplier_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromLongSupplier(() -> { - throw new DataFormatException(); - }).getAsLong()); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromLongSupplier_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromLongSupplier(() -> { - throw new NumberFormatException(); - }).getAsLong()); - } - @Test - public void fromLongSupplier_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromLongSupplier(() -> { - throw new ServiceConfigurationError(""); - }).getAsLong()); - } - @Test - public void fromDoubleSupplier_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingDoubleSupplier lambda = mock(ThrowingDoubleSupplier.class); - when(lambda.getAsDouble()).thenReturn(2.0); - assertEquals(2.0, collector.fromDoubleSupplier(lambda).getAsDouble(), 0.1); - verify(lambda, only()).getAsDouble(); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleSupplier_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromDoubleSupplier(() -> { - throw new DataFormatException(); - }).getAsDouble()); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromDoubleSupplier_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromDoubleSupplier(() -> { - throw new NumberFormatException(); - }).getAsDouble()); - } - @Test - public void fromDoubleSupplier_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromDoubleSupplier(() -> { - throw new ServiceConfigurationError(""); - }).getAsDouble()); - } - @Test - public void fromBooleanSupplier_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingBooleanSupplier lambda = mock(ThrowingBooleanSupplier.class); - when(lambda.getAsBoolean()).thenReturn(true); - assertEquals(true, collector.fromBooleanSupplier(lambda).getAsBoolean()); - verify(lambda, only()).getAsBoolean(); - assertTrue(collector.empty()); - } - @Test - public void fromBooleanSupplier_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromBooleanSupplier(() -> { - throw new DataFormatException(); - }).getAsBoolean()); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromBooleanSupplier_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromBooleanSupplier(() -> { - throw new NumberFormatException(); - }).getAsBoolean()); - } - @Test - public void fromBooleanSupplier_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromBooleanSupplier(() -> { - throw new ServiceConfigurationError(""); - }).getAsBoolean()); - } - @Test - public void consumer_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingConsumer lambda = mock(ThrowingConsumer.class); - collector.consumer(lambda).accept("input"); - verify(lambda, only()).accept("input"); - assertTrue(collector.empty()); - } - @Test - public void consumer_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.consumer(t -> { - throw new DataFormatException(); - }).accept("input")); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void consumer_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().consumer(t -> { - throw new NumberFormatException(); - }).accept("input")); - } - @Test - public void consumer_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().consumer(t -> { - throw new ServiceConfigurationError(""); - }).accept("input")); - } - @Test - public void fromIntConsumer_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingIntConsumer lambda = mock(ThrowingIntConsumer.class); - collector.fromIntConsumer(lambda).accept(1); - verify(lambda, only()).accept(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntConsumer_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromIntConsumer(v -> { - throw new DataFormatException(); - }).accept(1)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromIntConsumer_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromIntConsumer(v -> { - throw new NumberFormatException(); - }).accept(1)); - } - @Test - public void fromIntConsumer_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromIntConsumer(v -> { - throw new ServiceConfigurationError(""); - }).accept(1)); - } - @Test - public void fromLongConsumer_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingLongConsumer lambda = mock(ThrowingLongConsumer.class); - collector.fromLongConsumer(lambda).accept(1L); - verify(lambda, only()).accept(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongConsumer_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromLongConsumer(v -> { - throw new DataFormatException(); - }).accept(1L)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromLongConsumer_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromLongConsumer(v -> { - throw new NumberFormatException(); - }).accept(1L)); - } - @Test - public void fromLongConsumer_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromLongConsumer(v -> { - throw new ServiceConfigurationError(""); - }).accept(1L)); - } - @Test - public void fromDoubleConsumer_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingDoubleConsumer lambda = mock(ThrowingDoubleConsumer.class); - collector.fromDoubleConsumer(lambda).accept(1.0); - verify(lambda, only()).accept(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleConsumer_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromDoubleConsumer(v -> { - throw new DataFormatException(); - }).accept(1.0)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromDoubleConsumer_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromDoubleConsumer(v -> { - throw new NumberFormatException(); - }).accept(1.0)); - } - @Test - public void fromDoubleConsumer_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromDoubleConsumer(v -> { - throw new ServiceConfigurationError(""); - }).accept(1.0)); - } - @Test - public void fromBiConsumer_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingBiConsumer lambda = mock(ThrowingBiConsumer.class); - collector.fromBiConsumer(lambda).accept("input1", "input2"); - verify(lambda, only()).accept("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromBiConsumer_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromBiConsumer((t, u) -> { - throw new DataFormatException(); - }).accept("input1", "input2")); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromBiConsumer_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromBiConsumer((t, u) -> { - throw new NumberFormatException(); - }).accept("input1", "input2")); - } - @Test - public void fromBiConsumer_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromBiConsumer((t, u) -> { - throw new ServiceConfigurationError(""); - }).accept("input1", "input2")); - } - @Test - public void fromObjIntConsumer_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingObjIntConsumer lambda = mock(ThrowingObjIntConsumer.class); - collector.fromObjIntConsumer(lambda).accept("input", 1); - verify(lambda, only()).accept("input", 1); - assertTrue(collector.empty()); - } - @Test - public void fromObjIntConsumer_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromObjIntConsumer((t, v) -> { - throw new DataFormatException(); - }).accept("input", 1)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromObjIntConsumer_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromObjIntConsumer((t, v) -> { - throw new NumberFormatException(); - }).accept("input", 1)); - } - @Test - public void fromObjIntConsumer_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromObjIntConsumer((t, v) -> { - throw new ServiceConfigurationError(""); - }).accept("input", 1)); - } - @Test - public void fromObjLongConsumer_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingObjLongConsumer lambda = mock(ThrowingObjLongConsumer.class); - collector.fromObjLongConsumer(lambda).accept("input", 1L); - verify(lambda, only()).accept("input", 1L); - assertTrue(collector.empty()); - } - @Test - public void fromObjLongConsumer_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromObjLongConsumer((t, v) -> { - throw new DataFormatException(); - }).accept("input", 1L)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromObjLongConsumer_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromObjLongConsumer((t, v) -> { - throw new NumberFormatException(); - }).accept("input", 1L)); - } - @Test - public void fromObjLongConsumer_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromObjLongConsumer((t, v) -> { - throw new ServiceConfigurationError(""); - }).accept("input", 1L)); - } - @Test - public void fromObjDoubleConsumer_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingObjDoubleConsumer lambda = mock(ThrowingObjDoubleConsumer.class); - collector.fromObjDoubleConsumer(lambda).accept("input", 1.0); - verify(lambda, only()).accept("input", 1.0); - assertTrue(collector.empty()); - } - @Test - public void fromObjDoubleConsumer_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromObjDoubleConsumer((t, v) -> { - throw new DataFormatException(); - }).accept("input", 1.0)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromObjDoubleConsumer_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromObjDoubleConsumer((t, v) -> { - throw new NumberFormatException(); - }).accept("input", 1.0)); - } - @Test - public void fromObjDoubleConsumer_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromObjDoubleConsumer((t, v) -> { - throw new ServiceConfigurationError(""); - }).accept("input", 1.0)); - } - @Test - public void predicate_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingPredicate lambda = mock(ThrowingPredicate.class); - when(lambda.test("input")).thenReturn(true); - assertEquals(true, collector.predicate(lambda).test("input")); - verify(lambda, only()).test("input"); - assertTrue(collector.empty()); - } - @Test - public void predicate_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.predicate(t -> { - throw new DataFormatException(); - }).test("input")); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void predicate_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().predicate(t -> { - throw new NumberFormatException(); - }).test("input")); - } - @Test - public void predicate_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().predicate(t -> { - throw new ServiceConfigurationError(""); - }).test("input")); - } - @Test - public void fromIntPredicate_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingIntPredicate lambda = mock(ThrowingIntPredicate.class); - when(lambda.test(1)).thenReturn(true); - assertEquals(true, collector.fromIntPredicate(lambda).test(1)); - verify(lambda, only()).test(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntPredicate_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromIntPredicate(v -> { - throw new DataFormatException(); - }).test(1)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromIntPredicate_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromIntPredicate(v -> { - throw new NumberFormatException(); - }).test(1)); - } - @Test - public void fromIntPredicate_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromIntPredicate(v -> { - throw new ServiceConfigurationError(""); - }).test(1)); - } - @Test - public void fromLongPredicate_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingLongPredicate lambda = mock(ThrowingLongPredicate.class); - when(lambda.test(1L)).thenReturn(true); - assertEquals(true, collector.fromLongPredicate(lambda).test(1L)); - verify(lambda, only()).test(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongPredicate_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromLongPredicate(v -> { - throw new DataFormatException(); - }).test(1L)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromLongPredicate_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromLongPredicate(v -> { - throw new NumberFormatException(); - }).test(1L)); - } - @Test - public void fromLongPredicate_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromLongPredicate(v -> { - throw new ServiceConfigurationError(""); - }).test(1L)); - } - @Test - public void fromDoublePredicate_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingDoublePredicate lambda = mock(ThrowingDoublePredicate.class); - when(lambda.test(1.0)).thenReturn(true); - assertEquals(true, collector.fromDoublePredicate(lambda).test(1.0)); - verify(lambda, only()).test(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoublePredicate_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromDoublePredicate(v -> { - throw new DataFormatException(); - }).test(1.0)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromDoublePredicate_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromDoublePredicate(v -> { - throw new NumberFormatException(); - }).test(1.0)); - } - @Test - public void fromDoublePredicate_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromDoublePredicate(v -> { - throw new ServiceConfigurationError(""); - }).test(1.0)); - } - @Test - public void fromBiPredicate_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingBiPredicate lambda = mock(ThrowingBiPredicate.class); - when(lambda.test("input1", "input2")).thenReturn(true); - assertEquals(true, collector.fromBiPredicate(lambda).test("input1", "input2")); - verify(lambda, only()).test("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromBiPredicate_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromBiPredicate((t, u) -> { - throw new DataFormatException(); - }).test("input1", "input2")); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromBiPredicate_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromBiPredicate((t, u) -> { - throw new NumberFormatException(); - }).test("input1", "input2")); - } - @Test - public void fromBiPredicate_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromBiPredicate((t, u) -> { - throw new ServiceConfigurationError(""); - }).test("input1", "input2")); - } - @Test - public void function_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingFunction lambda = mock(ThrowingFunction.class); - when(lambda.apply("input")).thenReturn("value"); - assertEquals("value", collector.function(lambda).apply("input")); - verify(lambda, only()).apply("input"); - assertTrue(collector.empty()); - } - @Test - public void function_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.function(t -> { - throw new DataFormatException(); - }).apply("input")); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void function_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().function(t -> { - throw new NumberFormatException(); - }).apply("input")); - } - @Test - public void function_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().function(t -> { - throw new ServiceConfigurationError(""); - }).apply("input")); - } - @Test - public void fromToIntFunction_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingToIntFunction lambda = mock(ThrowingToIntFunction.class); - when(lambda.applyAsInt("input")).thenReturn(2); - assertEquals(2, collector.fromToIntFunction(lambda).applyAsInt("input")); - verify(lambda, only()).applyAsInt("input"); - assertTrue(collector.empty()); - } - @Test - public void fromToIntFunction_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromToIntFunction(v -> { - throw new DataFormatException(); - }).applyAsInt("input")); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromToIntFunction_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromToIntFunction(v -> { - throw new NumberFormatException(); - }).applyAsInt("input")); - } - @Test - public void fromToIntFunction_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromToIntFunction(v -> { - throw new ServiceConfigurationError(""); - }).applyAsInt("input")); - } - @Test - public void fromIntFunction_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingIntFunction lambda = mock(ThrowingIntFunction.class); - when(lambda.apply(1)).thenReturn("value"); - assertEquals("value", collector.fromIntFunction(lambda).apply(1)); - verify(lambda, only()).apply(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntFunction_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromIntFunction(v -> { - throw new DataFormatException(); - }).apply(1)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromIntFunction_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromIntFunction(v -> { - throw new NumberFormatException(); - }).apply(1)); - } - @Test - public void fromIntFunction_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromIntFunction(v -> { - throw new ServiceConfigurationError(""); - }).apply(1)); - } - @Test - public void fromIntToLongFunction_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingIntToLongFunction lambda = mock(ThrowingIntToLongFunction.class); - when(lambda.applyAsLong(1)).thenReturn(2L); - assertEquals(2L, collector.fromIntToLongFunction(lambda).applyAsLong(1)); - verify(lambda, only()).applyAsLong(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntToLongFunction_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromIntToLongFunction(v -> { - throw new DataFormatException(); - }).applyAsLong(1)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromIntToLongFunction_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromIntToLongFunction(v -> { - throw new NumberFormatException(); - }).applyAsLong(1)); - } - @Test - public void fromIntToLongFunction_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromIntToLongFunction(v -> { - throw new ServiceConfigurationError(""); - }).applyAsLong(1)); - } - @Test - public void fromIntToDoubleFunction_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingIntToDoubleFunction lambda = mock(ThrowingIntToDoubleFunction.class); - when(lambda.applyAsDouble(1)).thenReturn(2.0); - assertEquals(2.0, collector.fromIntToDoubleFunction(lambda).applyAsDouble(1), 0.1); - verify(lambda, only()).applyAsDouble(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntToDoubleFunction_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromIntToDoubleFunction(v -> { - throw new DataFormatException(); - }).applyAsDouble(1)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromIntToDoubleFunction_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromIntToDoubleFunction(v -> { - throw new NumberFormatException(); - }).applyAsDouble(1)); - } - @Test - public void fromIntToDoubleFunction_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromIntToDoubleFunction(v -> { - throw new ServiceConfigurationError(""); - }).applyAsDouble(1)); - } - @Test - public void fromToLongFunction_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingToLongFunction lambda = mock(ThrowingToLongFunction.class); - when(lambda.applyAsLong("input")).thenReturn(2L); - assertEquals(2L, collector.fromToLongFunction(lambda).applyAsLong("input")); - verify(lambda, only()).applyAsLong("input"); - assertTrue(collector.empty()); - } - @Test - public void fromToLongFunction_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromToLongFunction(v -> { - throw new DataFormatException(); - }).applyAsLong("input")); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromToLongFunction_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromToLongFunction(v -> { - throw new NumberFormatException(); - }).applyAsLong("input")); - } - @Test - public void fromToLongFunction_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromToLongFunction(v -> { - throw new ServiceConfigurationError(""); - }).applyAsLong("input")); - } - @Test - public void fromLongFunction_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingLongFunction lambda = mock(ThrowingLongFunction.class); - when(lambda.apply(1L)).thenReturn("value"); - assertEquals("value", collector.fromLongFunction(lambda).apply(1L)); - verify(lambda, only()).apply(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongFunction_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromLongFunction(v -> { - throw new DataFormatException(); - }).apply(1L)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromLongFunction_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromLongFunction(v -> { - throw new NumberFormatException(); - }).apply(1L)); - } - @Test - public void fromLongFunction_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromLongFunction(v -> { - throw new ServiceConfigurationError(""); - }).apply(1L)); - } - @Test - public void fromLongToIntFunction_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingLongToIntFunction lambda = mock(ThrowingLongToIntFunction.class); - when(lambda.applyAsInt(1L)).thenReturn(2); - assertEquals(2, collector.fromLongToIntFunction(lambda).applyAsInt(1L)); - verify(lambda, only()).applyAsInt(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongToIntFunction_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromLongToIntFunction(v -> { - throw new DataFormatException(); - }).applyAsInt(1L)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromLongToIntFunction_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromLongToIntFunction(v -> { - throw new NumberFormatException(); - }).applyAsInt(1L)); - } - @Test - public void fromLongToIntFunction_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromLongToIntFunction(v -> { - throw new ServiceConfigurationError(""); - }).applyAsInt(1L)); - } - @Test - public void fromLongToDoubleFunction_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingLongToDoubleFunction lambda = mock(ThrowingLongToDoubleFunction.class); - when(lambda.applyAsDouble(1L)).thenReturn(2.0); - assertEquals(2.0, collector.fromLongToDoubleFunction(lambda).applyAsDouble(1L), 0.1); - verify(lambda, only()).applyAsDouble(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongToDoubleFunction_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromLongToDoubleFunction(v -> { - throw new DataFormatException(); - }).applyAsDouble(1L)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromLongToDoubleFunction_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromLongToDoubleFunction(v -> { - throw new NumberFormatException(); - }).applyAsDouble(1L)); - } - @Test - public void fromLongToDoubleFunction_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromLongToDoubleFunction(v -> { - throw new ServiceConfigurationError(""); - }).applyAsDouble(1L)); - } - @Test - public void fromToDoubleFunction_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingToDoubleFunction lambda = mock(ThrowingToDoubleFunction.class); - when(lambda.applyAsDouble("input")).thenReturn(2.0); - assertEquals(2.0, collector.fromToDoubleFunction(lambda).applyAsDouble("input"), 0.1); - verify(lambda, only()).applyAsDouble("input"); - assertTrue(collector.empty()); - } - @Test - public void fromToDoubleFunction_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromToDoubleFunction(v -> { - throw new DataFormatException(); - }).applyAsDouble("input")); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromToDoubleFunction_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromToDoubleFunction(v -> { - throw new NumberFormatException(); - }).applyAsDouble("input")); - } - @Test - public void fromToDoubleFunction_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromToDoubleFunction(v -> { - throw new ServiceConfigurationError(""); - }).applyAsDouble("input")); - } - @Test - public void fromDoubleFunction_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingDoubleFunction lambda = mock(ThrowingDoubleFunction.class); - when(lambda.apply(1.0)).thenReturn("value"); - assertEquals("value", collector.fromDoubleFunction(lambda).apply(1.0)); - verify(lambda, only()).apply(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleFunction_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromDoubleFunction(v -> { - throw new DataFormatException(); - }).apply(1.0)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromDoubleFunction_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromDoubleFunction(v -> { - throw new NumberFormatException(); - }).apply(1.0)); - } - @Test - public void fromDoubleFunction_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromDoubleFunction(v -> { - throw new ServiceConfigurationError(""); - }).apply(1.0)); - } - @Test - public void fromDoubleToIntFunction_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingDoubleToIntFunction lambda = mock(ThrowingDoubleToIntFunction.class); - when(lambda.applyAsInt(1.0)).thenReturn(2); - assertEquals(2, collector.fromDoubleToIntFunction(lambda).applyAsInt(1.0)); - verify(lambda, only()).applyAsInt(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleToIntFunction_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromDoubleToIntFunction(v -> { - throw new DataFormatException(); - }).applyAsInt(1.0)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromDoubleToIntFunction_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromDoubleToIntFunction(v -> { - throw new NumberFormatException(); - }).applyAsInt(1.0)); - } - @Test - public void fromDoubleToIntFunction_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromDoubleToIntFunction(v -> { - throw new ServiceConfigurationError(""); - }).applyAsInt(1.0)); - } - @Test - public void fromDoubleToLongFunction_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingDoubleToLongFunction lambda = mock(ThrowingDoubleToLongFunction.class); - when(lambda.applyAsLong(1.0)).thenReturn(2L); - assertEquals(2L, collector.fromDoubleToLongFunction(lambda).applyAsLong(1.0)); - verify(lambda, only()).applyAsLong(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleToLongFunction_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromDoubleToLongFunction(v -> { - throw new DataFormatException(); - }).applyAsLong(1.0)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromDoubleToLongFunction_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromDoubleToLongFunction(v -> { - throw new NumberFormatException(); - }).applyAsLong(1.0)); - } - @Test - public void fromDoubleToLongFunction_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromDoubleToLongFunction(v -> { - throw new ServiceConfigurationError(""); - }).applyAsLong(1.0)); - } - @Test - public void fromUnaryOperator_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingUnaryOperator lambda = mock(ThrowingUnaryOperator.class); - when(lambda.apply("input")).thenReturn("value"); - assertEquals("value", collector.fromUnaryOperator(lambda).apply("input")); - verify(lambda, only()).apply("input"); - assertTrue(collector.empty()); - } - @Test - public void fromUnaryOperator_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromUnaryOperator(o -> { - throw new DataFormatException(); - }).apply("input")); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromUnaryOperator_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromUnaryOperator(o -> { - throw new NumberFormatException(); - }).apply("input")); - } - @Test - public void fromUnaryOperator_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromUnaryOperator(o -> { - throw new ServiceConfigurationError(""); - }).apply("input")); - } - @Test - public void fromIntUnaryOperator_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingIntUnaryOperator lambda = mock(ThrowingIntUnaryOperator.class); - when(lambda.applyAsInt(1)).thenReturn(2); - assertEquals(2, collector.fromIntUnaryOperator(lambda).applyAsInt(1)); - verify(lambda, only()).applyAsInt(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntUnaryOperator_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromIntUnaryOperator(o -> { - throw new DataFormatException(); - }).applyAsInt(1)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromIntUnaryOperator_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromIntUnaryOperator(o -> { - throw new NumberFormatException(); - }).applyAsInt(1)); - } - @Test - public void fromIntUnaryOperator_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromIntUnaryOperator(o -> { - throw new ServiceConfigurationError(""); - }).applyAsInt(1)); - } - @Test - public void fromLongUnaryOperator_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingLongUnaryOperator lambda = mock(ThrowingLongUnaryOperator.class); - when(lambda.applyAsLong(1L)).thenReturn(2L); - assertEquals(2L, collector.fromLongUnaryOperator(lambda).applyAsLong(1L)); - verify(lambda, only()).applyAsLong(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongUnaryOperator_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromLongUnaryOperator(o -> { - throw new DataFormatException(); - }).applyAsLong(1L)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromLongUnaryOperator_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromLongUnaryOperator(o -> { - throw new NumberFormatException(); - }).applyAsLong(1L)); - } - @Test - public void fromLongUnaryOperator_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromLongUnaryOperator(o -> { - throw new ServiceConfigurationError(""); - }).applyAsLong(1L)); - } - @Test - public void fromDoubleUnaryOperator_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingDoubleUnaryOperator lambda = mock(ThrowingDoubleUnaryOperator.class); - when(lambda.applyAsDouble(1.0)).thenReturn(2.0); - assertEquals(2.0, collector.fromDoubleUnaryOperator(lambda).applyAsDouble(1.0), 0.1); - verify(lambda, only()).applyAsDouble(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleUnaryOperator_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromDoubleUnaryOperator(o -> { - throw new DataFormatException(); - }).applyAsDouble(1.0)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromDoubleUnaryOperator_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromDoubleUnaryOperator(o -> { - throw new NumberFormatException(); - }).applyAsDouble(1.0)); - } - @Test - public void fromDoubleUnaryOperator_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromDoubleUnaryOperator(o -> { - throw new ServiceConfigurationError(""); - }).applyAsDouble(1.0)); - } - @Test - public void fromBiFunction_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingBiFunction lambda = mock(ThrowingBiFunction.class); - when(lambda.apply("input1", "input2")).thenReturn("value"); - assertEquals("value", collector.fromBiFunction(lambda).apply("input1", "input2")); - verify(lambda, only()).apply("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromBiFunction_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromBiFunction((t, u) -> { - throw new DataFormatException(); - }).apply("input1", "input2")); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromBiFunction_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromBiFunction((t, u) -> { - throw new NumberFormatException(); - }).apply("input1", "input2")); - } - @Test - public void fromBiFunction_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromBiFunction((t, u) -> { - throw new ServiceConfigurationError(""); - }).apply("input1", "input2")); - } - @Test - public void fromToIntBiFunction_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingToIntBiFunction lambda = mock(ThrowingToIntBiFunction.class); - when(lambda.applyAsInt("input1", "input2")).thenReturn(2); - assertEquals(2, collector.fromToIntBiFunction(lambda).applyAsInt("input1", "input2")); - verify(lambda, only()).applyAsInt("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromToIntBiFunction_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromToIntBiFunction((t, u) -> { - throw new DataFormatException(); - }).applyAsInt("input1", "input2")); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromToIntBiFunction_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromToIntBiFunction((t, u) -> { - throw new NumberFormatException(); - }).applyAsInt("input1", "input2")); - } - @Test - public void fromToIntBiFunction_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromToIntBiFunction((t, u) -> { - throw new ServiceConfigurationError(""); - }).applyAsInt("input1", "input2")); - } - @Test - public void fromToLongBiFunction_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingToLongBiFunction lambda = mock(ThrowingToLongBiFunction.class); - when(lambda.applyAsLong("input1", "input2")).thenReturn(2L); - assertEquals(2L, collector.fromToLongBiFunction(lambda).applyAsLong("input1", "input2")); - verify(lambda, only()).applyAsLong("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromToLongBiFunction_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromToLongBiFunction((t, u) -> { - throw new DataFormatException(); - }).applyAsLong("input1", "input2")); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromToLongBiFunction_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromToLongBiFunction((t, u) -> { - throw new NumberFormatException(); - }).applyAsLong("input1", "input2")); - } - @Test - public void fromToLongBiFunction_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromToLongBiFunction((t, u) -> { - throw new ServiceConfigurationError(""); - }).applyAsLong("input1", "input2")); - } - @Test - public void fromToDoubleBiFunction_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingToDoubleBiFunction lambda = mock(ThrowingToDoubleBiFunction.class); - when(lambda.applyAsDouble("input1", "input2")).thenReturn(2.0); - assertEquals(2.0, collector.fromToDoubleBiFunction(lambda).applyAsDouble("input1", "input2"), 0.1); - verify(lambda, only()).applyAsDouble("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromToDoubleBiFunction_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromToDoubleBiFunction((t, u) -> { - throw new DataFormatException(); - }).applyAsDouble("input1", "input2")); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromToDoubleBiFunction_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromToDoubleBiFunction((t, u) -> { - throw new NumberFormatException(); - }).applyAsDouble("input1", "input2")); - } - @Test - public void fromToDoubleBiFunction_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromToDoubleBiFunction((t, u) -> { - throw new ServiceConfigurationError(""); - }).applyAsDouble("input1", "input2")); - } - @Test - public void fromBinaryOperator_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingBinaryOperator lambda = mock(ThrowingBinaryOperator.class); - when(lambda.apply("input1", "input2")).thenReturn("value"); - assertEquals("value", collector.fromBinaryOperator(lambda).apply("input1", "input2")); - verify(lambda, only()).apply("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromBinaryOperator_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromBinaryOperator((l, r) -> { - throw new DataFormatException(); - }).apply("input1", "input2")); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromBinaryOperator_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).apply("input1", "input2")); - } - @Test - public void fromBinaryOperator_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromBinaryOperator((l, r) -> { - throw new ServiceConfigurationError(""); - }).apply("input1", "input2")); - } - @Test - public void fromIntBinaryOperator_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingIntBinaryOperator lambda = mock(ThrowingIntBinaryOperator.class); - when(lambda.applyAsInt(11, 12)).thenReturn(2); - assertEquals(2, collector.fromIntBinaryOperator(lambda).applyAsInt(11, 12)); - verify(lambda, only()).applyAsInt(11, 12); - assertTrue(collector.empty()); - } - @Test - public void fromIntBinaryOperator_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromIntBinaryOperator((l, r) -> { - throw new DataFormatException(); - }).applyAsInt(11, 12)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromIntBinaryOperator_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromIntBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).applyAsInt(11, 12)); - } - @Test - public void fromIntBinaryOperator_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromIntBinaryOperator((l, r) -> { - throw new ServiceConfigurationError(""); - }).applyAsInt(11, 12)); - } - @Test - public void fromLongBinaryOperator_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingLongBinaryOperator lambda = mock(ThrowingLongBinaryOperator.class); - when(lambda.applyAsLong(11L, 12L)).thenReturn(2L); - assertEquals(2L, collector.fromLongBinaryOperator(lambda).applyAsLong(11L, 12L)); - verify(lambda, only()).applyAsLong(11L, 12L); - assertTrue(collector.empty()); - } - @Test - public void fromLongBinaryOperator_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromLongBinaryOperator((l, r) -> { - throw new DataFormatException(); - }).applyAsLong(11L, 12L)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromLongBinaryOperator_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromLongBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).applyAsLong(11L, 12L)); - } - @Test - public void fromLongBinaryOperator_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromLongBinaryOperator((l, r) -> { - throw new ServiceConfigurationError(""); - }).applyAsLong(11L, 12L)); - } - @Test - public void fromDoubleBinaryOperator_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingDoubleBinaryOperator lambda = mock(ThrowingDoubleBinaryOperator.class); - when(lambda.applyAsDouble(1.1, 1.2)).thenReturn(2.0); - assertEquals(2.0, collector.fromDoubleBinaryOperator(lambda).applyAsDouble(1.1, 1.2), 0.1); - verify(lambda, only()).applyAsDouble(1.1, 1.2); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleBinaryOperator_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.fromDoubleBinaryOperator((l, r) -> { - throw new DataFormatException(); - }).applyAsDouble(1.1, 1.2)); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void fromDoubleBinaryOperator_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromDoubleBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).applyAsDouble(1.1, 1.2)); - } - @Test - public void fromDoubleBinaryOperator_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromDoubleBinaryOperator((l, r) -> { - throw new ServiceConfigurationError(""); - }).applyAsDouble(1.1, 1.2)); - } - @Test - public void comparator_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingComparator lambda = mock(ThrowingComparator.class); - when(lambda.compare("input1", "input2")).thenReturn(2); - assertEquals(2, collector.comparator(lambda).compare("input1", "input2")); - verify(lambda, only()).compare("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void comparator_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.comparator((l, r) -> { - throw new DataFormatException(); - }).compare("input1", "input2")); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void comparator_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().comparator((l, r) -> { - throw new NumberFormatException(); - }).compare("input1", "input2")); - } - @Test - public void comparator_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().comparator((l, r) -> { - throw new ServiceConfigurationError(""); - }).compare("input1", "input2")); - } - @Test - public void closeable_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - AutoCloseable lambda = mock(AutoCloseable.class); - collector.closeable(lambda).close(); - verify(lambda, only()).close(); - assertTrue(collector.empty()); - } - @Test - public void closeable_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.closeable(() -> { - throw new DataFormatException(); - }).close()); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void closeable_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().closeable(() -> { - throw new NumberFormatException(); - }).close()); - } - @Test - public void closeable_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().closeable(() -> { - throw new ServiceConfigurationError(""); - }).close()); - } - @Test - public void run_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingRunnable lambda = mock(ThrowingRunnable.class); - collector.run(lambda); - verify(lambda, only()).run(); - assertTrue(collector.empty()); - } - @Test - public void run_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.run(() -> { - throw new DataFormatException(); - })); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void run_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().run(() -> { - throw new NumberFormatException(); - })); - } - @Test - public void run_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().run(() -> { - throw new ServiceConfigurationError(""); - })); - } - @Test - public void get_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - @SuppressWarnings("unchecked") ThrowingSupplier lambda = mock(ThrowingSupplier.class); - when(lambda.get()).thenReturn("value"); - assertEquals("value", collector.get(lambda)); - verify(lambda, only()).get(); - assertTrue(collector.empty()); - } - @Test - public void get_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.get(() -> { - throw new DataFormatException(); - })); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void get_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().get(() -> { - throw new NumberFormatException(); - })); - } - @Test - public void get_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().get(() -> { - throw new ServiceConfigurationError(""); - })); - } - @Test - public void getAsInt_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingIntSupplier lambda = mock(ThrowingIntSupplier.class); - when(lambda.getAsInt()).thenReturn(2); - assertEquals(2, collector.getAsInt(lambda)); - verify(lambda, only()).getAsInt(); - assertTrue(collector.empty()); - } - @Test - public void getAsInt_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.getAsInt(() -> { - throw new DataFormatException(); - })); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void getAsInt_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().getAsInt(() -> { - throw new NumberFormatException(); - })); - } - @Test - public void getAsInt_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().getAsInt(() -> { - throw new ServiceConfigurationError(""); - })); - } - @Test - public void getAsLong_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingLongSupplier lambda = mock(ThrowingLongSupplier.class); - when(lambda.getAsLong()).thenReturn(2L); - assertEquals(2L, collector.getAsLong(lambda)); - verify(lambda, only()).getAsLong(); - assertTrue(collector.empty()); - } - @Test - public void getAsLong_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.getAsLong(() -> { - throw new DataFormatException(); - })); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void getAsLong_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().getAsLong(() -> { - throw new NumberFormatException(); - })); - } - @Test - public void getAsLong_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().getAsLong(() -> { - throw new ServiceConfigurationError(""); - })); - } - @Test - public void getAsDouble_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingDoubleSupplier lambda = mock(ThrowingDoubleSupplier.class); - when(lambda.getAsDouble()).thenReturn(2.0); - assertEquals(2.0, collector.getAsDouble(lambda), 0.1); - verify(lambda, only()).getAsDouble(); - assertTrue(collector.empty()); - } - @Test - public void getAsDouble_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.getAsDouble(() -> { - throw new DataFormatException(); - })); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void getAsDouble_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().getAsDouble(() -> { - throw new NumberFormatException(); - })); - } - @Test - public void getAsDouble_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().getAsDouble(() -> { - throw new ServiceConfigurationError(""); - })); - } - @Test - public void getAsBoolean_complete() throws Throwable { - var collector = new CheckedExceptionCollector(); - ThrowingBooleanSupplier lambda = mock(ThrowingBooleanSupplier.class); - when(lambda.getAsBoolean()).thenReturn(true); - assertEquals(true, collector.getAsBoolean(lambda)); - verify(lambda, only()).getAsBoolean(); - assertTrue(collector.empty()); - } - @Test - public void getAsBoolean_exception() { - var collector = new CheckedExceptionCollector(); - assertThrows(CollectedException.class, () -> collector.getAsBoolean(() -> { - throw new DataFormatException(); - })); - assertThat(collector.single(), instanceOf(DataFormatException.class)); - } - @Test - public void getAsBoolean_runtime() { - assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().getAsBoolean(() -> { - throw new NumberFormatException(); - })); - } - @Test - public void getAsBoolean_error() { - assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().getAsBoolean(() -> { - throw new ServiceConfigurationError(""); - })); - } + @Test + public void runnable_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingRunnable lambda = mock(ThrowingRunnable.class); + collector.runnable(lambda).run(); + verify(lambda, only()).run(); + assertTrue(collector.empty()); + } + @Test + public void runnable_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.runnable(() -> { + throw new DataFormatException(); + }).run()); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void runnable_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().runnable(() -> { + throw new NumberFormatException(); + }).run()); + } + @Test + public void runnable_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().runnable(() -> { + throw new ServiceConfigurationError(""); + }).run()); + } + @Test + public void supplier_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingSupplier lambda = mock(ThrowingSupplier.class); + when(lambda.get()).thenReturn("value"); + assertEquals("value", collector.supplier(lambda).get()); + verify(lambda, only()).get(); + assertTrue(collector.empty()); + } + @Test + public void supplier_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.supplier(() -> { + throw new DataFormatException(); + }).get()); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void supplier_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().supplier(() -> { + throw new NumberFormatException(); + }).get()); + } + @Test + public void supplier_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().supplier(() -> { + throw new ServiceConfigurationError(""); + }).get()); + } + @Test + public void fromIntSupplier_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingIntSupplier lambda = mock(ThrowingIntSupplier.class); + when(lambda.getAsInt()).thenReturn(2); + assertEquals(2, collector.fromIntSupplier(lambda).getAsInt()); + verify(lambda, only()).getAsInt(); + assertTrue(collector.empty()); + } + @Test + public void fromIntSupplier_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromIntSupplier(() -> { + throw new DataFormatException(); + }).getAsInt()); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromIntSupplier_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromIntSupplier(() -> { + throw new NumberFormatException(); + }).getAsInt()); + } + @Test + public void fromIntSupplier_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromIntSupplier(() -> { + throw new ServiceConfigurationError(""); + }).getAsInt()); + } + @Test + public void fromLongSupplier_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingLongSupplier lambda = mock(ThrowingLongSupplier.class); + when(lambda.getAsLong()).thenReturn(2L); + assertEquals(2L, collector.fromLongSupplier(lambda).getAsLong()); + verify(lambda, only()).getAsLong(); + assertTrue(collector.empty()); + } + @Test + public void fromLongSupplier_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromLongSupplier(() -> { + throw new DataFormatException(); + }).getAsLong()); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromLongSupplier_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromLongSupplier(() -> { + throw new NumberFormatException(); + }).getAsLong()); + } + @Test + public void fromLongSupplier_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromLongSupplier(() -> { + throw new ServiceConfigurationError(""); + }).getAsLong()); + } + @Test + public void fromDoubleSupplier_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingDoubleSupplier lambda = mock(ThrowingDoubleSupplier.class); + when(lambda.getAsDouble()).thenReturn(2.0); + assertEquals(2.0, collector.fromDoubleSupplier(lambda).getAsDouble(), 0.1); + verify(lambda, only()).getAsDouble(); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleSupplier_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromDoubleSupplier(() -> { + throw new DataFormatException(); + }).getAsDouble()); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromDoubleSupplier_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromDoubleSupplier(() -> { + throw new NumberFormatException(); + }).getAsDouble()); + } + @Test + public void fromDoubleSupplier_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromDoubleSupplier(() -> { + throw new ServiceConfigurationError(""); + }).getAsDouble()); + } + @Test + public void fromBooleanSupplier_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingBooleanSupplier lambda = mock(ThrowingBooleanSupplier.class); + when(lambda.getAsBoolean()).thenReturn(true); + assertEquals(true, collector.fromBooleanSupplier(lambda).getAsBoolean()); + verify(lambda, only()).getAsBoolean(); + assertTrue(collector.empty()); + } + @Test + public void fromBooleanSupplier_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromBooleanSupplier(() -> { + throw new DataFormatException(); + }).getAsBoolean()); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromBooleanSupplier_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromBooleanSupplier(() -> { + throw new NumberFormatException(); + }).getAsBoolean()); + } + @Test + public void fromBooleanSupplier_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromBooleanSupplier(() -> { + throw new ServiceConfigurationError(""); + }).getAsBoolean()); + } + @Test + public void consumer_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingConsumer lambda = mock(ThrowingConsumer.class); + collector.consumer(lambda).accept("input"); + verify(lambda, only()).accept("input"); + assertTrue(collector.empty()); + } + @Test + public void consumer_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.consumer(t -> { + throw new DataFormatException(); + }).accept("input")); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void consumer_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().consumer(t -> { + throw new NumberFormatException(); + }).accept("input")); + } + @Test + public void consumer_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().consumer(t -> { + throw new ServiceConfigurationError(""); + }).accept("input")); + } + @Test + public void fromIntConsumer_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingIntConsumer lambda = mock(ThrowingIntConsumer.class); + collector.fromIntConsumer(lambda).accept(1); + verify(lambda, only()).accept(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntConsumer_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromIntConsumer(v -> { + throw new DataFormatException(); + }).accept(1)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromIntConsumer_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromIntConsumer(v -> { + throw new NumberFormatException(); + }).accept(1)); + } + @Test + public void fromIntConsumer_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromIntConsumer(v -> { + throw new ServiceConfigurationError(""); + }).accept(1)); + } + @Test + public void fromLongConsumer_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingLongConsumer lambda = mock(ThrowingLongConsumer.class); + collector.fromLongConsumer(lambda).accept(1L); + verify(lambda, only()).accept(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongConsumer_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromLongConsumer(v -> { + throw new DataFormatException(); + }).accept(1L)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromLongConsumer_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromLongConsumer(v -> { + throw new NumberFormatException(); + }).accept(1L)); + } + @Test + public void fromLongConsumer_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromLongConsumer(v -> { + throw new ServiceConfigurationError(""); + }).accept(1L)); + } + @Test + public void fromDoubleConsumer_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingDoubleConsumer lambda = mock(ThrowingDoubleConsumer.class); + collector.fromDoubleConsumer(lambda).accept(1.0); + verify(lambda, only()).accept(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleConsumer_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromDoubleConsumer(v -> { + throw new DataFormatException(); + }).accept(1.0)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromDoubleConsumer_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromDoubleConsumer(v -> { + throw new NumberFormatException(); + }).accept(1.0)); + } + @Test + public void fromDoubleConsumer_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromDoubleConsumer(v -> { + throw new ServiceConfigurationError(""); + }).accept(1.0)); + } + @Test + public void fromBiConsumer_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingBiConsumer lambda = mock(ThrowingBiConsumer.class); + collector.fromBiConsumer(lambda).accept("input1", "input2"); + verify(lambda, only()).accept("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromBiConsumer_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromBiConsumer((t, u) -> { + throw new DataFormatException(); + }).accept("input1", "input2")); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromBiConsumer_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromBiConsumer((t, u) -> { + throw new NumberFormatException(); + }).accept("input1", "input2")); + } + @Test + public void fromBiConsumer_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromBiConsumer((t, u) -> { + throw new ServiceConfigurationError(""); + }).accept("input1", "input2")); + } + @Test + public void fromObjIntConsumer_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingObjIntConsumer lambda = mock(ThrowingObjIntConsumer.class); + collector.fromObjIntConsumer(lambda).accept("input", 1); + verify(lambda, only()).accept("input", 1); + assertTrue(collector.empty()); + } + @Test + public void fromObjIntConsumer_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromObjIntConsumer((t, v) -> { + throw new DataFormatException(); + }).accept("input", 1)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromObjIntConsumer_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromObjIntConsumer((t, v) -> { + throw new NumberFormatException(); + }).accept("input", 1)); + } + @Test + public void fromObjIntConsumer_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromObjIntConsumer((t, v) -> { + throw new ServiceConfigurationError(""); + }).accept("input", 1)); + } + @Test + public void fromObjLongConsumer_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingObjLongConsumer lambda = mock(ThrowingObjLongConsumer.class); + collector.fromObjLongConsumer(lambda).accept("input", 1L); + verify(lambda, only()).accept("input", 1L); + assertTrue(collector.empty()); + } + @Test + public void fromObjLongConsumer_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromObjLongConsumer((t, v) -> { + throw new DataFormatException(); + }).accept("input", 1L)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromObjLongConsumer_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromObjLongConsumer((t, v) -> { + throw new NumberFormatException(); + }).accept("input", 1L)); + } + @Test + public void fromObjLongConsumer_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromObjLongConsumer((t, v) -> { + throw new ServiceConfigurationError(""); + }).accept("input", 1L)); + } + @Test + public void fromObjDoubleConsumer_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingObjDoubleConsumer lambda = mock(ThrowingObjDoubleConsumer.class); + collector.fromObjDoubleConsumer(lambda).accept("input", 1.0); + verify(lambda, only()).accept("input", 1.0); + assertTrue(collector.empty()); + } + @Test + public void fromObjDoubleConsumer_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromObjDoubleConsumer((t, v) -> { + throw new DataFormatException(); + }).accept("input", 1.0)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromObjDoubleConsumer_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromObjDoubleConsumer((t, v) -> { + throw new NumberFormatException(); + }).accept("input", 1.0)); + } + @Test + public void fromObjDoubleConsumer_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromObjDoubleConsumer((t, v) -> { + throw new ServiceConfigurationError(""); + }).accept("input", 1.0)); + } + @Test + public void predicate_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingPredicate lambda = mock(ThrowingPredicate.class); + when(lambda.test("input")).thenReturn(true); + assertEquals(true, collector.predicate(lambda).test("input")); + verify(lambda, only()).test("input"); + assertTrue(collector.empty()); + } + @Test + public void predicate_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.predicate(t -> { + throw new DataFormatException(); + }).test("input")); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void predicate_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().predicate(t -> { + throw new NumberFormatException(); + }).test("input")); + } + @Test + public void predicate_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().predicate(t -> { + throw new ServiceConfigurationError(""); + }).test("input")); + } + @Test + public void fromIntPredicate_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingIntPredicate lambda = mock(ThrowingIntPredicate.class); + when(lambda.test(1)).thenReturn(true); + assertEquals(true, collector.fromIntPredicate(lambda).test(1)); + verify(lambda, only()).test(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntPredicate_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromIntPredicate(v -> { + throw new DataFormatException(); + }).test(1)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromIntPredicate_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromIntPredicate(v -> { + throw new NumberFormatException(); + }).test(1)); + } + @Test + public void fromIntPredicate_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromIntPredicate(v -> { + throw new ServiceConfigurationError(""); + }).test(1)); + } + @Test + public void fromLongPredicate_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingLongPredicate lambda = mock(ThrowingLongPredicate.class); + when(lambda.test(1L)).thenReturn(true); + assertEquals(true, collector.fromLongPredicate(lambda).test(1L)); + verify(lambda, only()).test(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongPredicate_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromLongPredicate(v -> { + throw new DataFormatException(); + }).test(1L)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromLongPredicate_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromLongPredicate(v -> { + throw new NumberFormatException(); + }).test(1L)); + } + @Test + public void fromLongPredicate_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromLongPredicate(v -> { + throw new ServiceConfigurationError(""); + }).test(1L)); + } + @Test + public void fromDoublePredicate_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingDoublePredicate lambda = mock(ThrowingDoublePredicate.class); + when(lambda.test(1.0)).thenReturn(true); + assertEquals(true, collector.fromDoublePredicate(lambda).test(1.0)); + verify(lambda, only()).test(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoublePredicate_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromDoublePredicate(v -> { + throw new DataFormatException(); + }).test(1.0)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromDoublePredicate_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromDoublePredicate(v -> { + throw new NumberFormatException(); + }).test(1.0)); + } + @Test + public void fromDoublePredicate_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromDoublePredicate(v -> { + throw new ServiceConfigurationError(""); + }).test(1.0)); + } + @Test + public void fromBiPredicate_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingBiPredicate lambda = mock(ThrowingBiPredicate.class); + when(lambda.test("input1", "input2")).thenReturn(true); + assertEquals(true, collector.fromBiPredicate(lambda).test("input1", "input2")); + verify(lambda, only()).test("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromBiPredicate_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromBiPredicate((t, u) -> { + throw new DataFormatException(); + }).test("input1", "input2")); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromBiPredicate_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromBiPredicate((t, u) -> { + throw new NumberFormatException(); + }).test("input1", "input2")); + } + @Test + public void fromBiPredicate_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromBiPredicate((t, u) -> { + throw new ServiceConfigurationError(""); + }).test("input1", "input2")); + } + @Test + public void function_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingFunction lambda = mock(ThrowingFunction.class); + when(lambda.apply("input")).thenReturn("value"); + assertEquals("value", collector.function(lambda).apply("input")); + verify(lambda, only()).apply("input"); + assertTrue(collector.empty()); + } + @Test + public void function_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.function(t -> { + throw new DataFormatException(); + }).apply("input")); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void function_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().function(t -> { + throw new NumberFormatException(); + }).apply("input")); + } + @Test + public void function_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().function(t -> { + throw new ServiceConfigurationError(""); + }).apply("input")); + } + @Test + public void fromToIntFunction_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingToIntFunction lambda = mock(ThrowingToIntFunction.class); + when(lambda.applyAsInt("input")).thenReturn(2); + assertEquals(2, collector.fromToIntFunction(lambda).applyAsInt("input")); + verify(lambda, only()).applyAsInt("input"); + assertTrue(collector.empty()); + } + @Test + public void fromToIntFunction_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromToIntFunction(v -> { + throw new DataFormatException(); + }).applyAsInt("input")); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromToIntFunction_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromToIntFunction(v -> { + throw new NumberFormatException(); + }).applyAsInt("input")); + } + @Test + public void fromToIntFunction_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromToIntFunction(v -> { + throw new ServiceConfigurationError(""); + }).applyAsInt("input")); + } + @Test + public void fromIntFunction_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingIntFunction lambda = mock(ThrowingIntFunction.class); + when(lambda.apply(1)).thenReturn("value"); + assertEquals("value", collector.fromIntFunction(lambda).apply(1)); + verify(lambda, only()).apply(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntFunction_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromIntFunction(v -> { + throw new DataFormatException(); + }).apply(1)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromIntFunction_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromIntFunction(v -> { + throw new NumberFormatException(); + }).apply(1)); + } + @Test + public void fromIntFunction_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromIntFunction(v -> { + throw new ServiceConfigurationError(""); + }).apply(1)); + } + @Test + public void fromIntToLongFunction_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingIntToLongFunction lambda = mock(ThrowingIntToLongFunction.class); + when(lambda.applyAsLong(1)).thenReturn(2L); + assertEquals(2L, collector.fromIntToLongFunction(lambda).applyAsLong(1)); + verify(lambda, only()).applyAsLong(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntToLongFunction_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromIntToLongFunction(v -> { + throw new DataFormatException(); + }).applyAsLong(1)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromIntToLongFunction_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromIntToLongFunction(v -> { + throw new NumberFormatException(); + }).applyAsLong(1)); + } + @Test + public void fromIntToLongFunction_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromIntToLongFunction(v -> { + throw new ServiceConfigurationError(""); + }).applyAsLong(1)); + } + @Test + public void fromIntToDoubleFunction_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingIntToDoubleFunction lambda = mock(ThrowingIntToDoubleFunction.class); + when(lambda.applyAsDouble(1)).thenReturn(2.0); + assertEquals(2.0, collector.fromIntToDoubleFunction(lambda).applyAsDouble(1), 0.1); + verify(lambda, only()).applyAsDouble(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntToDoubleFunction_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromIntToDoubleFunction(v -> { + throw new DataFormatException(); + }).applyAsDouble(1)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromIntToDoubleFunction_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromIntToDoubleFunction(v -> { + throw new NumberFormatException(); + }).applyAsDouble(1)); + } + @Test + public void fromIntToDoubleFunction_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromIntToDoubleFunction(v -> { + throw new ServiceConfigurationError(""); + }).applyAsDouble(1)); + } + @Test + public void fromToLongFunction_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingToLongFunction lambda = mock(ThrowingToLongFunction.class); + when(lambda.applyAsLong("input")).thenReturn(2L); + assertEquals(2L, collector.fromToLongFunction(lambda).applyAsLong("input")); + verify(lambda, only()).applyAsLong("input"); + assertTrue(collector.empty()); + } + @Test + public void fromToLongFunction_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromToLongFunction(v -> { + throw new DataFormatException(); + }).applyAsLong("input")); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromToLongFunction_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromToLongFunction(v -> { + throw new NumberFormatException(); + }).applyAsLong("input")); + } + @Test + public void fromToLongFunction_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromToLongFunction(v -> { + throw new ServiceConfigurationError(""); + }).applyAsLong("input")); + } + @Test + public void fromLongFunction_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingLongFunction lambda = mock(ThrowingLongFunction.class); + when(lambda.apply(1L)).thenReturn("value"); + assertEquals("value", collector.fromLongFunction(lambda).apply(1L)); + verify(lambda, only()).apply(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongFunction_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromLongFunction(v -> { + throw new DataFormatException(); + }).apply(1L)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromLongFunction_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromLongFunction(v -> { + throw new NumberFormatException(); + }).apply(1L)); + } + @Test + public void fromLongFunction_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromLongFunction(v -> { + throw new ServiceConfigurationError(""); + }).apply(1L)); + } + @Test + public void fromLongToIntFunction_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingLongToIntFunction lambda = mock(ThrowingLongToIntFunction.class); + when(lambda.applyAsInt(1L)).thenReturn(2); + assertEquals(2, collector.fromLongToIntFunction(lambda).applyAsInt(1L)); + verify(lambda, only()).applyAsInt(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongToIntFunction_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromLongToIntFunction(v -> { + throw new DataFormatException(); + }).applyAsInt(1L)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromLongToIntFunction_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromLongToIntFunction(v -> { + throw new NumberFormatException(); + }).applyAsInt(1L)); + } + @Test + public void fromLongToIntFunction_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromLongToIntFunction(v -> { + throw new ServiceConfigurationError(""); + }).applyAsInt(1L)); + } + @Test + public void fromLongToDoubleFunction_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingLongToDoubleFunction lambda = mock(ThrowingLongToDoubleFunction.class); + when(lambda.applyAsDouble(1L)).thenReturn(2.0); + assertEquals(2.0, collector.fromLongToDoubleFunction(lambda).applyAsDouble(1L), 0.1); + verify(lambda, only()).applyAsDouble(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongToDoubleFunction_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromLongToDoubleFunction(v -> { + throw new DataFormatException(); + }).applyAsDouble(1L)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromLongToDoubleFunction_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromLongToDoubleFunction(v -> { + throw new NumberFormatException(); + }).applyAsDouble(1L)); + } + @Test + public void fromLongToDoubleFunction_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromLongToDoubleFunction(v -> { + throw new ServiceConfigurationError(""); + }).applyAsDouble(1L)); + } + @Test + public void fromToDoubleFunction_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingToDoubleFunction lambda = mock(ThrowingToDoubleFunction.class); + when(lambda.applyAsDouble("input")).thenReturn(2.0); + assertEquals(2.0, collector.fromToDoubleFunction(lambda).applyAsDouble("input"), 0.1); + verify(lambda, only()).applyAsDouble("input"); + assertTrue(collector.empty()); + } + @Test + public void fromToDoubleFunction_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromToDoubleFunction(v -> { + throw new DataFormatException(); + }).applyAsDouble("input")); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromToDoubleFunction_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromToDoubleFunction(v -> { + throw new NumberFormatException(); + }).applyAsDouble("input")); + } + @Test + public void fromToDoubleFunction_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromToDoubleFunction(v -> { + throw new ServiceConfigurationError(""); + }).applyAsDouble("input")); + } + @Test + public void fromDoubleFunction_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingDoubleFunction lambda = mock(ThrowingDoubleFunction.class); + when(lambda.apply(1.0)).thenReturn("value"); + assertEquals("value", collector.fromDoubleFunction(lambda).apply(1.0)); + verify(lambda, only()).apply(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleFunction_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromDoubleFunction(v -> { + throw new DataFormatException(); + }).apply(1.0)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromDoubleFunction_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromDoubleFunction(v -> { + throw new NumberFormatException(); + }).apply(1.0)); + } + @Test + public void fromDoubleFunction_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromDoubleFunction(v -> { + throw new ServiceConfigurationError(""); + }).apply(1.0)); + } + @Test + public void fromDoubleToIntFunction_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingDoubleToIntFunction lambda = mock(ThrowingDoubleToIntFunction.class); + when(lambda.applyAsInt(1.0)).thenReturn(2); + assertEquals(2, collector.fromDoubleToIntFunction(lambda).applyAsInt(1.0)); + verify(lambda, only()).applyAsInt(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleToIntFunction_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromDoubleToIntFunction(v -> { + throw new DataFormatException(); + }).applyAsInt(1.0)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromDoubleToIntFunction_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromDoubleToIntFunction(v -> { + throw new NumberFormatException(); + }).applyAsInt(1.0)); + } + @Test + public void fromDoubleToIntFunction_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromDoubleToIntFunction(v -> { + throw new ServiceConfigurationError(""); + }).applyAsInt(1.0)); + } + @Test + public void fromDoubleToLongFunction_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingDoubleToLongFunction lambda = mock(ThrowingDoubleToLongFunction.class); + when(lambda.applyAsLong(1.0)).thenReturn(2L); + assertEquals(2L, collector.fromDoubleToLongFunction(lambda).applyAsLong(1.0)); + verify(lambda, only()).applyAsLong(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleToLongFunction_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromDoubleToLongFunction(v -> { + throw new DataFormatException(); + }).applyAsLong(1.0)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromDoubleToLongFunction_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromDoubleToLongFunction(v -> { + throw new NumberFormatException(); + }).applyAsLong(1.0)); + } + @Test + public void fromDoubleToLongFunction_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromDoubleToLongFunction(v -> { + throw new ServiceConfigurationError(""); + }).applyAsLong(1.0)); + } + @Test + public void fromUnaryOperator_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingUnaryOperator lambda = mock(ThrowingUnaryOperator.class); + when(lambda.apply("input")).thenReturn("value"); + assertEquals("value", collector.fromUnaryOperator(lambda).apply("input")); + verify(lambda, only()).apply("input"); + assertTrue(collector.empty()); + } + @Test + public void fromUnaryOperator_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromUnaryOperator(o -> { + throw new DataFormatException(); + }).apply("input")); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromUnaryOperator_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromUnaryOperator(o -> { + throw new NumberFormatException(); + }).apply("input")); + } + @Test + public void fromUnaryOperator_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromUnaryOperator(o -> { + throw new ServiceConfigurationError(""); + }).apply("input")); + } + @Test + public void fromIntUnaryOperator_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingIntUnaryOperator lambda = mock(ThrowingIntUnaryOperator.class); + when(lambda.applyAsInt(1)).thenReturn(2); + assertEquals(2, collector.fromIntUnaryOperator(lambda).applyAsInt(1)); + verify(lambda, only()).applyAsInt(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntUnaryOperator_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromIntUnaryOperator(o -> { + throw new DataFormatException(); + }).applyAsInt(1)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromIntUnaryOperator_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromIntUnaryOperator(o -> { + throw new NumberFormatException(); + }).applyAsInt(1)); + } + @Test + public void fromIntUnaryOperator_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromIntUnaryOperator(o -> { + throw new ServiceConfigurationError(""); + }).applyAsInt(1)); + } + @Test + public void fromLongUnaryOperator_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingLongUnaryOperator lambda = mock(ThrowingLongUnaryOperator.class); + when(lambda.applyAsLong(1L)).thenReturn(2L); + assertEquals(2L, collector.fromLongUnaryOperator(lambda).applyAsLong(1L)); + verify(lambda, only()).applyAsLong(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongUnaryOperator_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromLongUnaryOperator(o -> { + throw new DataFormatException(); + }).applyAsLong(1L)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromLongUnaryOperator_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromLongUnaryOperator(o -> { + throw new NumberFormatException(); + }).applyAsLong(1L)); + } + @Test + public void fromLongUnaryOperator_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromLongUnaryOperator(o -> { + throw new ServiceConfigurationError(""); + }).applyAsLong(1L)); + } + @Test + public void fromDoubleUnaryOperator_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingDoubleUnaryOperator lambda = mock(ThrowingDoubleUnaryOperator.class); + when(lambda.applyAsDouble(1.0)).thenReturn(2.0); + assertEquals(2.0, collector.fromDoubleUnaryOperator(lambda).applyAsDouble(1.0), 0.1); + verify(lambda, only()).applyAsDouble(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleUnaryOperator_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromDoubleUnaryOperator(o -> { + throw new DataFormatException(); + }).applyAsDouble(1.0)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromDoubleUnaryOperator_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromDoubleUnaryOperator(o -> { + throw new NumberFormatException(); + }).applyAsDouble(1.0)); + } + @Test + public void fromDoubleUnaryOperator_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromDoubleUnaryOperator(o -> { + throw new ServiceConfigurationError(""); + }).applyAsDouble(1.0)); + } + @Test + public void fromBiFunction_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingBiFunction lambda = mock(ThrowingBiFunction.class); + when(lambda.apply("input1", "input2")).thenReturn("value"); + assertEquals("value", collector.fromBiFunction(lambda).apply("input1", "input2")); + verify(lambda, only()).apply("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromBiFunction_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromBiFunction((t, u) -> { + throw new DataFormatException(); + }).apply("input1", "input2")); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromBiFunction_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromBiFunction((t, u) -> { + throw new NumberFormatException(); + }).apply("input1", "input2")); + } + @Test + public void fromBiFunction_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromBiFunction((t, u) -> { + throw new ServiceConfigurationError(""); + }).apply("input1", "input2")); + } + @Test + public void fromToIntBiFunction_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingToIntBiFunction lambda = mock(ThrowingToIntBiFunction.class); + when(lambda.applyAsInt("input1", "input2")).thenReturn(2); + assertEquals(2, collector.fromToIntBiFunction(lambda).applyAsInt("input1", "input2")); + verify(lambda, only()).applyAsInt("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromToIntBiFunction_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromToIntBiFunction((t, u) -> { + throw new DataFormatException(); + }).applyAsInt("input1", "input2")); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromToIntBiFunction_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromToIntBiFunction((t, u) -> { + throw new NumberFormatException(); + }).applyAsInt("input1", "input2")); + } + @Test + public void fromToIntBiFunction_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromToIntBiFunction((t, u) -> { + throw new ServiceConfigurationError(""); + }).applyAsInt("input1", "input2")); + } + @Test + public void fromToLongBiFunction_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingToLongBiFunction lambda = mock(ThrowingToLongBiFunction.class); + when(lambda.applyAsLong("input1", "input2")).thenReturn(2L); + assertEquals(2L, collector.fromToLongBiFunction(lambda).applyAsLong("input1", "input2")); + verify(lambda, only()).applyAsLong("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromToLongBiFunction_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromToLongBiFunction((t, u) -> { + throw new DataFormatException(); + }).applyAsLong("input1", "input2")); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromToLongBiFunction_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromToLongBiFunction((t, u) -> { + throw new NumberFormatException(); + }).applyAsLong("input1", "input2")); + } + @Test + public void fromToLongBiFunction_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromToLongBiFunction((t, u) -> { + throw new ServiceConfigurationError(""); + }).applyAsLong("input1", "input2")); + } + @Test + public void fromToDoubleBiFunction_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingToDoubleBiFunction lambda = mock(ThrowingToDoubleBiFunction.class); + when(lambda.applyAsDouble("input1", "input2")).thenReturn(2.0); + assertEquals(2.0, collector.fromToDoubleBiFunction(lambda).applyAsDouble("input1", "input2"), 0.1); + verify(lambda, only()).applyAsDouble("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromToDoubleBiFunction_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromToDoubleBiFunction((t, u) -> { + throw new DataFormatException(); + }).applyAsDouble("input1", "input2")); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromToDoubleBiFunction_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromToDoubleBiFunction((t, u) -> { + throw new NumberFormatException(); + }).applyAsDouble("input1", "input2")); + } + @Test + public void fromToDoubleBiFunction_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromToDoubleBiFunction((t, u) -> { + throw new ServiceConfigurationError(""); + }).applyAsDouble("input1", "input2")); + } + @Test + public void fromBinaryOperator_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingBinaryOperator lambda = mock(ThrowingBinaryOperator.class); + when(lambda.apply("input1", "input2")).thenReturn("value"); + assertEquals("value", collector.fromBinaryOperator(lambda).apply("input1", "input2")); + verify(lambda, only()).apply("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromBinaryOperator_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromBinaryOperator((l, r) -> { + throw new DataFormatException(); + }).apply("input1", "input2")); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromBinaryOperator_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).apply("input1", "input2")); + } + @Test + public void fromBinaryOperator_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromBinaryOperator((l, r) -> { + throw new ServiceConfigurationError(""); + }).apply("input1", "input2")); + } + @Test + public void fromIntBinaryOperator_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingIntBinaryOperator lambda = mock(ThrowingIntBinaryOperator.class); + when(lambda.applyAsInt(11, 12)).thenReturn(2); + assertEquals(2, collector.fromIntBinaryOperator(lambda).applyAsInt(11, 12)); + verify(lambda, only()).applyAsInt(11, 12); + assertTrue(collector.empty()); + } + @Test + public void fromIntBinaryOperator_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromIntBinaryOperator((l, r) -> { + throw new DataFormatException(); + }).applyAsInt(11, 12)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromIntBinaryOperator_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromIntBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).applyAsInt(11, 12)); + } + @Test + public void fromIntBinaryOperator_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromIntBinaryOperator((l, r) -> { + throw new ServiceConfigurationError(""); + }).applyAsInt(11, 12)); + } + @Test + public void fromLongBinaryOperator_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingLongBinaryOperator lambda = mock(ThrowingLongBinaryOperator.class); + when(lambda.applyAsLong(11L, 12L)).thenReturn(2L); + assertEquals(2L, collector.fromLongBinaryOperator(lambda).applyAsLong(11L, 12L)); + verify(lambda, only()).applyAsLong(11L, 12L); + assertTrue(collector.empty()); + } + @Test + public void fromLongBinaryOperator_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromLongBinaryOperator((l, r) -> { + throw new DataFormatException(); + }).applyAsLong(11L, 12L)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromLongBinaryOperator_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromLongBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).applyAsLong(11L, 12L)); + } + @Test + public void fromLongBinaryOperator_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromLongBinaryOperator((l, r) -> { + throw new ServiceConfigurationError(""); + }).applyAsLong(11L, 12L)); + } + @Test + public void fromDoubleBinaryOperator_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingDoubleBinaryOperator lambda = mock(ThrowingDoubleBinaryOperator.class); + when(lambda.applyAsDouble(1.1, 1.2)).thenReturn(2.0); + assertEquals(2.0, collector.fromDoubleBinaryOperator(lambda).applyAsDouble(1.1, 1.2), 0.1); + verify(lambda, only()).applyAsDouble(1.1, 1.2); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleBinaryOperator_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.fromDoubleBinaryOperator((l, r) -> { + throw new DataFormatException(); + }).applyAsDouble(1.1, 1.2)); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void fromDoubleBinaryOperator_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().fromDoubleBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).applyAsDouble(1.1, 1.2)); + } + @Test + public void fromDoubleBinaryOperator_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().fromDoubleBinaryOperator((l, r) -> { + throw new ServiceConfigurationError(""); + }).applyAsDouble(1.1, 1.2)); + } + @Test + public void comparator_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingComparator lambda = mock(ThrowingComparator.class); + when(lambda.compare("input1", "input2")).thenReturn(2); + assertEquals(2, collector.comparator(lambda).compare("input1", "input2")); + verify(lambda, only()).compare("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void comparator_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.comparator((l, r) -> { + throw new DataFormatException(); + }).compare("input1", "input2")); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void comparator_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().comparator((l, r) -> { + throw new NumberFormatException(); + }).compare("input1", "input2")); + } + @Test + public void comparator_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().comparator((l, r) -> { + throw new ServiceConfigurationError(""); + }).compare("input1", "input2")); + } + @Test + public void closeable_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + AutoCloseable lambda = mock(AutoCloseable.class); + collector.closeable(lambda).close(); + verify(lambda, only()).close(); + assertTrue(collector.empty()); + } + @Test + public void closeable_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.closeable(() -> { + throw new DataFormatException(); + }).close()); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void closeable_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().closeable(() -> { + throw new NumberFormatException(); + }).close()); + } + @Test + public void closeable_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().closeable(() -> { + throw new ServiceConfigurationError(""); + }).close()); + } + @Test + public void run_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingRunnable lambda = mock(ThrowingRunnable.class); + collector.run(lambda); + verify(lambda, only()).run(); + assertTrue(collector.empty()); + } + @Test + public void run_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.run(() -> { + throw new DataFormatException(); + })); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void run_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().run(() -> { + throw new NumberFormatException(); + })); + } + @Test + public void run_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().run(() -> { + throw new ServiceConfigurationError(""); + })); + } + @Test + public void get_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + @SuppressWarnings("unchecked") ThrowingSupplier lambda = mock(ThrowingSupplier.class); + when(lambda.get()).thenReturn("value"); + assertEquals("value", collector.get(lambda)); + verify(lambda, only()).get(); + assertTrue(collector.empty()); + } + @Test + public void get_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.get(() -> { + throw new DataFormatException(); + })); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void get_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().get(() -> { + throw new NumberFormatException(); + })); + } + @Test + public void get_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().get(() -> { + throw new ServiceConfigurationError(""); + })); + } + @Test + public void getAsInt_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingIntSupplier lambda = mock(ThrowingIntSupplier.class); + when(lambda.getAsInt()).thenReturn(2); + assertEquals(2, collector.getAsInt(lambda)); + verify(lambda, only()).getAsInt(); + assertTrue(collector.empty()); + } + @Test + public void getAsInt_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.getAsInt(() -> { + throw new DataFormatException(); + })); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void getAsInt_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().getAsInt(() -> { + throw new NumberFormatException(); + })); + } + @Test + public void getAsInt_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().getAsInt(() -> { + throw new ServiceConfigurationError(""); + })); + } + @Test + public void getAsLong_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingLongSupplier lambda = mock(ThrowingLongSupplier.class); + when(lambda.getAsLong()).thenReturn(2L); + assertEquals(2L, collector.getAsLong(lambda)); + verify(lambda, only()).getAsLong(); + assertTrue(collector.empty()); + } + @Test + public void getAsLong_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.getAsLong(() -> { + throw new DataFormatException(); + })); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void getAsLong_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().getAsLong(() -> { + throw new NumberFormatException(); + })); + } + @Test + public void getAsLong_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().getAsLong(() -> { + throw new ServiceConfigurationError(""); + })); + } + @Test + public void getAsDouble_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingDoubleSupplier lambda = mock(ThrowingDoubleSupplier.class); + when(lambda.getAsDouble()).thenReturn(2.0); + assertEquals(2.0, collector.getAsDouble(lambda), 0.1); + verify(lambda, only()).getAsDouble(); + assertTrue(collector.empty()); + } + @Test + public void getAsDouble_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.getAsDouble(() -> { + throw new DataFormatException(); + })); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void getAsDouble_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().getAsDouble(() -> { + throw new NumberFormatException(); + })); + } + @Test + public void getAsDouble_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().getAsDouble(() -> { + throw new ServiceConfigurationError(""); + })); + } + @Test + public void getAsBoolean_complete() throws Throwable { + var collector = new CheckedExceptionCollector(); + ThrowingBooleanSupplier lambda = mock(ThrowingBooleanSupplier.class); + when(lambda.getAsBoolean()).thenReturn(true); + assertEquals(true, collector.getAsBoolean(lambda)); + verify(lambda, only()).getAsBoolean(); + assertTrue(collector.empty()); + } + @Test + public void getAsBoolean_exception() { + var collector = new CheckedExceptionCollector(); + assertThrows(CollectedException.class, () -> collector.getAsBoolean(() -> { + throw new DataFormatException(); + })); + assertThat(collector.single(), instanceOf(DataFormatException.class)); + } + @Test + public void getAsBoolean_runtime() { + assertThrows(NumberFormatException.class, () -> new CheckedExceptionCollector().getAsBoolean(() -> { + throw new NumberFormatException(); + })); + } + @Test + public void getAsBoolean_error() { + assertThrows(ServiceConfigurationError.class, () -> new CheckedExceptionCollector().getAsBoolean(() -> { + throw new ServiceConfigurationError(""); + })); + } } diff --git a/src/test/java/com/machinezoo/noexception/ExceptionFilterTest.java b/src/test/java/com/machinezoo/noexception/ExceptionFilterTest.java index 0a12e0c..03ff944 100644 --- a/src/test/java/com/machinezoo/noexception/ExceptionFilterTest.java +++ b/src/test/java/com/machinezoo/noexception/ExceptionFilterTest.java @@ -12,1293 +12,1293 @@ import com.machinezoo.closeablescope.CloseableScope; public class ExceptionFilterTest { - @Test - public void runnable_complete() { - var collector = new FilteredExceptionCollector(false); - Runnable lambda = mock(Runnable.class); - collector.runnable(lambda).run(); - verify(lambda, only()).run(); - assertTrue(collector.empty()); - } - @Test - public void runnable_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.runnable(() -> { - throw new NumberFormatException(); - }).run()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void runnable_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.runnable(() -> { - throw new NumberFormatException(); - }).run()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void supplier_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") Supplier lambda = mock(Supplier.class); - when(lambda.get()).thenReturn("value"); - assertEquals("value", collector.supplier(lambda).get()); - verify(lambda, only()).get(); - assertTrue(collector.empty()); - } - @Test - public void supplier_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.supplier(() -> { - throw new NumberFormatException(); - }).get()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void supplier_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.supplier(() -> { - throw new NumberFormatException(); - }).get()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntSupplier_complete() { - var collector = new FilteredExceptionCollector(false); - IntSupplier lambda = mock(IntSupplier.class); - when(lambda.getAsInt()).thenReturn(2); - assertEquals(2, collector.fromIntSupplier(lambda).getAsInt()); - verify(lambda, only()).getAsInt(); - assertTrue(collector.empty()); - } - @Test - public void fromIntSupplier_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromIntSupplier(() -> { - throw new NumberFormatException(); - }).getAsInt()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntSupplier_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromIntSupplier(() -> { - throw new NumberFormatException(); - }).getAsInt()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongSupplier_complete() { - var collector = new FilteredExceptionCollector(false); - LongSupplier lambda = mock(LongSupplier.class); - when(lambda.getAsLong()).thenReturn(2L); - assertEquals(2L, collector.fromLongSupplier(lambda).getAsLong()); - verify(lambda, only()).getAsLong(); - assertTrue(collector.empty()); - } - @Test - public void fromLongSupplier_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromLongSupplier(() -> { - throw new NumberFormatException(); - }).getAsLong()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongSupplier_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromLongSupplier(() -> { - throw new NumberFormatException(); - }).getAsLong()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleSupplier_complete() { - var collector = new FilteredExceptionCollector(false); - DoubleSupplier lambda = mock(DoubleSupplier.class); - when(lambda.getAsDouble()).thenReturn(2.0); - assertEquals(2.0, collector.fromDoubleSupplier(lambda).getAsDouble()); - verify(lambda, only()).getAsDouble(); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleSupplier_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromDoubleSupplier(() -> { - throw new NumberFormatException(); - }).getAsDouble()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleSupplier_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromDoubleSupplier(() -> { - throw new NumberFormatException(); - }).getAsDouble()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBooleanSupplier_complete() { - var collector = new FilteredExceptionCollector(false); - BooleanSupplier lambda = mock(BooleanSupplier.class); - when(lambda.getAsBoolean()).thenReturn(true); - assertEquals(true, collector.fromBooleanSupplier(lambda).getAsBoolean()); - verify(lambda, only()).getAsBoolean(); - assertTrue(collector.empty()); - } - @Test - public void fromBooleanSupplier_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromBooleanSupplier(() -> { - throw new NumberFormatException(); - }).getAsBoolean()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBooleanSupplier_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromBooleanSupplier(() -> { - throw new NumberFormatException(); - }).getAsBoolean()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void consumer_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") Consumer lambda = mock(Consumer.class); - collector.consumer(lambda).accept("input"); - verify(lambda, only()).accept("input"); - assertTrue(collector.empty()); - } - @Test - public void consumer_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.consumer(t -> { - throw new NumberFormatException(); - }).accept("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void consumer_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.consumer(t -> { - throw new NumberFormatException(); - }).accept("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntConsumer_complete() { - var collector = new FilteredExceptionCollector(false); - IntConsumer lambda = mock(IntConsumer.class); - collector.fromIntConsumer(lambda).accept(1); - verify(lambda, only()).accept(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntConsumer_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromIntConsumer(v -> { - throw new NumberFormatException(); - }).accept(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntConsumer_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromIntConsumer(v -> { - throw new NumberFormatException(); - }).accept(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongConsumer_complete() { - var collector = new FilteredExceptionCollector(false); - LongConsumer lambda = mock(LongConsumer.class); - collector.fromLongConsumer(lambda).accept(1L); - verify(lambda, only()).accept(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongConsumer_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromLongConsumer(v -> { - throw new NumberFormatException(); - }).accept(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongConsumer_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromLongConsumer(v -> { - throw new NumberFormatException(); - }).accept(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleConsumer_complete() { - var collector = new FilteredExceptionCollector(false); - DoubleConsumer lambda = mock(DoubleConsumer.class); - collector.fromDoubleConsumer(lambda).accept(1.0); - verify(lambda, only()).accept(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleConsumer_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromDoubleConsumer(v -> { - throw new NumberFormatException(); - }).accept(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleConsumer_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromDoubleConsumer(v -> { - throw new NumberFormatException(); - }).accept(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBiConsumer_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") BiConsumer lambda = mock(BiConsumer.class); - collector.fromBiConsumer(lambda).accept("input1", "input2"); - verify(lambda, only()).accept("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromBiConsumer_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromBiConsumer((t, u) -> { - throw new NumberFormatException(); - }).accept("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBiConsumer_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromBiConsumer((t, u) -> { - throw new NumberFormatException(); - }).accept("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromObjIntConsumer_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") ObjIntConsumer lambda = mock(ObjIntConsumer.class); - collector.fromObjIntConsumer(lambda).accept("input", 1); - verify(lambda, only()).accept("input", 1); - assertTrue(collector.empty()); - } - @Test - public void fromObjIntConsumer_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromObjIntConsumer((t, v) -> { - throw new NumberFormatException(); - }).accept("input", 1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromObjIntConsumer_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromObjIntConsumer((t, v) -> { - throw new NumberFormatException(); - }).accept("input", 1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromObjLongConsumer_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") ObjLongConsumer lambda = mock(ObjLongConsumer.class); - collector.fromObjLongConsumer(lambda).accept("input", 1L); - verify(lambda, only()).accept("input", 1L); - assertTrue(collector.empty()); - } - @Test - public void fromObjLongConsumer_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromObjLongConsumer((t, v) -> { - throw new NumberFormatException(); - }).accept("input", 1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromObjLongConsumer_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromObjLongConsumer((t, v) -> { - throw new NumberFormatException(); - }).accept("input", 1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromObjDoubleConsumer_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") ObjDoubleConsumer lambda = mock(ObjDoubleConsumer.class); - collector.fromObjDoubleConsumer(lambda).accept("input", 1.0); - verify(lambda, only()).accept("input", 1.0); - assertTrue(collector.empty()); - } - @Test - public void fromObjDoubleConsumer_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromObjDoubleConsumer((t, v) -> { - throw new NumberFormatException(); - }).accept("input", 1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromObjDoubleConsumer_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromObjDoubleConsumer((t, v) -> { - throw new NumberFormatException(); - }).accept("input", 1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void predicate_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") Predicate lambda = mock(Predicate.class); - when(lambda.test("input")).thenReturn(true); - assertEquals(true, collector.predicate(lambda).test("input")); - verify(lambda, only()).test("input"); - assertTrue(collector.empty()); - } - @Test - public void predicate_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.predicate(t -> { - throw new NumberFormatException(); - }).test("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void predicate_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.predicate(t -> { - throw new NumberFormatException(); - }).test("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntPredicate_complete() { - var collector = new FilteredExceptionCollector(false); - IntPredicate lambda = mock(IntPredicate.class); - when(lambda.test(1)).thenReturn(true); - assertEquals(true, collector.fromIntPredicate(lambda).test(1)); - verify(lambda, only()).test(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntPredicate_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromIntPredicate(v -> { - throw new NumberFormatException(); - }).test(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntPredicate_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromIntPredicate(v -> { - throw new NumberFormatException(); - }).test(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongPredicate_complete() { - var collector = new FilteredExceptionCollector(false); - LongPredicate lambda = mock(LongPredicate.class); - when(lambda.test(1L)).thenReturn(true); - assertEquals(true, collector.fromLongPredicate(lambda).test(1L)); - verify(lambda, only()).test(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongPredicate_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromLongPredicate(v -> { - throw new NumberFormatException(); - }).test(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongPredicate_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromLongPredicate(v -> { - throw new NumberFormatException(); - }).test(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoublePredicate_complete() { - var collector = new FilteredExceptionCollector(false); - DoublePredicate lambda = mock(DoublePredicate.class); - when(lambda.test(1.0)).thenReturn(true); - assertEquals(true, collector.fromDoublePredicate(lambda).test(1.0)); - verify(lambda, only()).test(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoublePredicate_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromDoublePredicate(v -> { - throw new NumberFormatException(); - }).test(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoublePredicate_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromDoublePredicate(v -> { - throw new NumberFormatException(); - }).test(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBiPredicate_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") BiPredicate lambda = mock(BiPredicate.class); - when(lambda.test("input1", "input2")).thenReturn(true); - assertEquals(true, collector.fromBiPredicate(lambda).test("input1", "input2")); - verify(lambda, only()).test("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromBiPredicate_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromBiPredicate((t, u) -> { - throw new NumberFormatException(); - }).test("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBiPredicate_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromBiPredicate((t, u) -> { - throw new NumberFormatException(); - }).test("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void function_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") Function lambda = mock(Function.class); - when(lambda.apply("input")).thenReturn("value"); - assertEquals("value", collector.function(lambda).apply("input")); - verify(lambda, only()).apply("input"); - assertTrue(collector.empty()); - } - @Test - public void function_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.function(t -> { - throw new NumberFormatException(); - }).apply("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void function_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.function(t -> { - throw new NumberFormatException(); - }).apply("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToIntFunction_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") ToIntFunction lambda = mock(ToIntFunction.class); - when(lambda.applyAsInt("input")).thenReturn(2); - assertEquals(2, collector.fromToIntFunction(lambda).applyAsInt("input")); - verify(lambda, only()).applyAsInt("input"); - assertTrue(collector.empty()); - } - @Test - public void fromToIntFunction_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromToIntFunction(v -> { - throw new NumberFormatException(); - }).applyAsInt("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToIntFunction_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromToIntFunction(v -> { - throw new NumberFormatException(); - }).applyAsInt("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntFunction_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") IntFunction lambda = mock(IntFunction.class); - when(lambda.apply(1)).thenReturn("value"); - assertEquals("value", collector.fromIntFunction(lambda).apply(1)); - verify(lambda, only()).apply(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntFunction_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromIntFunction(v -> { - throw new NumberFormatException(); - }).apply(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntFunction_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromIntFunction(v -> { - throw new NumberFormatException(); - }).apply(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntToLongFunction_complete() { - var collector = new FilteredExceptionCollector(false); - IntToLongFunction lambda = mock(IntToLongFunction.class); - when(lambda.applyAsLong(1)).thenReturn(2L); - assertEquals(2L, collector.fromIntToLongFunction(lambda).applyAsLong(1)); - verify(lambda, only()).applyAsLong(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntToLongFunction_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromIntToLongFunction(v -> { - throw new NumberFormatException(); - }).applyAsLong(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntToLongFunction_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromIntToLongFunction(v -> { - throw new NumberFormatException(); - }).applyAsLong(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntToDoubleFunction_complete() { - var collector = new FilteredExceptionCollector(false); - IntToDoubleFunction lambda = mock(IntToDoubleFunction.class); - when(lambda.applyAsDouble(1)).thenReturn(2.0); - assertEquals(2.0, collector.fromIntToDoubleFunction(lambda).applyAsDouble(1)); - verify(lambda, only()).applyAsDouble(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntToDoubleFunction_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromIntToDoubleFunction(v -> { - throw new NumberFormatException(); - }).applyAsDouble(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntToDoubleFunction_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromIntToDoubleFunction(v -> { - throw new NumberFormatException(); - }).applyAsDouble(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToLongFunction_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") ToLongFunction lambda = mock(ToLongFunction.class); - when(lambda.applyAsLong("input")).thenReturn(2L); - assertEquals(2L, collector.fromToLongFunction(lambda).applyAsLong("input")); - verify(lambda, only()).applyAsLong("input"); - assertTrue(collector.empty()); - } - @Test - public void fromToLongFunction_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromToLongFunction(v -> { - throw new NumberFormatException(); - }).applyAsLong("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToLongFunction_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromToLongFunction(v -> { - throw new NumberFormatException(); - }).applyAsLong("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongFunction_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") LongFunction lambda = mock(LongFunction.class); - when(lambda.apply(1L)).thenReturn("value"); - assertEquals("value", collector.fromLongFunction(lambda).apply(1L)); - verify(lambda, only()).apply(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongFunction_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromLongFunction(v -> { - throw new NumberFormatException(); - }).apply(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongFunction_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromLongFunction(v -> { - throw new NumberFormatException(); - }).apply(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongToIntFunction_complete() { - var collector = new FilteredExceptionCollector(false); - LongToIntFunction lambda = mock(LongToIntFunction.class); - when(lambda.applyAsInt(1L)).thenReturn(2); - assertEquals(2, collector.fromLongToIntFunction(lambda).applyAsInt(1L)); - verify(lambda, only()).applyAsInt(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongToIntFunction_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromLongToIntFunction(v -> { - throw new NumberFormatException(); - }).applyAsInt(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongToIntFunction_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromLongToIntFunction(v -> { - throw new NumberFormatException(); - }).applyAsInt(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongToDoubleFunction_complete() { - var collector = new FilteredExceptionCollector(false); - LongToDoubleFunction lambda = mock(LongToDoubleFunction.class); - when(lambda.applyAsDouble(1L)).thenReturn(2.0); - assertEquals(2.0, collector.fromLongToDoubleFunction(lambda).applyAsDouble(1L)); - verify(lambda, only()).applyAsDouble(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongToDoubleFunction_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromLongToDoubleFunction(v -> { - throw new NumberFormatException(); - }).applyAsDouble(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongToDoubleFunction_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromLongToDoubleFunction(v -> { - throw new NumberFormatException(); - }).applyAsDouble(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToDoubleFunction_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") ToDoubleFunction lambda = mock(ToDoubleFunction.class); - when(lambda.applyAsDouble("input")).thenReturn(2.0); - assertEquals(2.0, collector.fromToDoubleFunction(lambda).applyAsDouble("input")); - verify(lambda, only()).applyAsDouble("input"); - assertTrue(collector.empty()); - } - @Test - public void fromToDoubleFunction_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromToDoubleFunction(v -> { - throw new NumberFormatException(); - }).applyAsDouble("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToDoubleFunction_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromToDoubleFunction(v -> { - throw new NumberFormatException(); - }).applyAsDouble("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleFunction_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") DoubleFunction lambda = mock(DoubleFunction.class); - when(lambda.apply(1.0)).thenReturn("value"); - assertEquals("value", collector.fromDoubleFunction(lambda).apply(1.0)); - verify(lambda, only()).apply(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleFunction_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromDoubleFunction(v -> { - throw new NumberFormatException(); - }).apply(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleFunction_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromDoubleFunction(v -> { - throw new NumberFormatException(); - }).apply(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleToIntFunction_complete() { - var collector = new FilteredExceptionCollector(false); - DoubleToIntFunction lambda = mock(DoubleToIntFunction.class); - when(lambda.applyAsInt(1.0)).thenReturn(2); - assertEquals(2, collector.fromDoubleToIntFunction(lambda).applyAsInt(1.0)); - verify(lambda, only()).applyAsInt(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleToIntFunction_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromDoubleToIntFunction(v -> { - throw new NumberFormatException(); - }).applyAsInt(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleToIntFunction_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromDoubleToIntFunction(v -> { - throw new NumberFormatException(); - }).applyAsInt(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleToLongFunction_complete() { - var collector = new FilteredExceptionCollector(false); - DoubleToLongFunction lambda = mock(DoubleToLongFunction.class); - when(lambda.applyAsLong(1.0)).thenReturn(2L); - assertEquals(2L, collector.fromDoubleToLongFunction(lambda).applyAsLong(1.0)); - verify(lambda, only()).applyAsLong(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleToLongFunction_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromDoubleToLongFunction(v -> { - throw new NumberFormatException(); - }).applyAsLong(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleToLongFunction_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromDoubleToLongFunction(v -> { - throw new NumberFormatException(); - }).applyAsLong(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromUnaryOperator_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") UnaryOperator lambda = mock(UnaryOperator.class); - when(lambda.apply("input")).thenReturn("value"); - assertEquals("value", collector.fromUnaryOperator(lambda).apply("input")); - verify(lambda, only()).apply("input"); - assertTrue(collector.empty()); - } - @Test - public void fromUnaryOperator_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromUnaryOperator(o -> { - throw new NumberFormatException(); - }).apply("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromUnaryOperator_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromUnaryOperator(o -> { - throw new NumberFormatException(); - }).apply("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntUnaryOperator_complete() { - var collector = new FilteredExceptionCollector(false); - IntUnaryOperator lambda = mock(IntUnaryOperator.class); - when(lambda.applyAsInt(1)).thenReturn(2); - assertEquals(2, collector.fromIntUnaryOperator(lambda).applyAsInt(1)); - verify(lambda, only()).applyAsInt(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntUnaryOperator_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromIntUnaryOperator(o -> { - throw new NumberFormatException(); - }).applyAsInt(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntUnaryOperator_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromIntUnaryOperator(o -> { - throw new NumberFormatException(); - }).applyAsInt(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongUnaryOperator_complete() { - var collector = new FilteredExceptionCollector(false); - LongUnaryOperator lambda = mock(LongUnaryOperator.class); - when(lambda.applyAsLong(1L)).thenReturn(2L); - assertEquals(2L, collector.fromLongUnaryOperator(lambda).applyAsLong(1L)); - verify(lambda, only()).applyAsLong(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongUnaryOperator_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromLongUnaryOperator(o -> { - throw new NumberFormatException(); - }).applyAsLong(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongUnaryOperator_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromLongUnaryOperator(o -> { - throw new NumberFormatException(); - }).applyAsLong(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleUnaryOperator_complete() { - var collector = new FilteredExceptionCollector(false); - DoubleUnaryOperator lambda = mock(DoubleUnaryOperator.class); - when(lambda.applyAsDouble(1.0)).thenReturn(2.0); - assertEquals(2.0, collector.fromDoubleUnaryOperator(lambda).applyAsDouble(1.0)); - verify(lambda, only()).applyAsDouble(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleUnaryOperator_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromDoubleUnaryOperator(o -> { - throw new NumberFormatException(); - }).applyAsDouble(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleUnaryOperator_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromDoubleUnaryOperator(o -> { - throw new NumberFormatException(); - }).applyAsDouble(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBiFunction_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") BiFunction lambda = mock(BiFunction.class); - when(lambda.apply("input1", "input2")).thenReturn("value"); - assertEquals("value", collector.fromBiFunction(lambda).apply("input1", "input2")); - verify(lambda, only()).apply("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromBiFunction_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromBiFunction((t, u) -> { - throw new NumberFormatException(); - }).apply("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBiFunction_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromBiFunction((t, u) -> { - throw new NumberFormatException(); - }).apply("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToIntBiFunction_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") ToIntBiFunction lambda = mock(ToIntBiFunction.class); - when(lambda.applyAsInt("input1", "input2")).thenReturn(2); - assertEquals(2, collector.fromToIntBiFunction(lambda).applyAsInt("input1", "input2")); - verify(lambda, only()).applyAsInt("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromToIntBiFunction_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromToIntBiFunction((t, u) -> { - throw new NumberFormatException(); - }).applyAsInt("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToIntBiFunction_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromToIntBiFunction((t, u) -> { - throw new NumberFormatException(); - }).applyAsInt("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToLongBiFunction_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") ToLongBiFunction lambda = mock(ToLongBiFunction.class); - when(lambda.applyAsLong("input1", "input2")).thenReturn(2L); - assertEquals(2L, collector.fromToLongBiFunction(lambda).applyAsLong("input1", "input2")); - verify(lambda, only()).applyAsLong("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromToLongBiFunction_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromToLongBiFunction((t, u) -> { - throw new NumberFormatException(); - }).applyAsLong("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToLongBiFunction_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromToLongBiFunction((t, u) -> { - throw new NumberFormatException(); - }).applyAsLong("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToDoubleBiFunction_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") ToDoubleBiFunction lambda = mock(ToDoubleBiFunction.class); - when(lambda.applyAsDouble("input1", "input2")).thenReturn(2.0); - assertEquals(2.0, collector.fromToDoubleBiFunction(lambda).applyAsDouble("input1", "input2")); - verify(lambda, only()).applyAsDouble("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromToDoubleBiFunction_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromToDoubleBiFunction((t, u) -> { - throw new NumberFormatException(); - }).applyAsDouble("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToDoubleBiFunction_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromToDoubleBiFunction((t, u) -> { - throw new NumberFormatException(); - }).applyAsDouble("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBinaryOperator_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") BinaryOperator lambda = mock(BinaryOperator.class); - when(lambda.apply("input1", "input2")).thenReturn("value"); - assertEquals("value", collector.fromBinaryOperator(lambda).apply("input1", "input2")); - verify(lambda, only()).apply("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromBinaryOperator_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).apply("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBinaryOperator_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).apply("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntBinaryOperator_complete() { - var collector = new FilteredExceptionCollector(false); - IntBinaryOperator lambda = mock(IntBinaryOperator.class); - when(lambda.applyAsInt(11, 12)).thenReturn(2); - assertEquals(2, collector.fromIntBinaryOperator(lambda).applyAsInt(11, 12)); - verify(lambda, only()).applyAsInt(11, 12); - assertTrue(collector.empty()); - } - @Test - public void fromIntBinaryOperator_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromIntBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).applyAsInt(11, 12)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntBinaryOperator_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromIntBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).applyAsInt(11, 12)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongBinaryOperator_complete() { - var collector = new FilteredExceptionCollector(false); - LongBinaryOperator lambda = mock(LongBinaryOperator.class); - when(lambda.applyAsLong(11L, 12L)).thenReturn(2L); - assertEquals(2L, collector.fromLongBinaryOperator(lambda).applyAsLong(11L, 12L)); - verify(lambda, only()).applyAsLong(11L, 12L); - assertTrue(collector.empty()); - } - @Test - public void fromLongBinaryOperator_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromLongBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).applyAsLong(11L, 12L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongBinaryOperator_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromLongBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).applyAsLong(11L, 12L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleBinaryOperator_complete() { - var collector = new FilteredExceptionCollector(false); - DoubleBinaryOperator lambda = mock(DoubleBinaryOperator.class); - when(lambda.applyAsDouble(1.1, 1.2)).thenReturn(2.0); - assertEquals(2.0, collector.fromDoubleBinaryOperator(lambda).applyAsDouble(1.1, 1.2)); - verify(lambda, only()).applyAsDouble(1.1, 1.2); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleBinaryOperator_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromDoubleBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).applyAsDouble(1.1, 1.2)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleBinaryOperator_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.fromDoubleBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).applyAsDouble(1.1, 1.2)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void comparator_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") Comparator lambda = mock(Comparator.class); - when(lambda.compare("input1", "input2")).thenReturn(2); - assertEquals(2, collector.comparator(lambda).compare("input1", "input2")); - verify(lambda, only()).compare("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void comparator_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.comparator((l, r) -> { - throw new NumberFormatException(); - }).compare("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void comparator_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.comparator((l, r) -> { - throw new NumberFormatException(); - }).compare("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void closeable_complete() { - var collector = new FilteredExceptionCollector(false); - CloseableScope lambda = mock(CloseableScope.class); - collector.closeable(lambda).close(); - verify(lambda, only()).close(); - assertTrue(collector.empty()); - } - @Test - public void closeable_rethrow() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.closeable(() -> { - throw new NumberFormatException(); - }).close()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void closeable_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.closeable(() -> { - throw new NumberFormatException(); - }).close()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void run_complete() { - var collector = new FilteredExceptionCollector(false); - Runnable lambda = mock(Runnable.class); - collector.run(lambda); - verify(lambda, only()).run(); - assertTrue(collector.empty()); - } - @Test - public void run_pass() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.run(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void run_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.run(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void get_complete() { - var collector = new FilteredExceptionCollector(false); - @SuppressWarnings("unchecked") Supplier lambda = mock(Supplier.class); - when(lambda.get()).thenReturn("value"); - assertEquals("value", collector.get(lambda)); - verify(lambda, only()).get(); - assertTrue(collector.empty()); - } - @Test - public void get_pass() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.get(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void get_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.get(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void getAsInt_complete() { - var collector = new FilteredExceptionCollector(false); - IntSupplier lambda = mock(IntSupplier.class); - when(lambda.getAsInt()).thenReturn(2); - assertEquals(2, collector.getAsInt(lambda)); - verify(lambda, only()).getAsInt(); - assertTrue(collector.empty()); - } - @Test - public void getAsInt_pass() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.getAsInt(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void getAsInt_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.getAsInt(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void getAsLong_complete() { - var collector = new FilteredExceptionCollector(false); - LongSupplier lambda = mock(LongSupplier.class); - when(lambda.getAsLong()).thenReturn(2L); - assertEquals(2L, collector.getAsLong(lambda)); - verify(lambda, only()).getAsLong(); - assertTrue(collector.empty()); - } - @Test - public void getAsLong_pass() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.getAsLong(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void getAsLong_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.getAsLong(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void getAsDouble_complete() { - var collector = new FilteredExceptionCollector(false); - DoubleSupplier lambda = mock(DoubleSupplier.class); - when(lambda.getAsDouble()).thenReturn(2.0); - assertEquals(2.0, collector.getAsDouble(lambda)); - verify(lambda, only()).getAsDouble(); - assertTrue(collector.empty()); - } - @Test - public void getAsDouble_pass() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.getAsDouble(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void getAsDouble_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.getAsDouble(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void getAsBoolean_complete() { - var collector = new FilteredExceptionCollector(false); - BooleanSupplier lambda = mock(BooleanSupplier.class); - when(lambda.getAsBoolean()).thenReturn(true); - assertEquals(true, collector.getAsBoolean(lambda)); - verify(lambda, only()).getAsBoolean(); - assertTrue(collector.empty()); - } - @Test - public void getAsBoolean_pass() { - var collector = new FilteredExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.getAsBoolean(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void getAsBoolean_replace() { - var collector = new FilteredExceptionCollector(true); - assertThrows(CollectedException.class, () -> collector.getAsBoolean(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } + @Test + public void runnable_complete() { + var collector = new FilteredExceptionCollector(false); + Runnable lambda = mock(Runnable.class); + collector.runnable(lambda).run(); + verify(lambda, only()).run(); + assertTrue(collector.empty()); + } + @Test + public void runnable_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.runnable(() -> { + throw new NumberFormatException(); + }).run()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void runnable_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.runnable(() -> { + throw new NumberFormatException(); + }).run()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void supplier_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") Supplier lambda = mock(Supplier.class); + when(lambda.get()).thenReturn("value"); + assertEquals("value", collector.supplier(lambda).get()); + verify(lambda, only()).get(); + assertTrue(collector.empty()); + } + @Test + public void supplier_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.supplier(() -> { + throw new NumberFormatException(); + }).get()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void supplier_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.supplier(() -> { + throw new NumberFormatException(); + }).get()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntSupplier_complete() { + var collector = new FilteredExceptionCollector(false); + IntSupplier lambda = mock(IntSupplier.class); + when(lambda.getAsInt()).thenReturn(2); + assertEquals(2, collector.fromIntSupplier(lambda).getAsInt()); + verify(lambda, only()).getAsInt(); + assertTrue(collector.empty()); + } + @Test + public void fromIntSupplier_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromIntSupplier(() -> { + throw new NumberFormatException(); + }).getAsInt()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntSupplier_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromIntSupplier(() -> { + throw new NumberFormatException(); + }).getAsInt()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongSupplier_complete() { + var collector = new FilteredExceptionCollector(false); + LongSupplier lambda = mock(LongSupplier.class); + when(lambda.getAsLong()).thenReturn(2L); + assertEquals(2L, collector.fromLongSupplier(lambda).getAsLong()); + verify(lambda, only()).getAsLong(); + assertTrue(collector.empty()); + } + @Test + public void fromLongSupplier_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromLongSupplier(() -> { + throw new NumberFormatException(); + }).getAsLong()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongSupplier_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromLongSupplier(() -> { + throw new NumberFormatException(); + }).getAsLong()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleSupplier_complete() { + var collector = new FilteredExceptionCollector(false); + DoubleSupplier lambda = mock(DoubleSupplier.class); + when(lambda.getAsDouble()).thenReturn(2.0); + assertEquals(2.0, collector.fromDoubleSupplier(lambda).getAsDouble()); + verify(lambda, only()).getAsDouble(); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleSupplier_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromDoubleSupplier(() -> { + throw new NumberFormatException(); + }).getAsDouble()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleSupplier_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromDoubleSupplier(() -> { + throw new NumberFormatException(); + }).getAsDouble()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBooleanSupplier_complete() { + var collector = new FilteredExceptionCollector(false); + BooleanSupplier lambda = mock(BooleanSupplier.class); + when(lambda.getAsBoolean()).thenReturn(true); + assertEquals(true, collector.fromBooleanSupplier(lambda).getAsBoolean()); + verify(lambda, only()).getAsBoolean(); + assertTrue(collector.empty()); + } + @Test + public void fromBooleanSupplier_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromBooleanSupplier(() -> { + throw new NumberFormatException(); + }).getAsBoolean()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBooleanSupplier_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromBooleanSupplier(() -> { + throw new NumberFormatException(); + }).getAsBoolean()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void consumer_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") Consumer lambda = mock(Consumer.class); + collector.consumer(lambda).accept("input"); + verify(lambda, only()).accept("input"); + assertTrue(collector.empty()); + } + @Test + public void consumer_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.consumer(t -> { + throw new NumberFormatException(); + }).accept("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void consumer_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.consumer(t -> { + throw new NumberFormatException(); + }).accept("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntConsumer_complete() { + var collector = new FilteredExceptionCollector(false); + IntConsumer lambda = mock(IntConsumer.class); + collector.fromIntConsumer(lambda).accept(1); + verify(lambda, only()).accept(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntConsumer_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromIntConsumer(v -> { + throw new NumberFormatException(); + }).accept(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntConsumer_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromIntConsumer(v -> { + throw new NumberFormatException(); + }).accept(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongConsumer_complete() { + var collector = new FilteredExceptionCollector(false); + LongConsumer lambda = mock(LongConsumer.class); + collector.fromLongConsumer(lambda).accept(1L); + verify(lambda, only()).accept(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongConsumer_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromLongConsumer(v -> { + throw new NumberFormatException(); + }).accept(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongConsumer_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromLongConsumer(v -> { + throw new NumberFormatException(); + }).accept(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleConsumer_complete() { + var collector = new FilteredExceptionCollector(false); + DoubleConsumer lambda = mock(DoubleConsumer.class); + collector.fromDoubleConsumer(lambda).accept(1.0); + verify(lambda, only()).accept(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleConsumer_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromDoubleConsumer(v -> { + throw new NumberFormatException(); + }).accept(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleConsumer_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromDoubleConsumer(v -> { + throw new NumberFormatException(); + }).accept(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBiConsumer_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") BiConsumer lambda = mock(BiConsumer.class); + collector.fromBiConsumer(lambda).accept("input1", "input2"); + verify(lambda, only()).accept("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromBiConsumer_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromBiConsumer((t, u) -> { + throw new NumberFormatException(); + }).accept("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBiConsumer_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromBiConsumer((t, u) -> { + throw new NumberFormatException(); + }).accept("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromObjIntConsumer_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") ObjIntConsumer lambda = mock(ObjIntConsumer.class); + collector.fromObjIntConsumer(lambda).accept("input", 1); + verify(lambda, only()).accept("input", 1); + assertTrue(collector.empty()); + } + @Test + public void fromObjIntConsumer_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromObjIntConsumer((t, v) -> { + throw new NumberFormatException(); + }).accept("input", 1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromObjIntConsumer_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromObjIntConsumer((t, v) -> { + throw new NumberFormatException(); + }).accept("input", 1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromObjLongConsumer_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") ObjLongConsumer lambda = mock(ObjLongConsumer.class); + collector.fromObjLongConsumer(lambda).accept("input", 1L); + verify(lambda, only()).accept("input", 1L); + assertTrue(collector.empty()); + } + @Test + public void fromObjLongConsumer_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromObjLongConsumer((t, v) -> { + throw new NumberFormatException(); + }).accept("input", 1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromObjLongConsumer_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromObjLongConsumer((t, v) -> { + throw new NumberFormatException(); + }).accept("input", 1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromObjDoubleConsumer_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") ObjDoubleConsumer lambda = mock(ObjDoubleConsumer.class); + collector.fromObjDoubleConsumer(lambda).accept("input", 1.0); + verify(lambda, only()).accept("input", 1.0); + assertTrue(collector.empty()); + } + @Test + public void fromObjDoubleConsumer_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromObjDoubleConsumer((t, v) -> { + throw new NumberFormatException(); + }).accept("input", 1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromObjDoubleConsumer_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromObjDoubleConsumer((t, v) -> { + throw new NumberFormatException(); + }).accept("input", 1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void predicate_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") Predicate lambda = mock(Predicate.class); + when(lambda.test("input")).thenReturn(true); + assertEquals(true, collector.predicate(lambda).test("input")); + verify(lambda, only()).test("input"); + assertTrue(collector.empty()); + } + @Test + public void predicate_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.predicate(t -> { + throw new NumberFormatException(); + }).test("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void predicate_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.predicate(t -> { + throw new NumberFormatException(); + }).test("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntPredicate_complete() { + var collector = new FilteredExceptionCollector(false); + IntPredicate lambda = mock(IntPredicate.class); + when(lambda.test(1)).thenReturn(true); + assertEquals(true, collector.fromIntPredicate(lambda).test(1)); + verify(lambda, only()).test(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntPredicate_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromIntPredicate(v -> { + throw new NumberFormatException(); + }).test(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntPredicate_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromIntPredicate(v -> { + throw new NumberFormatException(); + }).test(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongPredicate_complete() { + var collector = new FilteredExceptionCollector(false); + LongPredicate lambda = mock(LongPredicate.class); + when(lambda.test(1L)).thenReturn(true); + assertEquals(true, collector.fromLongPredicate(lambda).test(1L)); + verify(lambda, only()).test(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongPredicate_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromLongPredicate(v -> { + throw new NumberFormatException(); + }).test(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongPredicate_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromLongPredicate(v -> { + throw new NumberFormatException(); + }).test(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoublePredicate_complete() { + var collector = new FilteredExceptionCollector(false); + DoublePredicate lambda = mock(DoublePredicate.class); + when(lambda.test(1.0)).thenReturn(true); + assertEquals(true, collector.fromDoublePredicate(lambda).test(1.0)); + verify(lambda, only()).test(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoublePredicate_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromDoublePredicate(v -> { + throw new NumberFormatException(); + }).test(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoublePredicate_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromDoublePredicate(v -> { + throw new NumberFormatException(); + }).test(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBiPredicate_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") BiPredicate lambda = mock(BiPredicate.class); + when(lambda.test("input1", "input2")).thenReturn(true); + assertEquals(true, collector.fromBiPredicate(lambda).test("input1", "input2")); + verify(lambda, only()).test("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromBiPredicate_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromBiPredicate((t, u) -> { + throw new NumberFormatException(); + }).test("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBiPredicate_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromBiPredicate((t, u) -> { + throw new NumberFormatException(); + }).test("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void function_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") Function lambda = mock(Function.class); + when(lambda.apply("input")).thenReturn("value"); + assertEquals("value", collector.function(lambda).apply("input")); + verify(lambda, only()).apply("input"); + assertTrue(collector.empty()); + } + @Test + public void function_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.function(t -> { + throw new NumberFormatException(); + }).apply("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void function_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.function(t -> { + throw new NumberFormatException(); + }).apply("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToIntFunction_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") ToIntFunction lambda = mock(ToIntFunction.class); + when(lambda.applyAsInt("input")).thenReturn(2); + assertEquals(2, collector.fromToIntFunction(lambda).applyAsInt("input")); + verify(lambda, only()).applyAsInt("input"); + assertTrue(collector.empty()); + } + @Test + public void fromToIntFunction_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromToIntFunction(v -> { + throw new NumberFormatException(); + }).applyAsInt("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToIntFunction_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromToIntFunction(v -> { + throw new NumberFormatException(); + }).applyAsInt("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntFunction_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") IntFunction lambda = mock(IntFunction.class); + when(lambda.apply(1)).thenReturn("value"); + assertEquals("value", collector.fromIntFunction(lambda).apply(1)); + verify(lambda, only()).apply(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntFunction_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromIntFunction(v -> { + throw new NumberFormatException(); + }).apply(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntFunction_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromIntFunction(v -> { + throw new NumberFormatException(); + }).apply(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntToLongFunction_complete() { + var collector = new FilteredExceptionCollector(false); + IntToLongFunction lambda = mock(IntToLongFunction.class); + when(lambda.applyAsLong(1)).thenReturn(2L); + assertEquals(2L, collector.fromIntToLongFunction(lambda).applyAsLong(1)); + verify(lambda, only()).applyAsLong(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntToLongFunction_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromIntToLongFunction(v -> { + throw new NumberFormatException(); + }).applyAsLong(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntToLongFunction_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromIntToLongFunction(v -> { + throw new NumberFormatException(); + }).applyAsLong(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntToDoubleFunction_complete() { + var collector = new FilteredExceptionCollector(false); + IntToDoubleFunction lambda = mock(IntToDoubleFunction.class); + when(lambda.applyAsDouble(1)).thenReturn(2.0); + assertEquals(2.0, collector.fromIntToDoubleFunction(lambda).applyAsDouble(1)); + verify(lambda, only()).applyAsDouble(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntToDoubleFunction_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromIntToDoubleFunction(v -> { + throw new NumberFormatException(); + }).applyAsDouble(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntToDoubleFunction_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromIntToDoubleFunction(v -> { + throw new NumberFormatException(); + }).applyAsDouble(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToLongFunction_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") ToLongFunction lambda = mock(ToLongFunction.class); + when(lambda.applyAsLong("input")).thenReturn(2L); + assertEquals(2L, collector.fromToLongFunction(lambda).applyAsLong("input")); + verify(lambda, only()).applyAsLong("input"); + assertTrue(collector.empty()); + } + @Test + public void fromToLongFunction_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromToLongFunction(v -> { + throw new NumberFormatException(); + }).applyAsLong("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToLongFunction_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromToLongFunction(v -> { + throw new NumberFormatException(); + }).applyAsLong("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongFunction_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") LongFunction lambda = mock(LongFunction.class); + when(lambda.apply(1L)).thenReturn("value"); + assertEquals("value", collector.fromLongFunction(lambda).apply(1L)); + verify(lambda, only()).apply(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongFunction_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromLongFunction(v -> { + throw new NumberFormatException(); + }).apply(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongFunction_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromLongFunction(v -> { + throw new NumberFormatException(); + }).apply(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongToIntFunction_complete() { + var collector = new FilteredExceptionCollector(false); + LongToIntFunction lambda = mock(LongToIntFunction.class); + when(lambda.applyAsInt(1L)).thenReturn(2); + assertEquals(2, collector.fromLongToIntFunction(lambda).applyAsInt(1L)); + verify(lambda, only()).applyAsInt(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongToIntFunction_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromLongToIntFunction(v -> { + throw new NumberFormatException(); + }).applyAsInt(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongToIntFunction_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromLongToIntFunction(v -> { + throw new NumberFormatException(); + }).applyAsInt(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongToDoubleFunction_complete() { + var collector = new FilteredExceptionCollector(false); + LongToDoubleFunction lambda = mock(LongToDoubleFunction.class); + when(lambda.applyAsDouble(1L)).thenReturn(2.0); + assertEquals(2.0, collector.fromLongToDoubleFunction(lambda).applyAsDouble(1L)); + verify(lambda, only()).applyAsDouble(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongToDoubleFunction_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromLongToDoubleFunction(v -> { + throw new NumberFormatException(); + }).applyAsDouble(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongToDoubleFunction_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromLongToDoubleFunction(v -> { + throw new NumberFormatException(); + }).applyAsDouble(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToDoubleFunction_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") ToDoubleFunction lambda = mock(ToDoubleFunction.class); + when(lambda.applyAsDouble("input")).thenReturn(2.0); + assertEquals(2.0, collector.fromToDoubleFunction(lambda).applyAsDouble("input")); + verify(lambda, only()).applyAsDouble("input"); + assertTrue(collector.empty()); + } + @Test + public void fromToDoubleFunction_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromToDoubleFunction(v -> { + throw new NumberFormatException(); + }).applyAsDouble("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToDoubleFunction_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromToDoubleFunction(v -> { + throw new NumberFormatException(); + }).applyAsDouble("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleFunction_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") DoubleFunction lambda = mock(DoubleFunction.class); + when(lambda.apply(1.0)).thenReturn("value"); + assertEquals("value", collector.fromDoubleFunction(lambda).apply(1.0)); + verify(lambda, only()).apply(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleFunction_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromDoubleFunction(v -> { + throw new NumberFormatException(); + }).apply(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleFunction_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromDoubleFunction(v -> { + throw new NumberFormatException(); + }).apply(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleToIntFunction_complete() { + var collector = new FilteredExceptionCollector(false); + DoubleToIntFunction lambda = mock(DoubleToIntFunction.class); + when(lambda.applyAsInt(1.0)).thenReturn(2); + assertEquals(2, collector.fromDoubleToIntFunction(lambda).applyAsInt(1.0)); + verify(lambda, only()).applyAsInt(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleToIntFunction_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromDoubleToIntFunction(v -> { + throw new NumberFormatException(); + }).applyAsInt(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleToIntFunction_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromDoubleToIntFunction(v -> { + throw new NumberFormatException(); + }).applyAsInt(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleToLongFunction_complete() { + var collector = new FilteredExceptionCollector(false); + DoubleToLongFunction lambda = mock(DoubleToLongFunction.class); + when(lambda.applyAsLong(1.0)).thenReturn(2L); + assertEquals(2L, collector.fromDoubleToLongFunction(lambda).applyAsLong(1.0)); + verify(lambda, only()).applyAsLong(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleToLongFunction_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromDoubleToLongFunction(v -> { + throw new NumberFormatException(); + }).applyAsLong(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleToLongFunction_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromDoubleToLongFunction(v -> { + throw new NumberFormatException(); + }).applyAsLong(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromUnaryOperator_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") UnaryOperator lambda = mock(UnaryOperator.class); + when(lambda.apply("input")).thenReturn("value"); + assertEquals("value", collector.fromUnaryOperator(lambda).apply("input")); + verify(lambda, only()).apply("input"); + assertTrue(collector.empty()); + } + @Test + public void fromUnaryOperator_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromUnaryOperator(o -> { + throw new NumberFormatException(); + }).apply("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromUnaryOperator_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromUnaryOperator(o -> { + throw new NumberFormatException(); + }).apply("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntUnaryOperator_complete() { + var collector = new FilteredExceptionCollector(false); + IntUnaryOperator lambda = mock(IntUnaryOperator.class); + when(lambda.applyAsInt(1)).thenReturn(2); + assertEquals(2, collector.fromIntUnaryOperator(lambda).applyAsInt(1)); + verify(lambda, only()).applyAsInt(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntUnaryOperator_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromIntUnaryOperator(o -> { + throw new NumberFormatException(); + }).applyAsInt(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntUnaryOperator_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromIntUnaryOperator(o -> { + throw new NumberFormatException(); + }).applyAsInt(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongUnaryOperator_complete() { + var collector = new FilteredExceptionCollector(false); + LongUnaryOperator lambda = mock(LongUnaryOperator.class); + when(lambda.applyAsLong(1L)).thenReturn(2L); + assertEquals(2L, collector.fromLongUnaryOperator(lambda).applyAsLong(1L)); + verify(lambda, only()).applyAsLong(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongUnaryOperator_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromLongUnaryOperator(o -> { + throw new NumberFormatException(); + }).applyAsLong(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongUnaryOperator_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromLongUnaryOperator(o -> { + throw new NumberFormatException(); + }).applyAsLong(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleUnaryOperator_complete() { + var collector = new FilteredExceptionCollector(false); + DoubleUnaryOperator lambda = mock(DoubleUnaryOperator.class); + when(lambda.applyAsDouble(1.0)).thenReturn(2.0); + assertEquals(2.0, collector.fromDoubleUnaryOperator(lambda).applyAsDouble(1.0)); + verify(lambda, only()).applyAsDouble(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleUnaryOperator_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromDoubleUnaryOperator(o -> { + throw new NumberFormatException(); + }).applyAsDouble(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleUnaryOperator_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromDoubleUnaryOperator(o -> { + throw new NumberFormatException(); + }).applyAsDouble(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBiFunction_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") BiFunction lambda = mock(BiFunction.class); + when(lambda.apply("input1", "input2")).thenReturn("value"); + assertEquals("value", collector.fromBiFunction(lambda).apply("input1", "input2")); + verify(lambda, only()).apply("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromBiFunction_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromBiFunction((t, u) -> { + throw new NumberFormatException(); + }).apply("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBiFunction_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromBiFunction((t, u) -> { + throw new NumberFormatException(); + }).apply("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToIntBiFunction_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") ToIntBiFunction lambda = mock(ToIntBiFunction.class); + when(lambda.applyAsInt("input1", "input2")).thenReturn(2); + assertEquals(2, collector.fromToIntBiFunction(lambda).applyAsInt("input1", "input2")); + verify(lambda, only()).applyAsInt("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromToIntBiFunction_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromToIntBiFunction((t, u) -> { + throw new NumberFormatException(); + }).applyAsInt("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToIntBiFunction_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromToIntBiFunction((t, u) -> { + throw new NumberFormatException(); + }).applyAsInt("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToLongBiFunction_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") ToLongBiFunction lambda = mock(ToLongBiFunction.class); + when(lambda.applyAsLong("input1", "input2")).thenReturn(2L); + assertEquals(2L, collector.fromToLongBiFunction(lambda).applyAsLong("input1", "input2")); + verify(lambda, only()).applyAsLong("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromToLongBiFunction_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromToLongBiFunction((t, u) -> { + throw new NumberFormatException(); + }).applyAsLong("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToLongBiFunction_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromToLongBiFunction((t, u) -> { + throw new NumberFormatException(); + }).applyAsLong("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToDoubleBiFunction_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") ToDoubleBiFunction lambda = mock(ToDoubleBiFunction.class); + when(lambda.applyAsDouble("input1", "input2")).thenReturn(2.0); + assertEquals(2.0, collector.fromToDoubleBiFunction(lambda).applyAsDouble("input1", "input2")); + verify(lambda, only()).applyAsDouble("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromToDoubleBiFunction_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromToDoubleBiFunction((t, u) -> { + throw new NumberFormatException(); + }).applyAsDouble("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToDoubleBiFunction_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromToDoubleBiFunction((t, u) -> { + throw new NumberFormatException(); + }).applyAsDouble("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBinaryOperator_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") BinaryOperator lambda = mock(BinaryOperator.class); + when(lambda.apply("input1", "input2")).thenReturn("value"); + assertEquals("value", collector.fromBinaryOperator(lambda).apply("input1", "input2")); + verify(lambda, only()).apply("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromBinaryOperator_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).apply("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBinaryOperator_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).apply("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntBinaryOperator_complete() { + var collector = new FilteredExceptionCollector(false); + IntBinaryOperator lambda = mock(IntBinaryOperator.class); + when(lambda.applyAsInt(11, 12)).thenReturn(2); + assertEquals(2, collector.fromIntBinaryOperator(lambda).applyAsInt(11, 12)); + verify(lambda, only()).applyAsInt(11, 12); + assertTrue(collector.empty()); + } + @Test + public void fromIntBinaryOperator_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromIntBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).applyAsInt(11, 12)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntBinaryOperator_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromIntBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).applyAsInt(11, 12)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongBinaryOperator_complete() { + var collector = new FilteredExceptionCollector(false); + LongBinaryOperator lambda = mock(LongBinaryOperator.class); + when(lambda.applyAsLong(11L, 12L)).thenReturn(2L); + assertEquals(2L, collector.fromLongBinaryOperator(lambda).applyAsLong(11L, 12L)); + verify(lambda, only()).applyAsLong(11L, 12L); + assertTrue(collector.empty()); + } + @Test + public void fromLongBinaryOperator_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromLongBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).applyAsLong(11L, 12L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongBinaryOperator_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromLongBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).applyAsLong(11L, 12L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleBinaryOperator_complete() { + var collector = new FilteredExceptionCollector(false); + DoubleBinaryOperator lambda = mock(DoubleBinaryOperator.class); + when(lambda.applyAsDouble(1.1, 1.2)).thenReturn(2.0); + assertEquals(2.0, collector.fromDoubleBinaryOperator(lambda).applyAsDouble(1.1, 1.2)); + verify(lambda, only()).applyAsDouble(1.1, 1.2); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleBinaryOperator_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromDoubleBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).applyAsDouble(1.1, 1.2)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleBinaryOperator_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.fromDoubleBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).applyAsDouble(1.1, 1.2)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void comparator_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") Comparator lambda = mock(Comparator.class); + when(lambda.compare("input1", "input2")).thenReturn(2); + assertEquals(2, collector.comparator(lambda).compare("input1", "input2")); + verify(lambda, only()).compare("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void comparator_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.comparator((l, r) -> { + throw new NumberFormatException(); + }).compare("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void comparator_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.comparator((l, r) -> { + throw new NumberFormatException(); + }).compare("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void closeable_complete() { + var collector = new FilteredExceptionCollector(false); + CloseableScope lambda = mock(CloseableScope.class); + collector.closeable(lambda).close(); + verify(lambda, only()).close(); + assertTrue(collector.empty()); + } + @Test + public void closeable_rethrow() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.closeable(() -> { + throw new NumberFormatException(); + }).close()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void closeable_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.closeable(() -> { + throw new NumberFormatException(); + }).close()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void run_complete() { + var collector = new FilteredExceptionCollector(false); + Runnable lambda = mock(Runnable.class); + collector.run(lambda); + verify(lambda, only()).run(); + assertTrue(collector.empty()); + } + @Test + public void run_pass() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.run(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void run_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.run(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void get_complete() { + var collector = new FilteredExceptionCollector(false); + @SuppressWarnings("unchecked") Supplier lambda = mock(Supplier.class); + when(lambda.get()).thenReturn("value"); + assertEquals("value", collector.get(lambda)); + verify(lambda, only()).get(); + assertTrue(collector.empty()); + } + @Test + public void get_pass() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.get(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void get_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.get(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void getAsInt_complete() { + var collector = new FilteredExceptionCollector(false); + IntSupplier lambda = mock(IntSupplier.class); + when(lambda.getAsInt()).thenReturn(2); + assertEquals(2, collector.getAsInt(lambda)); + verify(lambda, only()).getAsInt(); + assertTrue(collector.empty()); + } + @Test + public void getAsInt_pass() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.getAsInt(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void getAsInt_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.getAsInt(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void getAsLong_complete() { + var collector = new FilteredExceptionCollector(false); + LongSupplier lambda = mock(LongSupplier.class); + when(lambda.getAsLong()).thenReturn(2L); + assertEquals(2L, collector.getAsLong(lambda)); + verify(lambda, only()).getAsLong(); + assertTrue(collector.empty()); + } + @Test + public void getAsLong_pass() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.getAsLong(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void getAsLong_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.getAsLong(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void getAsDouble_complete() { + var collector = new FilteredExceptionCollector(false); + DoubleSupplier lambda = mock(DoubleSupplier.class); + when(lambda.getAsDouble()).thenReturn(2.0); + assertEquals(2.0, collector.getAsDouble(lambda)); + verify(lambda, only()).getAsDouble(); + assertTrue(collector.empty()); + } + @Test + public void getAsDouble_pass() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.getAsDouble(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void getAsDouble_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.getAsDouble(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void getAsBoolean_complete() { + var collector = new FilteredExceptionCollector(false); + BooleanSupplier lambda = mock(BooleanSupplier.class); + when(lambda.getAsBoolean()).thenReturn(true); + assertEquals(true, collector.getAsBoolean(lambda)); + verify(lambda, only()).getAsBoolean(); + assertTrue(collector.empty()); + } + @Test + public void getAsBoolean_pass() { + var collector = new FilteredExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.getAsBoolean(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void getAsBoolean_replace() { + var collector = new FilteredExceptionCollector(true); + assertThrows(CollectedException.class, () -> collector.getAsBoolean(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } } diff --git a/src/test/java/com/machinezoo/noexception/ExceptionHandlerTest.java b/src/test/java/com/machinezoo/noexception/ExceptionHandlerTest.java index 6f7fa8d..35dfdc8 100644 --- a/src/test/java/com/machinezoo/noexception/ExceptionHandlerTest.java +++ b/src/test/java/com/machinezoo/noexception/ExceptionHandlerTest.java @@ -13,1293 +13,1293 @@ import com.machinezoo.noexception.optional.*; public class ExceptionHandlerTest { - @Test - public void runnable_complete() { - var collector = new ExceptionCollector(true); - Runnable lambda = mock(Runnable.class); - collector.runnable(lambda).run(); - verify(lambda, only()).run(); - assertTrue(collector.empty()); - } - @Test - public void runnable_swallowException() { - var collector = new ExceptionCollector(true); - collector.runnable(() -> { - throw new NumberFormatException(); - }).run(); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void runnable_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.runnable(() -> { - throw new NumberFormatException(); - }).run()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void supplier_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") Supplier lambda = mock(Supplier.class); - when(lambda.get()).thenReturn("value"); - assertEquals(Optional.of("value"), collector.supplier(lambda).get()); - verify(lambda, only()).get(); - assertTrue(collector.empty()); - } - @Test - public void supplier_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(Optional.empty(), collector.supplier(() -> { - throw new NumberFormatException(); - }).get()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void supplier_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.supplier(() -> { - throw new NumberFormatException(); - }).get()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntSupplier_complete() { - var collector = new ExceptionCollector(true); - IntSupplier lambda = mock(IntSupplier.class); - when(lambda.getAsInt()).thenReturn(2); - assertEquals(OptionalInt.of(2), collector.fromIntSupplier(lambda).get()); - verify(lambda, only()).getAsInt(); - assertTrue(collector.empty()); - } - @Test - public void fromIntSupplier_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalInt.empty(), collector.fromIntSupplier(() -> { - throw new NumberFormatException(); - }).get()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntSupplier_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromIntSupplier(() -> { - throw new NumberFormatException(); - }).get()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongSupplier_complete() { - var collector = new ExceptionCollector(true); - LongSupplier lambda = mock(LongSupplier.class); - when(lambda.getAsLong()).thenReturn(2L); - assertEquals(OptionalLong.of(2L), collector.fromLongSupplier(lambda).get()); - verify(lambda, only()).getAsLong(); - assertTrue(collector.empty()); - } - @Test - public void fromLongSupplier_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalLong.empty(), collector.fromLongSupplier(() -> { - throw new NumberFormatException(); - }).get()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongSupplier_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromLongSupplier(() -> { - throw new NumberFormatException(); - }).get()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleSupplier_complete() { - var collector = new ExceptionCollector(true); - DoubleSupplier lambda = mock(DoubleSupplier.class); - when(lambda.getAsDouble()).thenReturn(2.0); - assertEquals(OptionalDouble.of(2.0), collector.fromDoubleSupplier(lambda).get()); - verify(lambda, only()).getAsDouble(); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleSupplier_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalDouble.empty(), collector.fromDoubleSupplier(() -> { - throw new NumberFormatException(); - }).get()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleSupplier_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromDoubleSupplier(() -> { - throw new NumberFormatException(); - }).get()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBooleanSupplier_complete() { - var collector = new ExceptionCollector(true); - BooleanSupplier lambda = mock(BooleanSupplier.class); - when(lambda.getAsBoolean()).thenReturn(true); - assertEquals(OptionalBoolean.of(true), collector.fromBooleanSupplier(lambda).get()); - verify(lambda, only()).getAsBoolean(); - assertTrue(collector.empty()); - } - @Test - public void fromBooleanSupplier_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalBoolean.empty(), collector.fromBooleanSupplier(() -> { - throw new NumberFormatException(); - }).get()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBooleanSupplier_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromBooleanSupplier(() -> { - throw new NumberFormatException(); - }).get()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void consumer_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") Consumer lambda = mock(Consumer.class); - collector.consumer(lambda).accept("input"); - verify(lambda, only()).accept("input"); - assertTrue(collector.empty()); - } - @Test - public void consumer_swallowException() { - var collector = new ExceptionCollector(true); - collector.consumer(t -> { - throw new NumberFormatException(); - }).accept("input"); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void consumer_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.consumer(t -> { - throw new NumberFormatException(); - }).accept("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntConsumer_complete() { - var collector = new ExceptionCollector(true); - IntConsumer lambda = mock(IntConsumer.class); - collector.fromIntConsumer(lambda).accept(1); - verify(lambda, only()).accept(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntConsumer_swallowException() { - var collector = new ExceptionCollector(true); - collector.fromIntConsumer(v -> { - throw new NumberFormatException(); - }).accept(1); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntConsumer_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromIntConsumer(v -> { - throw new NumberFormatException(); - }).accept(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongConsumer_complete() { - var collector = new ExceptionCollector(true); - LongConsumer lambda = mock(LongConsumer.class); - collector.fromLongConsumer(lambda).accept(1L); - verify(lambda, only()).accept(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongConsumer_swallowException() { - var collector = new ExceptionCollector(true); - collector.fromLongConsumer(v -> { - throw new NumberFormatException(); - }).accept(1L); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongConsumer_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromLongConsumer(v -> { - throw new NumberFormatException(); - }).accept(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleConsumer_complete() { - var collector = new ExceptionCollector(true); - DoubleConsumer lambda = mock(DoubleConsumer.class); - collector.fromDoubleConsumer(lambda).accept(1.0); - verify(lambda, only()).accept(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleConsumer_swallowException() { - var collector = new ExceptionCollector(true); - collector.fromDoubleConsumer(v -> { - throw new NumberFormatException(); - }).accept(1.0); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleConsumer_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromDoubleConsumer(v -> { - throw new NumberFormatException(); - }).accept(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBiConsumer_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") BiConsumer lambda = mock(BiConsumer.class); - collector.fromBiConsumer(lambda).accept("input1", "input2"); - verify(lambda, only()).accept("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromBiConsumer_swallowException() { - var collector = new ExceptionCollector(true); - collector.fromBiConsumer((t, u) -> { - throw new NumberFormatException(); - }).accept("input1", "input2"); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBiConsumer_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromBiConsumer((t, u) -> { - throw new NumberFormatException(); - }).accept("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromObjIntConsumer_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") ObjIntConsumer lambda = mock(ObjIntConsumer.class); - collector.fromObjIntConsumer(lambda).accept("input", 1); - verify(lambda, only()).accept("input", 1); - assertTrue(collector.empty()); - } - @Test - public void fromObjIntConsumer_swallowException() { - var collector = new ExceptionCollector(true); - collector.fromObjIntConsumer((t, v) -> { - throw new NumberFormatException(); - }).accept("input", 1); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromObjIntConsumer_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromObjIntConsumer((t, v) -> { - throw new NumberFormatException(); - }).accept("input", 1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromObjLongConsumer_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") ObjLongConsumer lambda = mock(ObjLongConsumer.class); - collector.fromObjLongConsumer(lambda).accept("input", 1L); - verify(lambda, only()).accept("input", 1L); - assertTrue(collector.empty()); - } - @Test - public void fromObjLongConsumer_swallowException() { - var collector = new ExceptionCollector(true); - collector.fromObjLongConsumer((t, v) -> { - throw new NumberFormatException(); - }).accept("input", 1L); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromObjLongConsumer_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromObjLongConsumer((t, v) -> { - throw new NumberFormatException(); - }).accept("input", 1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromObjDoubleConsumer_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") ObjDoubleConsumer lambda = mock(ObjDoubleConsumer.class); - collector.fromObjDoubleConsumer(lambda).accept("input", 1.0); - verify(lambda, only()).accept("input", 1.0); - assertTrue(collector.empty()); - } - @Test - public void fromObjDoubleConsumer_swallowException() { - var collector = new ExceptionCollector(true); - collector.fromObjDoubleConsumer((t, v) -> { - throw new NumberFormatException(); - }).accept("input", 1.0); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromObjDoubleConsumer_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromObjDoubleConsumer((t, v) -> { - throw new NumberFormatException(); - }).accept("input", 1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void predicate_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") Predicate lambda = mock(Predicate.class); - when(lambda.test("input")).thenReturn(true); - assertEquals(OptionalBoolean.of(true), collector.predicate(lambda).test("input")); - verify(lambda, only()).test("input"); - assertTrue(collector.empty()); - } - @Test - public void predicate_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalBoolean.empty(), collector.predicate(t -> { - throw new NumberFormatException(); - }).test("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void predicate_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.predicate(t -> { - throw new NumberFormatException(); - }).test("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntPredicate_complete() { - var collector = new ExceptionCollector(true); - IntPredicate lambda = mock(IntPredicate.class); - when(lambda.test(1)).thenReturn(true); - assertEquals(OptionalBoolean.of(true), collector.fromIntPredicate(lambda).test(1)); - verify(lambda, only()).test(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntPredicate_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalBoolean.empty(), collector.fromIntPredicate(v -> { - throw new NumberFormatException(); - }).test(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntPredicate_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromIntPredicate(v -> { - throw new NumberFormatException(); - }).test(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongPredicate_complete() { - var collector = new ExceptionCollector(true); - LongPredicate lambda = mock(LongPredicate.class); - when(lambda.test(1L)).thenReturn(true); - assertEquals(OptionalBoolean.of(true), collector.fromLongPredicate(lambda).test(1L)); - verify(lambda, only()).test(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongPredicate_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalBoolean.empty(), collector.fromLongPredicate(v -> { - throw new NumberFormatException(); - }).test(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongPredicate_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromLongPredicate(v -> { - throw new NumberFormatException(); - }).test(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoublePredicate_complete() { - var collector = new ExceptionCollector(true); - DoublePredicate lambda = mock(DoublePredicate.class); - when(lambda.test(1.0)).thenReturn(true); - assertEquals(OptionalBoolean.of(true), collector.fromDoublePredicate(lambda).test(1.0)); - verify(lambda, only()).test(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoublePredicate_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalBoolean.empty(), collector.fromDoublePredicate(v -> { - throw new NumberFormatException(); - }).test(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoublePredicate_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromDoublePredicate(v -> { - throw new NumberFormatException(); - }).test(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBiPredicate_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") BiPredicate lambda = mock(BiPredicate.class); - when(lambda.test("input1", "input2")).thenReturn(true); - assertEquals(OptionalBoolean.of(true), collector.fromBiPredicate(lambda).test("input1", "input2")); - verify(lambda, only()).test("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromBiPredicate_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalBoolean.empty(), collector.fromBiPredicate((t, u) -> { - throw new NumberFormatException(); - }).test("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBiPredicate_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromBiPredicate((t, u) -> { - throw new NumberFormatException(); - }).test("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void function_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") Function lambda = mock(Function.class); - when(lambda.apply("input")).thenReturn("value"); - assertEquals(Optional.of("value"), collector.function(lambda).apply("input")); - verify(lambda, only()).apply("input"); - assertTrue(collector.empty()); - } - @Test - public void function_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(Optional.empty(), collector.function(t -> { - throw new NumberFormatException(); - }).apply("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void function_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.function(t -> { - throw new NumberFormatException(); - }).apply("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToIntFunction_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") ToIntFunction lambda = mock(ToIntFunction.class); - when(lambda.applyAsInt("input")).thenReturn(2); - assertEquals(OptionalInt.of(2), collector.fromToIntFunction(lambda).apply("input")); - verify(lambda, only()).applyAsInt("input"); - assertTrue(collector.empty()); - } - @Test - public void fromToIntFunction_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalInt.empty(), collector.fromToIntFunction(v -> { - throw new NumberFormatException(); - }).apply("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToIntFunction_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromToIntFunction(v -> { - throw new NumberFormatException(); - }).apply("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntFunction_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") IntFunction lambda = mock(IntFunction.class); - when(lambda.apply(1)).thenReturn("value"); - assertEquals(Optional.of("value"), collector.fromIntFunction(lambda).apply(1)); - verify(lambda, only()).apply(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntFunction_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(Optional.empty(), collector.fromIntFunction(v -> { - throw new NumberFormatException(); - }).apply(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntFunction_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromIntFunction(v -> { - throw new NumberFormatException(); - }).apply(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntToLongFunction_complete() { - var collector = new ExceptionCollector(true); - IntToLongFunction lambda = mock(IntToLongFunction.class); - when(lambda.applyAsLong(1)).thenReturn(2L); - assertEquals(OptionalLong.of(2L), collector.fromIntToLongFunction(lambda).apply(1)); - verify(lambda, only()).applyAsLong(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntToLongFunction_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalLong.empty(), collector.fromIntToLongFunction(v -> { - throw new NumberFormatException(); - }).apply(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntToLongFunction_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromIntToLongFunction(v -> { - throw new NumberFormatException(); - }).apply(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntToDoubleFunction_complete() { - var collector = new ExceptionCollector(true); - IntToDoubleFunction lambda = mock(IntToDoubleFunction.class); - when(lambda.applyAsDouble(1)).thenReturn(2.0); - assertEquals(OptionalDouble.of(2.0), collector.fromIntToDoubleFunction(lambda).apply(1)); - verify(lambda, only()).applyAsDouble(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntToDoubleFunction_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalDouble.empty(), collector.fromIntToDoubleFunction(v -> { - throw new NumberFormatException(); - }).apply(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntToDoubleFunction_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromIntToDoubleFunction(v -> { - throw new NumberFormatException(); - }).apply(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToLongFunction_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") ToLongFunction lambda = mock(ToLongFunction.class); - when(lambda.applyAsLong("input")).thenReturn(2L); - assertEquals(OptionalLong.of(2L), collector.fromToLongFunction(lambda).apply("input")); - verify(lambda, only()).applyAsLong("input"); - assertTrue(collector.empty()); - } - @Test - public void fromToLongFunction_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalLong.empty(), collector.fromToLongFunction(v -> { - throw new NumberFormatException(); - }).apply("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToLongFunction_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromToLongFunction(v -> { - throw new NumberFormatException(); - }).apply("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongFunction_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") LongFunction lambda = mock(LongFunction.class); - when(lambda.apply(1L)).thenReturn("value"); - assertEquals(Optional.of("value"), collector.fromLongFunction(lambda).apply(1L)); - verify(lambda, only()).apply(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongFunction_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(Optional.empty(), collector.fromLongFunction(v -> { - throw new NumberFormatException(); - }).apply(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongFunction_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromLongFunction(v -> { - throw new NumberFormatException(); - }).apply(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongToIntFunction_complete() { - var collector = new ExceptionCollector(true); - LongToIntFunction lambda = mock(LongToIntFunction.class); - when(lambda.applyAsInt(1L)).thenReturn(2); - assertEquals(OptionalInt.of(2), collector.fromLongToIntFunction(lambda).apply(1L)); - verify(lambda, only()).applyAsInt(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongToIntFunction_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalInt.empty(), collector.fromLongToIntFunction(v -> { - throw new NumberFormatException(); - }).apply(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongToIntFunction_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromLongToIntFunction(v -> { - throw new NumberFormatException(); - }).apply(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongToDoubleFunction_complete() { - var collector = new ExceptionCollector(true); - LongToDoubleFunction lambda = mock(LongToDoubleFunction.class); - when(lambda.applyAsDouble(1L)).thenReturn(2.0); - assertEquals(OptionalDouble.of(2.0), collector.fromLongToDoubleFunction(lambda).apply(1L)); - verify(lambda, only()).applyAsDouble(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongToDoubleFunction_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalDouble.empty(), collector.fromLongToDoubleFunction(v -> { - throw new NumberFormatException(); - }).apply(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongToDoubleFunction_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromLongToDoubleFunction(v -> { - throw new NumberFormatException(); - }).apply(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToDoubleFunction_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") ToDoubleFunction lambda = mock(ToDoubleFunction.class); - when(lambda.applyAsDouble("input")).thenReturn(2.0); - assertEquals(OptionalDouble.of(2.0), collector.fromToDoubleFunction(lambda).apply("input")); - verify(lambda, only()).applyAsDouble("input"); - assertTrue(collector.empty()); - } - @Test - public void fromToDoubleFunction_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalDouble.empty(), collector.fromToDoubleFunction(v -> { - throw new NumberFormatException(); - }).apply("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToDoubleFunction_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromToDoubleFunction(v -> { - throw new NumberFormatException(); - }).apply("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleFunction_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") DoubleFunction lambda = mock(DoubleFunction.class); - when(lambda.apply(1.0)).thenReturn("value"); - assertEquals(Optional.of("value"), collector.fromDoubleFunction(lambda).apply(1.0)); - verify(lambda, only()).apply(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleFunction_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(Optional.empty(), collector.fromDoubleFunction(v -> { - throw new NumberFormatException(); - }).apply(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleFunction_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromDoubleFunction(v -> { - throw new NumberFormatException(); - }).apply(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleToIntFunction_complete() { - var collector = new ExceptionCollector(true); - DoubleToIntFunction lambda = mock(DoubleToIntFunction.class); - when(lambda.applyAsInt(1.0)).thenReturn(2); - assertEquals(OptionalInt.of(2), collector.fromDoubleToIntFunction(lambda).apply(1.0)); - verify(lambda, only()).applyAsInt(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleToIntFunction_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalInt.empty(), collector.fromDoubleToIntFunction(v -> { - throw new NumberFormatException(); - }).apply(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleToIntFunction_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromDoubleToIntFunction(v -> { - throw new NumberFormatException(); - }).apply(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleToLongFunction_complete() { - var collector = new ExceptionCollector(true); - DoubleToLongFunction lambda = mock(DoubleToLongFunction.class); - when(lambda.applyAsLong(1.0)).thenReturn(2L); - assertEquals(OptionalLong.of(2L), collector.fromDoubleToLongFunction(lambda).apply(1.0)); - verify(lambda, only()).applyAsLong(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleToLongFunction_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalLong.empty(), collector.fromDoubleToLongFunction(v -> { - throw new NumberFormatException(); - }).apply(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleToLongFunction_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromDoubleToLongFunction(v -> { - throw new NumberFormatException(); - }).apply(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromUnaryOperator_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") UnaryOperator lambda = mock(UnaryOperator.class); - when(lambda.apply("input")).thenReturn("value"); - assertEquals(Optional.of("value"), collector.fromUnaryOperator(lambda).apply("input")); - verify(lambda, only()).apply("input"); - assertTrue(collector.empty()); - } - @Test - public void fromUnaryOperator_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(Optional.empty(), collector.fromUnaryOperator(o -> { - throw new NumberFormatException(); - }).apply("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromUnaryOperator_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromUnaryOperator(o -> { - throw new NumberFormatException(); - }).apply("input")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntUnaryOperator_complete() { - var collector = new ExceptionCollector(true); - IntUnaryOperator lambda = mock(IntUnaryOperator.class); - when(lambda.applyAsInt(1)).thenReturn(2); - assertEquals(OptionalInt.of(2), collector.fromIntUnaryOperator(lambda).apply(1)); - verify(lambda, only()).applyAsInt(1); - assertTrue(collector.empty()); - } - @Test - public void fromIntUnaryOperator_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalInt.empty(), collector.fromIntUnaryOperator(o -> { - throw new NumberFormatException(); - }).apply(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntUnaryOperator_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromIntUnaryOperator(o -> { - throw new NumberFormatException(); - }).apply(1)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongUnaryOperator_complete() { - var collector = new ExceptionCollector(true); - LongUnaryOperator lambda = mock(LongUnaryOperator.class); - when(lambda.applyAsLong(1L)).thenReturn(2L); - assertEquals(OptionalLong.of(2L), collector.fromLongUnaryOperator(lambda).apply(1L)); - verify(lambda, only()).applyAsLong(1L); - assertTrue(collector.empty()); - } - @Test - public void fromLongUnaryOperator_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalLong.empty(), collector.fromLongUnaryOperator(o -> { - throw new NumberFormatException(); - }).apply(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongUnaryOperator_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromLongUnaryOperator(o -> { - throw new NumberFormatException(); - }).apply(1L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleUnaryOperator_complete() { - var collector = new ExceptionCollector(true); - DoubleUnaryOperator lambda = mock(DoubleUnaryOperator.class); - when(lambda.applyAsDouble(1.0)).thenReturn(2.0); - assertEquals(OptionalDouble.of(2.0), collector.fromDoubleUnaryOperator(lambda).apply(1.0)); - verify(lambda, only()).applyAsDouble(1.0); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleUnaryOperator_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalDouble.empty(), collector.fromDoubleUnaryOperator(o -> { - throw new NumberFormatException(); - }).apply(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleUnaryOperator_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromDoubleUnaryOperator(o -> { - throw new NumberFormatException(); - }).apply(1.0)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBiFunction_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") BiFunction lambda = mock(BiFunction.class); - when(lambda.apply("input1", "input2")).thenReturn("value"); - assertEquals(Optional.of("value"), collector.fromBiFunction(lambda).apply("input1", "input2")); - verify(lambda, only()).apply("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromBiFunction_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(Optional.empty(), collector.fromBiFunction((t, u) -> { - throw new NumberFormatException(); - }).apply("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBiFunction_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromBiFunction((t, u) -> { - throw new NumberFormatException(); - }).apply("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToIntBiFunction_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") ToIntBiFunction lambda = mock(ToIntBiFunction.class); - when(lambda.applyAsInt("input1", "input2")).thenReturn(2); - assertEquals(OptionalInt.of(2), collector.fromToIntBiFunction(lambda).apply("input1", "input2")); - verify(lambda, only()).applyAsInt("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromToIntBiFunction_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalInt.empty(), collector.fromToIntBiFunction((t, u) -> { - throw new NumberFormatException(); - }).apply("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToIntBiFunction_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromToIntBiFunction((t, u) -> { - throw new NumberFormatException(); - }).apply("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToLongBiFunction_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") ToLongBiFunction lambda = mock(ToLongBiFunction.class); - when(lambda.applyAsLong("input1", "input2")).thenReturn(2L); - assertEquals(OptionalLong.of(2L), collector.fromToLongBiFunction(lambda).apply("input1", "input2")); - verify(lambda, only()).applyAsLong("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromToLongBiFunction_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalLong.empty(), collector.fromToLongBiFunction((t, u) -> { - throw new NumberFormatException(); - }).apply("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToLongBiFunction_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromToLongBiFunction((t, u) -> { - throw new NumberFormatException(); - }).apply("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToDoubleBiFunction_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") ToDoubleBiFunction lambda = mock(ToDoubleBiFunction.class); - when(lambda.applyAsDouble("input1", "input2")).thenReturn(2.0); - assertEquals(OptionalDouble.of(2.0), collector.fromToDoubleBiFunction(lambda).apply("input1", "input2")); - verify(lambda, only()).applyAsDouble("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromToDoubleBiFunction_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalDouble.empty(), collector.fromToDoubleBiFunction((t, u) -> { - throw new NumberFormatException(); - }).apply("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromToDoubleBiFunction_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromToDoubleBiFunction((t, u) -> { - throw new NumberFormatException(); - }).apply("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBinaryOperator_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") BinaryOperator lambda = mock(BinaryOperator.class); - when(lambda.apply("input1", "input2")).thenReturn("value"); - assertEquals(Optional.of("value"), collector.fromBinaryOperator(lambda).apply("input1", "input2")); - verify(lambda, only()).apply("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void fromBinaryOperator_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(Optional.empty(), collector.fromBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).apply("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromBinaryOperator_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).apply("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntBinaryOperator_complete() { - var collector = new ExceptionCollector(true); - IntBinaryOperator lambda = mock(IntBinaryOperator.class); - when(lambda.applyAsInt(11, 12)).thenReturn(2); - assertEquals(OptionalInt.of(2), collector.fromIntBinaryOperator(lambda).apply(11, 12)); - verify(lambda, only()).applyAsInt(11, 12); - assertTrue(collector.empty()); - } - @Test - public void fromIntBinaryOperator_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalInt.empty(), collector.fromIntBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).apply(11, 12)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromIntBinaryOperator_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromIntBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).apply(11, 12)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongBinaryOperator_complete() { - var collector = new ExceptionCollector(true); - LongBinaryOperator lambda = mock(LongBinaryOperator.class); - when(lambda.applyAsLong(11L, 12L)).thenReturn(2L); - assertEquals(OptionalLong.of(2L), collector.fromLongBinaryOperator(lambda).apply(11L, 12L)); - verify(lambda, only()).applyAsLong(11L, 12L); - assertTrue(collector.empty()); - } - @Test - public void fromLongBinaryOperator_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalLong.empty(), collector.fromLongBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).apply(11L, 12L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromLongBinaryOperator_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromLongBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).apply(11L, 12L)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleBinaryOperator_complete() { - var collector = new ExceptionCollector(true); - DoubleBinaryOperator lambda = mock(DoubleBinaryOperator.class); - when(lambda.applyAsDouble(1.1, 1.2)).thenReturn(2.0); - assertEquals(OptionalDouble.of(2.0), collector.fromDoubleBinaryOperator(lambda).apply(1.1, 1.2)); - verify(lambda, only()).applyAsDouble(1.1, 1.2); - assertTrue(collector.empty()); - } - @Test - public void fromDoubleBinaryOperator_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalDouble.empty(), collector.fromDoubleBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).apply(1.1, 1.2)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void fromDoubleBinaryOperator_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.fromDoubleBinaryOperator((l, r) -> { - throw new NumberFormatException(); - }).apply(1.1, 1.2)); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void comparator_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") Comparator lambda = mock(Comparator.class); - when(lambda.compare("input1", "input2")).thenReturn(2); - assertEquals(OptionalInt.of(2), collector.comparator(lambda).compare("input1", "input2")); - verify(lambda, only()).compare("input1", "input2"); - assertTrue(collector.empty()); - } - @Test - public void comparator_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalInt.empty(), collector.comparator((l, r) -> { - throw new NumberFormatException(); - }).compare("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void comparator_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.comparator((l, r) -> { - throw new NumberFormatException(); - }).compare("input1", "input2")); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void closeable_complete() { - var collector = new ExceptionCollector(true); - CloseableScope lambda = mock(CloseableScope.class); - collector.closeable(lambda).close(); - verify(lambda, only()).close(); - assertTrue(collector.empty()); - } - @Test - public void closeable_swallowException() { - var collector = new ExceptionCollector(true); - collector.closeable(() -> { - throw new NumberFormatException(); - }).close(); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void closeable_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.closeable(() -> { - throw new NumberFormatException(); - }).close()); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void run_complete() { - var collector = new ExceptionCollector(true); - Runnable lambda = mock(Runnable.class); - collector.run(lambda); - verify(lambda, only()).run(); - assertTrue(collector.empty()); - } - @Test - public void run_swallowException() { - var collector = new ExceptionCollector(true); - collector.run(() -> { - throw new NumberFormatException(); - }); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void run_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.run(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void get_complete() { - var collector = new ExceptionCollector(true); - @SuppressWarnings("unchecked") Supplier lambda = mock(Supplier.class); - when(lambda.get()).thenReturn("value"); - assertEquals(Optional.of("value"), collector.get(lambda)); - verify(lambda, only()).get(); - assertTrue(collector.empty()); - } - @Test - public void get_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(Optional.empty(), collector.get(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void get_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.get(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void getAsInt_complete() { - var collector = new ExceptionCollector(true); - IntSupplier lambda = mock(IntSupplier.class); - when(lambda.getAsInt()).thenReturn(2); - assertEquals(OptionalInt.of(2), collector.getAsInt(lambda)); - verify(lambda, only()).getAsInt(); - assertTrue(collector.empty()); - } - @Test - public void getAsInt_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalInt.empty(), collector.getAsInt(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void getAsInt_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.getAsInt(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void getAsLong_complete() { - var collector = new ExceptionCollector(true); - LongSupplier lambda = mock(LongSupplier.class); - when(lambda.getAsLong()).thenReturn(2L); - assertEquals(OptionalLong.of(2L), collector.getAsLong(lambda)); - verify(lambda, only()).getAsLong(); - assertTrue(collector.empty()); - } - @Test - public void getAsLong_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalLong.empty(), collector.getAsLong(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void getAsLong_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.getAsLong(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void getAsDouble_complete() { - var collector = new ExceptionCollector(true); - DoubleSupplier lambda = mock(DoubleSupplier.class); - when(lambda.getAsDouble()).thenReturn(2.0); - assertEquals(OptionalDouble.of(2.0), collector.getAsDouble(lambda)); - verify(lambda, only()).getAsDouble(); - assertTrue(collector.empty()); - } - @Test - public void getAsDouble_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalDouble.empty(), collector.getAsDouble(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void getAsDouble_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.getAsDouble(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void getAsBoolean_complete() { - var collector = new ExceptionCollector(true); - BooleanSupplier lambda = mock(BooleanSupplier.class); - when(lambda.getAsBoolean()).thenReturn(true); - assertEquals(OptionalBoolean.of(true), collector.getAsBoolean(lambda)); - verify(lambda, only()).getAsBoolean(); - assertTrue(collector.empty()); - } - @Test - public void getAsBoolean_swallowException() { - var collector = new ExceptionCollector(true); - assertEquals(OptionalBoolean.empty(), collector.getAsBoolean(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } - @Test - public void getAsBoolean_passException() { - var collector = new ExceptionCollector(false); - assertThrows(NumberFormatException.class, () -> collector.getAsBoolean(() -> { - throw new NumberFormatException(); - })); - assertThat(collector.single(), instanceOf(NumberFormatException.class)); - } + @Test + public void runnable_complete() { + var collector = new ExceptionCollector(true); + Runnable lambda = mock(Runnable.class); + collector.runnable(lambda).run(); + verify(lambda, only()).run(); + assertTrue(collector.empty()); + } + @Test + public void runnable_swallowException() { + var collector = new ExceptionCollector(true); + collector.runnable(() -> { + throw new NumberFormatException(); + }).run(); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void runnable_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.runnable(() -> { + throw new NumberFormatException(); + }).run()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void supplier_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") Supplier lambda = mock(Supplier.class); + when(lambda.get()).thenReturn("value"); + assertEquals(Optional.of("value"), collector.supplier(lambda).get()); + verify(lambda, only()).get(); + assertTrue(collector.empty()); + } + @Test + public void supplier_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(Optional.empty(), collector.supplier(() -> { + throw new NumberFormatException(); + }).get()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void supplier_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.supplier(() -> { + throw new NumberFormatException(); + }).get()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntSupplier_complete() { + var collector = new ExceptionCollector(true); + IntSupplier lambda = mock(IntSupplier.class); + when(lambda.getAsInt()).thenReturn(2); + assertEquals(OptionalInt.of(2), collector.fromIntSupplier(lambda).get()); + verify(lambda, only()).getAsInt(); + assertTrue(collector.empty()); + } + @Test + public void fromIntSupplier_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalInt.empty(), collector.fromIntSupplier(() -> { + throw new NumberFormatException(); + }).get()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntSupplier_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromIntSupplier(() -> { + throw new NumberFormatException(); + }).get()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongSupplier_complete() { + var collector = new ExceptionCollector(true); + LongSupplier lambda = mock(LongSupplier.class); + when(lambda.getAsLong()).thenReturn(2L); + assertEquals(OptionalLong.of(2L), collector.fromLongSupplier(lambda).get()); + verify(lambda, only()).getAsLong(); + assertTrue(collector.empty()); + } + @Test + public void fromLongSupplier_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalLong.empty(), collector.fromLongSupplier(() -> { + throw new NumberFormatException(); + }).get()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongSupplier_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromLongSupplier(() -> { + throw new NumberFormatException(); + }).get()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleSupplier_complete() { + var collector = new ExceptionCollector(true); + DoubleSupplier lambda = mock(DoubleSupplier.class); + when(lambda.getAsDouble()).thenReturn(2.0); + assertEquals(OptionalDouble.of(2.0), collector.fromDoubleSupplier(lambda).get()); + verify(lambda, only()).getAsDouble(); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleSupplier_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalDouble.empty(), collector.fromDoubleSupplier(() -> { + throw new NumberFormatException(); + }).get()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleSupplier_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromDoubleSupplier(() -> { + throw new NumberFormatException(); + }).get()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBooleanSupplier_complete() { + var collector = new ExceptionCollector(true); + BooleanSupplier lambda = mock(BooleanSupplier.class); + when(lambda.getAsBoolean()).thenReturn(true); + assertEquals(OptionalBoolean.of(true), collector.fromBooleanSupplier(lambda).get()); + verify(lambda, only()).getAsBoolean(); + assertTrue(collector.empty()); + } + @Test + public void fromBooleanSupplier_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalBoolean.empty(), collector.fromBooleanSupplier(() -> { + throw new NumberFormatException(); + }).get()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBooleanSupplier_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromBooleanSupplier(() -> { + throw new NumberFormatException(); + }).get()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void consumer_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") Consumer lambda = mock(Consumer.class); + collector.consumer(lambda).accept("input"); + verify(lambda, only()).accept("input"); + assertTrue(collector.empty()); + } + @Test + public void consumer_swallowException() { + var collector = new ExceptionCollector(true); + collector.consumer(t -> { + throw new NumberFormatException(); + }).accept("input"); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void consumer_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.consumer(t -> { + throw new NumberFormatException(); + }).accept("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntConsumer_complete() { + var collector = new ExceptionCollector(true); + IntConsumer lambda = mock(IntConsumer.class); + collector.fromIntConsumer(lambda).accept(1); + verify(lambda, only()).accept(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntConsumer_swallowException() { + var collector = new ExceptionCollector(true); + collector.fromIntConsumer(v -> { + throw new NumberFormatException(); + }).accept(1); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntConsumer_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromIntConsumer(v -> { + throw new NumberFormatException(); + }).accept(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongConsumer_complete() { + var collector = new ExceptionCollector(true); + LongConsumer lambda = mock(LongConsumer.class); + collector.fromLongConsumer(lambda).accept(1L); + verify(lambda, only()).accept(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongConsumer_swallowException() { + var collector = new ExceptionCollector(true); + collector.fromLongConsumer(v -> { + throw new NumberFormatException(); + }).accept(1L); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongConsumer_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromLongConsumer(v -> { + throw new NumberFormatException(); + }).accept(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleConsumer_complete() { + var collector = new ExceptionCollector(true); + DoubleConsumer lambda = mock(DoubleConsumer.class); + collector.fromDoubleConsumer(lambda).accept(1.0); + verify(lambda, only()).accept(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleConsumer_swallowException() { + var collector = new ExceptionCollector(true); + collector.fromDoubleConsumer(v -> { + throw new NumberFormatException(); + }).accept(1.0); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleConsumer_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromDoubleConsumer(v -> { + throw new NumberFormatException(); + }).accept(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBiConsumer_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") BiConsumer lambda = mock(BiConsumer.class); + collector.fromBiConsumer(lambda).accept("input1", "input2"); + verify(lambda, only()).accept("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromBiConsumer_swallowException() { + var collector = new ExceptionCollector(true); + collector.fromBiConsumer((t, u) -> { + throw new NumberFormatException(); + }).accept("input1", "input2"); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBiConsumer_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromBiConsumer((t, u) -> { + throw new NumberFormatException(); + }).accept("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromObjIntConsumer_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") ObjIntConsumer lambda = mock(ObjIntConsumer.class); + collector.fromObjIntConsumer(lambda).accept("input", 1); + verify(lambda, only()).accept("input", 1); + assertTrue(collector.empty()); + } + @Test + public void fromObjIntConsumer_swallowException() { + var collector = new ExceptionCollector(true); + collector.fromObjIntConsumer((t, v) -> { + throw new NumberFormatException(); + }).accept("input", 1); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromObjIntConsumer_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromObjIntConsumer((t, v) -> { + throw new NumberFormatException(); + }).accept("input", 1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromObjLongConsumer_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") ObjLongConsumer lambda = mock(ObjLongConsumer.class); + collector.fromObjLongConsumer(lambda).accept("input", 1L); + verify(lambda, only()).accept("input", 1L); + assertTrue(collector.empty()); + } + @Test + public void fromObjLongConsumer_swallowException() { + var collector = new ExceptionCollector(true); + collector.fromObjLongConsumer((t, v) -> { + throw new NumberFormatException(); + }).accept("input", 1L); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromObjLongConsumer_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromObjLongConsumer((t, v) -> { + throw new NumberFormatException(); + }).accept("input", 1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromObjDoubleConsumer_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") ObjDoubleConsumer lambda = mock(ObjDoubleConsumer.class); + collector.fromObjDoubleConsumer(lambda).accept("input", 1.0); + verify(lambda, only()).accept("input", 1.0); + assertTrue(collector.empty()); + } + @Test + public void fromObjDoubleConsumer_swallowException() { + var collector = new ExceptionCollector(true); + collector.fromObjDoubleConsumer((t, v) -> { + throw new NumberFormatException(); + }).accept("input", 1.0); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromObjDoubleConsumer_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromObjDoubleConsumer((t, v) -> { + throw new NumberFormatException(); + }).accept("input", 1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void predicate_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") Predicate lambda = mock(Predicate.class); + when(lambda.test("input")).thenReturn(true); + assertEquals(OptionalBoolean.of(true), collector.predicate(lambda).test("input")); + verify(lambda, only()).test("input"); + assertTrue(collector.empty()); + } + @Test + public void predicate_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalBoolean.empty(), collector.predicate(t -> { + throw new NumberFormatException(); + }).test("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void predicate_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.predicate(t -> { + throw new NumberFormatException(); + }).test("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntPredicate_complete() { + var collector = new ExceptionCollector(true); + IntPredicate lambda = mock(IntPredicate.class); + when(lambda.test(1)).thenReturn(true); + assertEquals(OptionalBoolean.of(true), collector.fromIntPredicate(lambda).test(1)); + verify(lambda, only()).test(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntPredicate_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalBoolean.empty(), collector.fromIntPredicate(v -> { + throw new NumberFormatException(); + }).test(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntPredicate_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromIntPredicate(v -> { + throw new NumberFormatException(); + }).test(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongPredicate_complete() { + var collector = new ExceptionCollector(true); + LongPredicate lambda = mock(LongPredicate.class); + when(lambda.test(1L)).thenReturn(true); + assertEquals(OptionalBoolean.of(true), collector.fromLongPredicate(lambda).test(1L)); + verify(lambda, only()).test(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongPredicate_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalBoolean.empty(), collector.fromLongPredicate(v -> { + throw new NumberFormatException(); + }).test(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongPredicate_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromLongPredicate(v -> { + throw new NumberFormatException(); + }).test(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoublePredicate_complete() { + var collector = new ExceptionCollector(true); + DoublePredicate lambda = mock(DoublePredicate.class); + when(lambda.test(1.0)).thenReturn(true); + assertEquals(OptionalBoolean.of(true), collector.fromDoublePredicate(lambda).test(1.0)); + verify(lambda, only()).test(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoublePredicate_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalBoolean.empty(), collector.fromDoublePredicate(v -> { + throw new NumberFormatException(); + }).test(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoublePredicate_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromDoublePredicate(v -> { + throw new NumberFormatException(); + }).test(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBiPredicate_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") BiPredicate lambda = mock(BiPredicate.class); + when(lambda.test("input1", "input2")).thenReturn(true); + assertEquals(OptionalBoolean.of(true), collector.fromBiPredicate(lambda).test("input1", "input2")); + verify(lambda, only()).test("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromBiPredicate_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalBoolean.empty(), collector.fromBiPredicate((t, u) -> { + throw new NumberFormatException(); + }).test("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBiPredicate_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromBiPredicate((t, u) -> { + throw new NumberFormatException(); + }).test("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void function_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") Function lambda = mock(Function.class); + when(lambda.apply("input")).thenReturn("value"); + assertEquals(Optional.of("value"), collector.function(lambda).apply("input")); + verify(lambda, only()).apply("input"); + assertTrue(collector.empty()); + } + @Test + public void function_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(Optional.empty(), collector.function(t -> { + throw new NumberFormatException(); + }).apply("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void function_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.function(t -> { + throw new NumberFormatException(); + }).apply("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToIntFunction_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") ToIntFunction lambda = mock(ToIntFunction.class); + when(lambda.applyAsInt("input")).thenReturn(2); + assertEquals(OptionalInt.of(2), collector.fromToIntFunction(lambda).apply("input")); + verify(lambda, only()).applyAsInt("input"); + assertTrue(collector.empty()); + } + @Test + public void fromToIntFunction_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalInt.empty(), collector.fromToIntFunction(v -> { + throw new NumberFormatException(); + }).apply("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToIntFunction_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromToIntFunction(v -> { + throw new NumberFormatException(); + }).apply("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntFunction_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") IntFunction lambda = mock(IntFunction.class); + when(lambda.apply(1)).thenReturn("value"); + assertEquals(Optional.of("value"), collector.fromIntFunction(lambda).apply(1)); + verify(lambda, only()).apply(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntFunction_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(Optional.empty(), collector.fromIntFunction(v -> { + throw new NumberFormatException(); + }).apply(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntFunction_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromIntFunction(v -> { + throw new NumberFormatException(); + }).apply(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntToLongFunction_complete() { + var collector = new ExceptionCollector(true); + IntToLongFunction lambda = mock(IntToLongFunction.class); + when(lambda.applyAsLong(1)).thenReturn(2L); + assertEquals(OptionalLong.of(2L), collector.fromIntToLongFunction(lambda).apply(1)); + verify(lambda, only()).applyAsLong(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntToLongFunction_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalLong.empty(), collector.fromIntToLongFunction(v -> { + throw new NumberFormatException(); + }).apply(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntToLongFunction_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromIntToLongFunction(v -> { + throw new NumberFormatException(); + }).apply(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntToDoubleFunction_complete() { + var collector = new ExceptionCollector(true); + IntToDoubleFunction lambda = mock(IntToDoubleFunction.class); + when(lambda.applyAsDouble(1)).thenReturn(2.0); + assertEquals(OptionalDouble.of(2.0), collector.fromIntToDoubleFunction(lambda).apply(1)); + verify(lambda, only()).applyAsDouble(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntToDoubleFunction_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalDouble.empty(), collector.fromIntToDoubleFunction(v -> { + throw new NumberFormatException(); + }).apply(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntToDoubleFunction_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromIntToDoubleFunction(v -> { + throw new NumberFormatException(); + }).apply(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToLongFunction_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") ToLongFunction lambda = mock(ToLongFunction.class); + when(lambda.applyAsLong("input")).thenReturn(2L); + assertEquals(OptionalLong.of(2L), collector.fromToLongFunction(lambda).apply("input")); + verify(lambda, only()).applyAsLong("input"); + assertTrue(collector.empty()); + } + @Test + public void fromToLongFunction_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalLong.empty(), collector.fromToLongFunction(v -> { + throw new NumberFormatException(); + }).apply("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToLongFunction_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromToLongFunction(v -> { + throw new NumberFormatException(); + }).apply("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongFunction_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") LongFunction lambda = mock(LongFunction.class); + when(lambda.apply(1L)).thenReturn("value"); + assertEquals(Optional.of("value"), collector.fromLongFunction(lambda).apply(1L)); + verify(lambda, only()).apply(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongFunction_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(Optional.empty(), collector.fromLongFunction(v -> { + throw new NumberFormatException(); + }).apply(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongFunction_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromLongFunction(v -> { + throw new NumberFormatException(); + }).apply(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongToIntFunction_complete() { + var collector = new ExceptionCollector(true); + LongToIntFunction lambda = mock(LongToIntFunction.class); + when(lambda.applyAsInt(1L)).thenReturn(2); + assertEquals(OptionalInt.of(2), collector.fromLongToIntFunction(lambda).apply(1L)); + verify(lambda, only()).applyAsInt(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongToIntFunction_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalInt.empty(), collector.fromLongToIntFunction(v -> { + throw new NumberFormatException(); + }).apply(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongToIntFunction_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromLongToIntFunction(v -> { + throw new NumberFormatException(); + }).apply(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongToDoubleFunction_complete() { + var collector = new ExceptionCollector(true); + LongToDoubleFunction lambda = mock(LongToDoubleFunction.class); + when(lambda.applyAsDouble(1L)).thenReturn(2.0); + assertEquals(OptionalDouble.of(2.0), collector.fromLongToDoubleFunction(lambda).apply(1L)); + verify(lambda, only()).applyAsDouble(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongToDoubleFunction_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalDouble.empty(), collector.fromLongToDoubleFunction(v -> { + throw new NumberFormatException(); + }).apply(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongToDoubleFunction_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromLongToDoubleFunction(v -> { + throw new NumberFormatException(); + }).apply(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToDoubleFunction_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") ToDoubleFunction lambda = mock(ToDoubleFunction.class); + when(lambda.applyAsDouble("input")).thenReturn(2.0); + assertEquals(OptionalDouble.of(2.0), collector.fromToDoubleFunction(lambda).apply("input")); + verify(lambda, only()).applyAsDouble("input"); + assertTrue(collector.empty()); + } + @Test + public void fromToDoubleFunction_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalDouble.empty(), collector.fromToDoubleFunction(v -> { + throw new NumberFormatException(); + }).apply("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToDoubleFunction_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromToDoubleFunction(v -> { + throw new NumberFormatException(); + }).apply("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleFunction_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") DoubleFunction lambda = mock(DoubleFunction.class); + when(lambda.apply(1.0)).thenReturn("value"); + assertEquals(Optional.of("value"), collector.fromDoubleFunction(lambda).apply(1.0)); + verify(lambda, only()).apply(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleFunction_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(Optional.empty(), collector.fromDoubleFunction(v -> { + throw new NumberFormatException(); + }).apply(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleFunction_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromDoubleFunction(v -> { + throw new NumberFormatException(); + }).apply(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleToIntFunction_complete() { + var collector = new ExceptionCollector(true); + DoubleToIntFunction lambda = mock(DoubleToIntFunction.class); + when(lambda.applyAsInt(1.0)).thenReturn(2); + assertEquals(OptionalInt.of(2), collector.fromDoubleToIntFunction(lambda).apply(1.0)); + verify(lambda, only()).applyAsInt(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleToIntFunction_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalInt.empty(), collector.fromDoubleToIntFunction(v -> { + throw new NumberFormatException(); + }).apply(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleToIntFunction_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromDoubleToIntFunction(v -> { + throw new NumberFormatException(); + }).apply(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleToLongFunction_complete() { + var collector = new ExceptionCollector(true); + DoubleToLongFunction lambda = mock(DoubleToLongFunction.class); + when(lambda.applyAsLong(1.0)).thenReturn(2L); + assertEquals(OptionalLong.of(2L), collector.fromDoubleToLongFunction(lambda).apply(1.0)); + verify(lambda, only()).applyAsLong(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleToLongFunction_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalLong.empty(), collector.fromDoubleToLongFunction(v -> { + throw new NumberFormatException(); + }).apply(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleToLongFunction_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromDoubleToLongFunction(v -> { + throw new NumberFormatException(); + }).apply(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromUnaryOperator_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") UnaryOperator lambda = mock(UnaryOperator.class); + when(lambda.apply("input")).thenReturn("value"); + assertEquals(Optional.of("value"), collector.fromUnaryOperator(lambda).apply("input")); + verify(lambda, only()).apply("input"); + assertTrue(collector.empty()); + } + @Test + public void fromUnaryOperator_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(Optional.empty(), collector.fromUnaryOperator(o -> { + throw new NumberFormatException(); + }).apply("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromUnaryOperator_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromUnaryOperator(o -> { + throw new NumberFormatException(); + }).apply("input")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntUnaryOperator_complete() { + var collector = new ExceptionCollector(true); + IntUnaryOperator lambda = mock(IntUnaryOperator.class); + when(lambda.applyAsInt(1)).thenReturn(2); + assertEquals(OptionalInt.of(2), collector.fromIntUnaryOperator(lambda).apply(1)); + verify(lambda, only()).applyAsInt(1); + assertTrue(collector.empty()); + } + @Test + public void fromIntUnaryOperator_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalInt.empty(), collector.fromIntUnaryOperator(o -> { + throw new NumberFormatException(); + }).apply(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntUnaryOperator_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromIntUnaryOperator(o -> { + throw new NumberFormatException(); + }).apply(1)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongUnaryOperator_complete() { + var collector = new ExceptionCollector(true); + LongUnaryOperator lambda = mock(LongUnaryOperator.class); + when(lambda.applyAsLong(1L)).thenReturn(2L); + assertEquals(OptionalLong.of(2L), collector.fromLongUnaryOperator(lambda).apply(1L)); + verify(lambda, only()).applyAsLong(1L); + assertTrue(collector.empty()); + } + @Test + public void fromLongUnaryOperator_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalLong.empty(), collector.fromLongUnaryOperator(o -> { + throw new NumberFormatException(); + }).apply(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongUnaryOperator_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromLongUnaryOperator(o -> { + throw new NumberFormatException(); + }).apply(1L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleUnaryOperator_complete() { + var collector = new ExceptionCollector(true); + DoubleUnaryOperator lambda = mock(DoubleUnaryOperator.class); + when(lambda.applyAsDouble(1.0)).thenReturn(2.0); + assertEquals(OptionalDouble.of(2.0), collector.fromDoubleUnaryOperator(lambda).apply(1.0)); + verify(lambda, only()).applyAsDouble(1.0); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleUnaryOperator_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalDouble.empty(), collector.fromDoubleUnaryOperator(o -> { + throw new NumberFormatException(); + }).apply(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleUnaryOperator_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromDoubleUnaryOperator(o -> { + throw new NumberFormatException(); + }).apply(1.0)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBiFunction_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") BiFunction lambda = mock(BiFunction.class); + when(lambda.apply("input1", "input2")).thenReturn("value"); + assertEquals(Optional.of("value"), collector.fromBiFunction(lambda).apply("input1", "input2")); + verify(lambda, only()).apply("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromBiFunction_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(Optional.empty(), collector.fromBiFunction((t, u) -> { + throw new NumberFormatException(); + }).apply("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBiFunction_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromBiFunction((t, u) -> { + throw new NumberFormatException(); + }).apply("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToIntBiFunction_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") ToIntBiFunction lambda = mock(ToIntBiFunction.class); + when(lambda.applyAsInt("input1", "input2")).thenReturn(2); + assertEquals(OptionalInt.of(2), collector.fromToIntBiFunction(lambda).apply("input1", "input2")); + verify(lambda, only()).applyAsInt("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromToIntBiFunction_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalInt.empty(), collector.fromToIntBiFunction((t, u) -> { + throw new NumberFormatException(); + }).apply("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToIntBiFunction_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromToIntBiFunction((t, u) -> { + throw new NumberFormatException(); + }).apply("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToLongBiFunction_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") ToLongBiFunction lambda = mock(ToLongBiFunction.class); + when(lambda.applyAsLong("input1", "input2")).thenReturn(2L); + assertEquals(OptionalLong.of(2L), collector.fromToLongBiFunction(lambda).apply("input1", "input2")); + verify(lambda, only()).applyAsLong("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromToLongBiFunction_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalLong.empty(), collector.fromToLongBiFunction((t, u) -> { + throw new NumberFormatException(); + }).apply("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToLongBiFunction_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromToLongBiFunction((t, u) -> { + throw new NumberFormatException(); + }).apply("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToDoubleBiFunction_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") ToDoubleBiFunction lambda = mock(ToDoubleBiFunction.class); + when(lambda.applyAsDouble("input1", "input2")).thenReturn(2.0); + assertEquals(OptionalDouble.of(2.0), collector.fromToDoubleBiFunction(lambda).apply("input1", "input2")); + verify(lambda, only()).applyAsDouble("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromToDoubleBiFunction_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalDouble.empty(), collector.fromToDoubleBiFunction((t, u) -> { + throw new NumberFormatException(); + }).apply("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromToDoubleBiFunction_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromToDoubleBiFunction((t, u) -> { + throw new NumberFormatException(); + }).apply("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBinaryOperator_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") BinaryOperator lambda = mock(BinaryOperator.class); + when(lambda.apply("input1", "input2")).thenReturn("value"); + assertEquals(Optional.of("value"), collector.fromBinaryOperator(lambda).apply("input1", "input2")); + verify(lambda, only()).apply("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void fromBinaryOperator_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(Optional.empty(), collector.fromBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).apply("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromBinaryOperator_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).apply("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntBinaryOperator_complete() { + var collector = new ExceptionCollector(true); + IntBinaryOperator lambda = mock(IntBinaryOperator.class); + when(lambda.applyAsInt(11, 12)).thenReturn(2); + assertEquals(OptionalInt.of(2), collector.fromIntBinaryOperator(lambda).apply(11, 12)); + verify(lambda, only()).applyAsInt(11, 12); + assertTrue(collector.empty()); + } + @Test + public void fromIntBinaryOperator_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalInt.empty(), collector.fromIntBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).apply(11, 12)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromIntBinaryOperator_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromIntBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).apply(11, 12)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongBinaryOperator_complete() { + var collector = new ExceptionCollector(true); + LongBinaryOperator lambda = mock(LongBinaryOperator.class); + when(lambda.applyAsLong(11L, 12L)).thenReturn(2L); + assertEquals(OptionalLong.of(2L), collector.fromLongBinaryOperator(lambda).apply(11L, 12L)); + verify(lambda, only()).applyAsLong(11L, 12L); + assertTrue(collector.empty()); + } + @Test + public void fromLongBinaryOperator_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalLong.empty(), collector.fromLongBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).apply(11L, 12L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromLongBinaryOperator_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromLongBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).apply(11L, 12L)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleBinaryOperator_complete() { + var collector = new ExceptionCollector(true); + DoubleBinaryOperator lambda = mock(DoubleBinaryOperator.class); + when(lambda.applyAsDouble(1.1, 1.2)).thenReturn(2.0); + assertEquals(OptionalDouble.of(2.0), collector.fromDoubleBinaryOperator(lambda).apply(1.1, 1.2)); + verify(lambda, only()).applyAsDouble(1.1, 1.2); + assertTrue(collector.empty()); + } + @Test + public void fromDoubleBinaryOperator_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalDouble.empty(), collector.fromDoubleBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).apply(1.1, 1.2)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void fromDoubleBinaryOperator_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.fromDoubleBinaryOperator((l, r) -> { + throw new NumberFormatException(); + }).apply(1.1, 1.2)); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void comparator_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") Comparator lambda = mock(Comparator.class); + when(lambda.compare("input1", "input2")).thenReturn(2); + assertEquals(OptionalInt.of(2), collector.comparator(lambda).compare("input1", "input2")); + verify(lambda, only()).compare("input1", "input2"); + assertTrue(collector.empty()); + } + @Test + public void comparator_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalInt.empty(), collector.comparator((l, r) -> { + throw new NumberFormatException(); + }).compare("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void comparator_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.comparator((l, r) -> { + throw new NumberFormatException(); + }).compare("input1", "input2")); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void closeable_complete() { + var collector = new ExceptionCollector(true); + CloseableScope lambda = mock(CloseableScope.class); + collector.closeable(lambda).close(); + verify(lambda, only()).close(); + assertTrue(collector.empty()); + } + @Test + public void closeable_swallowException() { + var collector = new ExceptionCollector(true); + collector.closeable(() -> { + throw new NumberFormatException(); + }).close(); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void closeable_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.closeable(() -> { + throw new NumberFormatException(); + }).close()); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void run_complete() { + var collector = new ExceptionCollector(true); + Runnable lambda = mock(Runnable.class); + collector.run(lambda); + verify(lambda, only()).run(); + assertTrue(collector.empty()); + } + @Test + public void run_swallowException() { + var collector = new ExceptionCollector(true); + collector.run(() -> { + throw new NumberFormatException(); + }); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void run_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.run(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void get_complete() { + var collector = new ExceptionCollector(true); + @SuppressWarnings("unchecked") Supplier lambda = mock(Supplier.class); + when(lambda.get()).thenReturn("value"); + assertEquals(Optional.of("value"), collector.get(lambda)); + verify(lambda, only()).get(); + assertTrue(collector.empty()); + } + @Test + public void get_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(Optional.empty(), collector.get(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void get_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.get(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void getAsInt_complete() { + var collector = new ExceptionCollector(true); + IntSupplier lambda = mock(IntSupplier.class); + when(lambda.getAsInt()).thenReturn(2); + assertEquals(OptionalInt.of(2), collector.getAsInt(lambda)); + verify(lambda, only()).getAsInt(); + assertTrue(collector.empty()); + } + @Test + public void getAsInt_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalInt.empty(), collector.getAsInt(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void getAsInt_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.getAsInt(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void getAsLong_complete() { + var collector = new ExceptionCollector(true); + LongSupplier lambda = mock(LongSupplier.class); + when(lambda.getAsLong()).thenReturn(2L); + assertEquals(OptionalLong.of(2L), collector.getAsLong(lambda)); + verify(lambda, only()).getAsLong(); + assertTrue(collector.empty()); + } + @Test + public void getAsLong_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalLong.empty(), collector.getAsLong(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void getAsLong_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.getAsLong(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void getAsDouble_complete() { + var collector = new ExceptionCollector(true); + DoubleSupplier lambda = mock(DoubleSupplier.class); + when(lambda.getAsDouble()).thenReturn(2.0); + assertEquals(OptionalDouble.of(2.0), collector.getAsDouble(lambda)); + verify(lambda, only()).getAsDouble(); + assertTrue(collector.empty()); + } + @Test + public void getAsDouble_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalDouble.empty(), collector.getAsDouble(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void getAsDouble_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.getAsDouble(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void getAsBoolean_complete() { + var collector = new ExceptionCollector(true); + BooleanSupplier lambda = mock(BooleanSupplier.class); + when(lambda.getAsBoolean()).thenReturn(true); + assertEquals(OptionalBoolean.of(true), collector.getAsBoolean(lambda)); + verify(lambda, only()).getAsBoolean(); + assertTrue(collector.empty()); + } + @Test + public void getAsBoolean_swallowException() { + var collector = new ExceptionCollector(true); + assertEquals(OptionalBoolean.empty(), collector.getAsBoolean(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } + @Test + public void getAsBoolean_passException() { + var collector = new ExceptionCollector(false); + assertThrows(NumberFormatException.class, () -> collector.getAsBoolean(() -> { + throw new NumberFormatException(); + })); + assertThat(collector.single(), instanceOf(NumberFormatException.class)); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultBiFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultBiFunctionTest.java index 8da48e5..7403c46 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultBiFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultBiFunctionTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultBiFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalBiFunction full = mock(OptionalBiFunction.class); - when(full.apply("input1", "input2")).thenReturn(Optional.of("value")); - assertEquals("value", new DefaultBiFunction(full, "default").apply("input1", "input2")); - verify(full, only()).apply("input1", "input2"); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalBiFunction empty = mock(OptionalBiFunction.class); - when(empty.apply("input1", "input2")).thenReturn(Optional.empty()); - assertEquals("default", new DefaultBiFunction(empty, "default").apply("input1", "input2")); - verify(empty, only()).apply("input1", "input2"); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalBiFunction full = mock(OptionalBiFunction.class); + when(full.apply("input1", "input2")).thenReturn(Optional.of("value")); + assertEquals("value", new DefaultBiFunction(full, "default").apply("input1", "input2")); + verify(full, only()).apply("input1", "input2"); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalBiFunction empty = mock(OptionalBiFunction.class); + when(empty.apply("input1", "input2")).thenReturn(Optional.empty()); + assertEquals("default", new DefaultBiFunction(empty, "default").apply("input1", "input2")); + verify(empty, only()).apply("input1", "input2"); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultBiPredicateTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultBiPredicateTest.java index 54c5f01..4f27d4b 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultBiPredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultBiPredicateTest.java @@ -7,18 +7,18 @@ import org.junit.jupiter.api.*; public class DefaultBiPredicateTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalBiPredicate full = mock(OptionalBiPredicate.class); - when(full.test("input1", "input2")).thenReturn(OptionalBoolean.of(true)); - assertEquals(true, new DefaultBiPredicate(full, false).test("input1", "input2")); - verify(full, only()).test("input1", "input2"); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalBiPredicate empty = mock(OptionalBiPredicate.class); - when(empty.test("input1", "input2")).thenReturn(OptionalBoolean.empty()); - assertEquals(false, new DefaultBiPredicate(empty, false).test("input1", "input2")); - verify(empty, only()).test("input1", "input2"); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalBiPredicate full = mock(OptionalBiPredicate.class); + when(full.test("input1", "input2")).thenReturn(OptionalBoolean.of(true)); + assertEquals(true, new DefaultBiPredicate(full, false).test("input1", "input2")); + verify(full, only()).test("input1", "input2"); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalBiPredicate empty = mock(OptionalBiPredicate.class); + when(empty.test("input1", "input2")).thenReturn(OptionalBoolean.empty()); + assertEquals(false, new DefaultBiPredicate(empty, false).test("input1", "input2")); + verify(empty, only()).test("input1", "input2"); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultBinaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultBinaryOperatorTest.java index 205f56c..70ab03f 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultBinaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultBinaryOperatorTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultBinaryOperatorTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalBinaryOperator full = mock(OptionalBinaryOperator.class); - when(full.apply("input1", "input2")).thenReturn(Optional.of("value")); - assertEquals("value", new DefaultBinaryOperator(full, "default").apply("input1", "input2")); - verify(full, only()).apply("input1", "input2"); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalBinaryOperator empty = mock(OptionalBinaryOperator.class); - when(empty.apply("input1", "input2")).thenReturn(Optional.empty()); - assertEquals("default", new DefaultBinaryOperator(empty, "default").apply("input1", "input2")); - verify(empty, only()).apply("input1", "input2"); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalBinaryOperator full = mock(OptionalBinaryOperator.class); + when(full.apply("input1", "input2")).thenReturn(Optional.of("value")); + assertEquals("value", new DefaultBinaryOperator(full, "default").apply("input1", "input2")); + verify(full, only()).apply("input1", "input2"); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalBinaryOperator empty = mock(OptionalBinaryOperator.class); + when(empty.apply("input1", "input2")).thenReturn(Optional.empty()); + assertEquals("default", new DefaultBinaryOperator(empty, "default").apply("input1", "input2")); + verify(empty, only()).apply("input1", "input2"); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultBooleanSupplierTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultBooleanSupplierTest.java index e9e00ea..e1b406a 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultBooleanSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultBooleanSupplierTest.java @@ -7,18 +7,18 @@ import org.junit.jupiter.api.*; public class DefaultBooleanSupplierTest { - @Test - public void full() { - OptionalBooleanSupplier full = mock(OptionalBooleanSupplier.class); - when(full.get()).thenReturn(OptionalBoolean.of(true)); - assertEquals(true, new DefaultBooleanSupplier(full, false).getAsBoolean()); - verify(full, only()).get(); - } - @Test - public void empty() { - OptionalBooleanSupplier empty = mock(OptionalBooleanSupplier.class); - when(empty.get()).thenReturn(OptionalBoolean.empty()); - assertEquals(false, new DefaultBooleanSupplier(empty, false).getAsBoolean()); - verify(empty, only()).get(); - } + @Test + public void full() { + OptionalBooleanSupplier full = mock(OptionalBooleanSupplier.class); + when(full.get()).thenReturn(OptionalBoolean.of(true)); + assertEquals(true, new DefaultBooleanSupplier(full, false).getAsBoolean()); + verify(full, only()).get(); + } + @Test + public void empty() { + OptionalBooleanSupplier empty = mock(OptionalBooleanSupplier.class); + when(empty.get()).thenReturn(OptionalBoolean.empty()); + assertEquals(false, new DefaultBooleanSupplier(empty, false).getAsBoolean()); + verify(empty, only()).get(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultComparatorTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultComparatorTest.java index 4b6f986..a6a02c9 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultComparatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultComparatorTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultComparatorTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalComparator full = mock(OptionalComparator.class); - when(full.compare("input1", "input2")).thenReturn(OptionalInt.of(2)); - assertEquals(2, new DefaultComparator(full, 3).compare("input1", "input2")); - verify(full, only()).compare("input1", "input2"); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalComparator empty = mock(OptionalComparator.class); - when(empty.compare("input1", "input2")).thenReturn(OptionalInt.empty()); - assertEquals(3, new DefaultComparator(empty, 3).compare("input1", "input2")); - verify(empty, only()).compare("input1", "input2"); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalComparator full = mock(OptionalComparator.class); + when(full.compare("input1", "input2")).thenReturn(OptionalInt.of(2)); + assertEquals(2, new DefaultComparator(full, 3).compare("input1", "input2")); + verify(full, only()).compare("input1", "input2"); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalComparator empty = mock(OptionalComparator.class); + when(empty.compare("input1", "input2")).thenReturn(OptionalInt.empty()); + assertEquals(3, new DefaultComparator(empty, 3).compare("input1", "input2")); + verify(empty, only()).compare("input1", "input2"); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleBinaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleBinaryOperatorTest.java index 77c2eb9..af52290 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleBinaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleBinaryOperatorTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultDoubleBinaryOperatorTest { - @Test - public void full() { - OptionalDoubleBinaryOperator full = mock(OptionalDoubleBinaryOperator.class); - when(full.apply(1.1, 1.2)).thenReturn(OptionalDouble.of(2.0)); - assertEquals(2.0, new DefaultDoubleBinaryOperator(full, 3.0).applyAsDouble(1.1, 1.2), 0.1); - verify(full, only()).apply(1.1, 1.2); - } - @Test - public void empty() { - OptionalDoubleBinaryOperator empty = mock(OptionalDoubleBinaryOperator.class); - when(empty.apply(1.1, 1.2)).thenReturn(OptionalDouble.empty()); - assertEquals(3.0, new DefaultDoubleBinaryOperator(empty, 3.0).applyAsDouble(1.1, 1.2), 0.1); - verify(empty, only()).apply(1.1, 1.2); - } + @Test + public void full() { + OptionalDoubleBinaryOperator full = mock(OptionalDoubleBinaryOperator.class); + when(full.apply(1.1, 1.2)).thenReturn(OptionalDouble.of(2.0)); + assertEquals(2.0, new DefaultDoubleBinaryOperator(full, 3.0).applyAsDouble(1.1, 1.2), 0.1); + verify(full, only()).apply(1.1, 1.2); + } + @Test + public void empty() { + OptionalDoubleBinaryOperator empty = mock(OptionalDoubleBinaryOperator.class); + when(empty.apply(1.1, 1.2)).thenReturn(OptionalDouble.empty()); + assertEquals(3.0, new DefaultDoubleBinaryOperator(empty, 3.0).applyAsDouble(1.1, 1.2), 0.1); + verify(empty, only()).apply(1.1, 1.2); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleFunctionTest.java index 1b6f680..e0e0c79 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleFunctionTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultDoubleFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalDoubleFunction full = mock(OptionalDoubleFunction.class); - when(full.apply(1.0)).thenReturn(Optional.of("value")); - assertEquals("value", new DefaultDoubleFunction(full, "default").apply(1.0)); - verify(full, only()).apply(1.0); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalDoubleFunction empty = mock(OptionalDoubleFunction.class); - when(empty.apply(1.0)).thenReturn(Optional.empty()); - assertEquals("default", new DefaultDoubleFunction(empty, "default").apply(1.0)); - verify(empty, only()).apply(1.0); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalDoubleFunction full = mock(OptionalDoubleFunction.class); + when(full.apply(1.0)).thenReturn(Optional.of("value")); + assertEquals("value", new DefaultDoubleFunction(full, "default").apply(1.0)); + verify(full, only()).apply(1.0); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalDoubleFunction empty = mock(OptionalDoubleFunction.class); + when(empty.apply(1.0)).thenReturn(Optional.empty()); + assertEquals("default", new DefaultDoubleFunction(empty, "default").apply(1.0)); + verify(empty, only()).apply(1.0); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultDoublePredicateTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultDoublePredicateTest.java index 3f88737..4a6ac0c 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultDoublePredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultDoublePredicateTest.java @@ -7,18 +7,18 @@ import org.junit.jupiter.api.*; public class DefaultDoublePredicateTest { - @Test - public void full() { - OptionalDoublePredicate full = mock(OptionalDoublePredicate.class); - when(full.test(1.0)).thenReturn(OptionalBoolean.of(true)); - assertEquals(true, new DefaultDoublePredicate(full, false).test(1.0)); - verify(full, only()).test(1.0); - } - @Test - public void empty() { - OptionalDoublePredicate empty = mock(OptionalDoublePredicate.class); - when(empty.test(1.0)).thenReturn(OptionalBoolean.empty()); - assertEquals(false, new DefaultDoublePredicate(empty, false).test(1.0)); - verify(empty, only()).test(1.0); - } + @Test + public void full() { + OptionalDoublePredicate full = mock(OptionalDoublePredicate.class); + when(full.test(1.0)).thenReturn(OptionalBoolean.of(true)); + assertEquals(true, new DefaultDoublePredicate(full, false).test(1.0)); + verify(full, only()).test(1.0); + } + @Test + public void empty() { + OptionalDoublePredicate empty = mock(OptionalDoublePredicate.class); + when(empty.test(1.0)).thenReturn(OptionalBoolean.empty()); + assertEquals(false, new DefaultDoublePredicate(empty, false).test(1.0)); + verify(empty, only()).test(1.0); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleSupplierTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleSupplierTest.java index b44209e..7ac0b30 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleSupplierTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultDoubleSupplierTest { - @Test - public void full() { - OptionalDoubleSupplier full = mock(OptionalDoubleSupplier.class); - when(full.get()).thenReturn(OptionalDouble.of(2.0)); - assertEquals(2.0, new DefaultDoubleSupplier(full, 3.0).getAsDouble(), 0.1); - verify(full, only()).get(); - } - @Test - public void empty() { - OptionalDoubleSupplier empty = mock(OptionalDoubleSupplier.class); - when(empty.get()).thenReturn(OptionalDouble.empty()); - assertEquals(3.0, new DefaultDoubleSupplier(empty, 3.0).getAsDouble(), 0.1); - verify(empty, only()).get(); - } + @Test + public void full() { + OptionalDoubleSupplier full = mock(OptionalDoubleSupplier.class); + when(full.get()).thenReturn(OptionalDouble.of(2.0)); + assertEquals(2.0, new DefaultDoubleSupplier(full, 3.0).getAsDouble(), 0.1); + verify(full, only()).get(); + } + @Test + public void empty() { + OptionalDoubleSupplier empty = mock(OptionalDoubleSupplier.class); + when(empty.get()).thenReturn(OptionalDouble.empty()); + assertEquals(3.0, new DefaultDoubleSupplier(empty, 3.0).getAsDouble(), 0.1); + verify(empty, only()).get(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleToIntFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleToIntFunctionTest.java index d8353c2..5491810 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleToIntFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleToIntFunctionTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultDoubleToIntFunctionTest { - @Test - public void full() { - OptionalDoubleToIntFunction full = mock(OptionalDoubleToIntFunction.class); - when(full.apply(1.0)).thenReturn(OptionalInt.of(2)); - assertEquals(2, new DefaultDoubleToIntFunction(full, 3).applyAsInt(1.0)); - verify(full, only()).apply(1.0); - } - @Test - public void empty() { - OptionalDoubleToIntFunction empty = mock(OptionalDoubleToIntFunction.class); - when(empty.apply(1.0)).thenReturn(OptionalInt.empty()); - assertEquals(3, new DefaultDoubleToIntFunction(empty, 3).applyAsInt(1.0)); - verify(empty, only()).apply(1.0); - } + @Test + public void full() { + OptionalDoubleToIntFunction full = mock(OptionalDoubleToIntFunction.class); + when(full.apply(1.0)).thenReturn(OptionalInt.of(2)); + assertEquals(2, new DefaultDoubleToIntFunction(full, 3).applyAsInt(1.0)); + verify(full, only()).apply(1.0); + } + @Test + public void empty() { + OptionalDoubleToIntFunction empty = mock(OptionalDoubleToIntFunction.class); + when(empty.apply(1.0)).thenReturn(OptionalInt.empty()); + assertEquals(3, new DefaultDoubleToIntFunction(empty, 3).applyAsInt(1.0)); + verify(empty, only()).apply(1.0); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleToLongFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleToLongFunctionTest.java index 0e336fb..dc28b20 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleToLongFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleToLongFunctionTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultDoubleToLongFunctionTest { - @Test - public void full() { - OptionalDoubleToLongFunction full = mock(OptionalDoubleToLongFunction.class); - when(full.apply(1.0)).thenReturn(OptionalLong.of(2L)); - assertEquals(2L, new DefaultDoubleToLongFunction(full, 3L).applyAsLong(1.0)); - verify(full, only()).apply(1.0); - } - @Test - public void empty() { - OptionalDoubleToLongFunction empty = mock(OptionalDoubleToLongFunction.class); - when(empty.apply(1.0)).thenReturn(OptionalLong.empty()); - assertEquals(3L, new DefaultDoubleToLongFunction(empty, 3L).applyAsLong(1.0)); - verify(empty, only()).apply(1.0); - } + @Test + public void full() { + OptionalDoubleToLongFunction full = mock(OptionalDoubleToLongFunction.class); + when(full.apply(1.0)).thenReturn(OptionalLong.of(2L)); + assertEquals(2L, new DefaultDoubleToLongFunction(full, 3L).applyAsLong(1.0)); + verify(full, only()).apply(1.0); + } + @Test + public void empty() { + OptionalDoubleToLongFunction empty = mock(OptionalDoubleToLongFunction.class); + when(empty.apply(1.0)).thenReturn(OptionalLong.empty()); + assertEquals(3L, new DefaultDoubleToLongFunction(empty, 3L).applyAsLong(1.0)); + verify(empty, only()).apply(1.0); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleUnaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleUnaryOperatorTest.java index ebf196b..e9cee73 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleUnaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultDoubleUnaryOperatorTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultDoubleUnaryOperatorTest { - @Test - public void full() { - OptionalDoubleUnaryOperator full = mock(OptionalDoubleUnaryOperator.class); - when(full.apply(1.0)).thenReturn(OptionalDouble.of(2.0)); - assertEquals(2.0, new DefaultDoubleUnaryOperator(full, 3.0).applyAsDouble(1.0), 0.1); - verify(full, only()).apply(1.0); - } - @Test - public void empty() { - OptionalDoubleUnaryOperator empty = mock(OptionalDoubleUnaryOperator.class); - when(empty.apply(1.0)).thenReturn(OptionalDouble.empty()); - assertEquals(3.0, new DefaultDoubleUnaryOperator(empty, 3.0).applyAsDouble(1.0), 0.1); - verify(empty, only()).apply(1.0); - } + @Test + public void full() { + OptionalDoubleUnaryOperator full = mock(OptionalDoubleUnaryOperator.class); + when(full.apply(1.0)).thenReturn(OptionalDouble.of(2.0)); + assertEquals(2.0, new DefaultDoubleUnaryOperator(full, 3.0).applyAsDouble(1.0), 0.1); + verify(full, only()).apply(1.0); + } + @Test + public void empty() { + OptionalDoubleUnaryOperator empty = mock(OptionalDoubleUnaryOperator.class); + when(empty.apply(1.0)).thenReturn(OptionalDouble.empty()); + assertEquals(3.0, new DefaultDoubleUnaryOperator(empty, 3.0).applyAsDouble(1.0), 0.1); + verify(empty, only()).apply(1.0); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultFunctionTest.java index 57bca53..1743357 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultFunctionTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalFunction full = mock(OptionalFunction.class); - when(full.apply("input")).thenReturn(Optional.of("value")); - assertEquals("value", new DefaultFunction(full, "default").apply("input")); - verify(full, only()).apply("input"); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalFunction empty = mock(OptionalFunction.class); - when(empty.apply("input")).thenReturn(Optional.empty()); - assertEquals("default", new DefaultFunction(empty, "default").apply("input")); - verify(empty, only()).apply("input"); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalFunction full = mock(OptionalFunction.class); + when(full.apply("input")).thenReturn(Optional.of("value")); + assertEquals("value", new DefaultFunction(full, "default").apply("input")); + verify(full, only()).apply("input"); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalFunction empty = mock(OptionalFunction.class); + when(empty.apply("input")).thenReturn(Optional.empty()); + assertEquals("default", new DefaultFunction(empty, "default").apply("input")); + verify(empty, only()).apply("input"); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultIntBinaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultIntBinaryOperatorTest.java index fbb752e..241482d 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultIntBinaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultIntBinaryOperatorTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultIntBinaryOperatorTest { - @Test - public void full() { - OptionalIntBinaryOperator full = mock(OptionalIntBinaryOperator.class); - when(full.apply(11, 12)).thenReturn(OptionalInt.of(2)); - assertEquals(2, new DefaultIntBinaryOperator(full, 3).applyAsInt(11, 12)); - verify(full, only()).apply(11, 12); - } - @Test - public void empty() { - OptionalIntBinaryOperator empty = mock(OptionalIntBinaryOperator.class); - when(empty.apply(11, 12)).thenReturn(OptionalInt.empty()); - assertEquals(3, new DefaultIntBinaryOperator(empty, 3).applyAsInt(11, 12)); - verify(empty, only()).apply(11, 12); - } + @Test + public void full() { + OptionalIntBinaryOperator full = mock(OptionalIntBinaryOperator.class); + when(full.apply(11, 12)).thenReturn(OptionalInt.of(2)); + assertEquals(2, new DefaultIntBinaryOperator(full, 3).applyAsInt(11, 12)); + verify(full, only()).apply(11, 12); + } + @Test + public void empty() { + OptionalIntBinaryOperator empty = mock(OptionalIntBinaryOperator.class); + when(empty.apply(11, 12)).thenReturn(OptionalInt.empty()); + assertEquals(3, new DefaultIntBinaryOperator(empty, 3).applyAsInt(11, 12)); + verify(empty, only()).apply(11, 12); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultIntFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultIntFunctionTest.java index 4e672d0..90546f4 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultIntFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultIntFunctionTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultIntFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalIntFunction full = mock(OptionalIntFunction.class); - when(full.apply(1)).thenReturn(Optional.of("value")); - assertEquals("value", new DefaultIntFunction(full, "default").apply(1)); - verify(full, only()).apply(1); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalIntFunction empty = mock(OptionalIntFunction.class); - when(empty.apply(1)).thenReturn(Optional.empty()); - assertEquals("default", new DefaultIntFunction(empty, "default").apply(1)); - verify(empty, only()).apply(1); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalIntFunction full = mock(OptionalIntFunction.class); + when(full.apply(1)).thenReturn(Optional.of("value")); + assertEquals("value", new DefaultIntFunction(full, "default").apply(1)); + verify(full, only()).apply(1); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalIntFunction empty = mock(OptionalIntFunction.class); + when(empty.apply(1)).thenReturn(Optional.empty()); + assertEquals("default", new DefaultIntFunction(empty, "default").apply(1)); + verify(empty, only()).apply(1); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultIntPredicateTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultIntPredicateTest.java index 9642cf4..f7bfe3f 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultIntPredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultIntPredicateTest.java @@ -7,18 +7,18 @@ import org.junit.jupiter.api.*; public class DefaultIntPredicateTest { - @Test - public void full() { - OptionalIntPredicate full = mock(OptionalIntPredicate.class); - when(full.test(1)).thenReturn(OptionalBoolean.of(true)); - assertEquals(true, new DefaultIntPredicate(full, false).test(1)); - verify(full, only()).test(1); - } - @Test - public void empty() { - OptionalIntPredicate empty = mock(OptionalIntPredicate.class); - when(empty.test(1)).thenReturn(OptionalBoolean.empty()); - assertEquals(false, new DefaultIntPredicate(empty, false).test(1)); - verify(empty, only()).test(1); - } + @Test + public void full() { + OptionalIntPredicate full = mock(OptionalIntPredicate.class); + when(full.test(1)).thenReturn(OptionalBoolean.of(true)); + assertEquals(true, new DefaultIntPredicate(full, false).test(1)); + verify(full, only()).test(1); + } + @Test + public void empty() { + OptionalIntPredicate empty = mock(OptionalIntPredicate.class); + when(empty.test(1)).thenReturn(OptionalBoolean.empty()); + assertEquals(false, new DefaultIntPredicate(empty, false).test(1)); + verify(empty, only()).test(1); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultIntSupplierTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultIntSupplierTest.java index f034d67..be27d2e 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultIntSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultIntSupplierTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultIntSupplierTest { - @Test - public void full() { - OptionalIntSupplier full = mock(OptionalIntSupplier.class); - when(full.get()).thenReturn(OptionalInt.of(2)); - assertEquals(2, new DefaultIntSupplier(full, 3).getAsInt()); - verify(full, only()).get(); - } - @Test - public void empty() { - OptionalIntSupplier empty = mock(OptionalIntSupplier.class); - when(empty.get()).thenReturn(OptionalInt.empty()); - assertEquals(3, new DefaultIntSupplier(empty, 3).getAsInt()); - verify(empty, only()).get(); - } + @Test + public void full() { + OptionalIntSupplier full = mock(OptionalIntSupplier.class); + when(full.get()).thenReturn(OptionalInt.of(2)); + assertEquals(2, new DefaultIntSupplier(full, 3).getAsInt()); + verify(full, only()).get(); + } + @Test + public void empty() { + OptionalIntSupplier empty = mock(OptionalIntSupplier.class); + when(empty.get()).thenReturn(OptionalInt.empty()); + assertEquals(3, new DefaultIntSupplier(empty, 3).getAsInt()); + verify(empty, only()).get(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultIntToDoubleFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultIntToDoubleFunctionTest.java index 9978f87..acd4792 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultIntToDoubleFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultIntToDoubleFunctionTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultIntToDoubleFunctionTest { - @Test - public void full() { - OptionalIntToDoubleFunction full = mock(OptionalIntToDoubleFunction.class); - when(full.apply(1)).thenReturn(OptionalDouble.of(2.0)); - assertEquals(2.0, new DefaultIntToDoubleFunction(full, 3.0).applyAsDouble(1), 0.1); - verify(full, only()).apply(1); - } - @Test - public void empty() { - OptionalIntToDoubleFunction empty = mock(OptionalIntToDoubleFunction.class); - when(empty.apply(1)).thenReturn(OptionalDouble.empty()); - assertEquals(3.0, new DefaultIntToDoubleFunction(empty, 3.0).applyAsDouble(1), 0.1); - verify(empty, only()).apply(1); - } + @Test + public void full() { + OptionalIntToDoubleFunction full = mock(OptionalIntToDoubleFunction.class); + when(full.apply(1)).thenReturn(OptionalDouble.of(2.0)); + assertEquals(2.0, new DefaultIntToDoubleFunction(full, 3.0).applyAsDouble(1), 0.1); + verify(full, only()).apply(1); + } + @Test + public void empty() { + OptionalIntToDoubleFunction empty = mock(OptionalIntToDoubleFunction.class); + when(empty.apply(1)).thenReturn(OptionalDouble.empty()); + assertEquals(3.0, new DefaultIntToDoubleFunction(empty, 3.0).applyAsDouble(1), 0.1); + verify(empty, only()).apply(1); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultIntToLongFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultIntToLongFunctionTest.java index f47ea15..4f430e6 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultIntToLongFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultIntToLongFunctionTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultIntToLongFunctionTest { - @Test - public void full() { - OptionalIntToLongFunction full = mock(OptionalIntToLongFunction.class); - when(full.apply(1)).thenReturn(OptionalLong.of(2L)); - assertEquals(2L, new DefaultIntToLongFunction(full, 3L).applyAsLong(1)); - verify(full, only()).apply(1); - } - @Test - public void empty() { - OptionalIntToLongFunction empty = mock(OptionalIntToLongFunction.class); - when(empty.apply(1)).thenReturn(OptionalLong.empty()); - assertEquals(3L, new DefaultIntToLongFunction(empty, 3L).applyAsLong(1)); - verify(empty, only()).apply(1); - } + @Test + public void full() { + OptionalIntToLongFunction full = mock(OptionalIntToLongFunction.class); + when(full.apply(1)).thenReturn(OptionalLong.of(2L)); + assertEquals(2L, new DefaultIntToLongFunction(full, 3L).applyAsLong(1)); + verify(full, only()).apply(1); + } + @Test + public void empty() { + OptionalIntToLongFunction empty = mock(OptionalIntToLongFunction.class); + when(empty.apply(1)).thenReturn(OptionalLong.empty()); + assertEquals(3L, new DefaultIntToLongFunction(empty, 3L).applyAsLong(1)); + verify(empty, only()).apply(1); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultIntUnaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultIntUnaryOperatorTest.java index eeec836..473b234 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultIntUnaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultIntUnaryOperatorTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultIntUnaryOperatorTest { - @Test - public void full() { - OptionalIntUnaryOperator full = mock(OptionalIntUnaryOperator.class); - when(full.apply(1)).thenReturn(OptionalInt.of(2)); - assertEquals(2, new DefaultIntUnaryOperator(full, 3).applyAsInt(1)); - verify(full, only()).apply(1); - } - @Test - public void empty() { - OptionalIntUnaryOperator empty = mock(OptionalIntUnaryOperator.class); - when(empty.apply(1)).thenReturn(OptionalInt.empty()); - assertEquals(3, new DefaultIntUnaryOperator(empty, 3).applyAsInt(1)); - verify(empty, only()).apply(1); - } + @Test + public void full() { + OptionalIntUnaryOperator full = mock(OptionalIntUnaryOperator.class); + when(full.apply(1)).thenReturn(OptionalInt.of(2)); + assertEquals(2, new DefaultIntUnaryOperator(full, 3).applyAsInt(1)); + verify(full, only()).apply(1); + } + @Test + public void empty() { + OptionalIntUnaryOperator empty = mock(OptionalIntUnaryOperator.class); + when(empty.apply(1)).thenReturn(OptionalInt.empty()); + assertEquals(3, new DefaultIntUnaryOperator(empty, 3).applyAsInt(1)); + verify(empty, only()).apply(1); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultLongBinaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultLongBinaryOperatorTest.java index 55e7518..13b7ad1 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultLongBinaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultLongBinaryOperatorTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultLongBinaryOperatorTest { - @Test - public void full() { - OptionalLongBinaryOperator full = mock(OptionalLongBinaryOperator.class); - when(full.apply(11L, 12L)).thenReturn(OptionalLong.of(2L)); - assertEquals(2L, new DefaultLongBinaryOperator(full, 3L).applyAsLong(11L, 12L)); - verify(full, only()).apply(11L, 12L); - } - @Test - public void empty() { - OptionalLongBinaryOperator empty = mock(OptionalLongBinaryOperator.class); - when(empty.apply(11L, 12L)).thenReturn(OptionalLong.empty()); - assertEquals(3L, new DefaultLongBinaryOperator(empty, 3L).applyAsLong(11L, 12L)); - verify(empty, only()).apply(11L, 12L); - } + @Test + public void full() { + OptionalLongBinaryOperator full = mock(OptionalLongBinaryOperator.class); + when(full.apply(11L, 12L)).thenReturn(OptionalLong.of(2L)); + assertEquals(2L, new DefaultLongBinaryOperator(full, 3L).applyAsLong(11L, 12L)); + verify(full, only()).apply(11L, 12L); + } + @Test + public void empty() { + OptionalLongBinaryOperator empty = mock(OptionalLongBinaryOperator.class); + when(empty.apply(11L, 12L)).thenReturn(OptionalLong.empty()); + assertEquals(3L, new DefaultLongBinaryOperator(empty, 3L).applyAsLong(11L, 12L)); + verify(empty, only()).apply(11L, 12L); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultLongFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultLongFunctionTest.java index a688eac..9aa81fc 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultLongFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultLongFunctionTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultLongFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalLongFunction full = mock(OptionalLongFunction.class); - when(full.apply(1L)).thenReturn(Optional.of("value")); - assertEquals("value", new DefaultLongFunction(full, "default").apply(1L)); - verify(full, only()).apply(1L); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalLongFunction empty = mock(OptionalLongFunction.class); - when(empty.apply(1L)).thenReturn(Optional.empty()); - assertEquals("default", new DefaultLongFunction(empty, "default").apply(1L)); - verify(empty, only()).apply(1L); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalLongFunction full = mock(OptionalLongFunction.class); + when(full.apply(1L)).thenReturn(Optional.of("value")); + assertEquals("value", new DefaultLongFunction(full, "default").apply(1L)); + verify(full, only()).apply(1L); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalLongFunction empty = mock(OptionalLongFunction.class); + when(empty.apply(1L)).thenReturn(Optional.empty()); + assertEquals("default", new DefaultLongFunction(empty, "default").apply(1L)); + verify(empty, only()).apply(1L); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultLongPredicateTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultLongPredicateTest.java index f55eb94..90173bc 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultLongPredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultLongPredicateTest.java @@ -7,18 +7,18 @@ import org.junit.jupiter.api.*; public class DefaultLongPredicateTest { - @Test - public void full() { - OptionalLongPredicate full = mock(OptionalLongPredicate.class); - when(full.test(1L)).thenReturn(OptionalBoolean.of(true)); - assertEquals(true, new DefaultLongPredicate(full, false).test(1L)); - verify(full, only()).test(1L); - } - @Test - public void empty() { - OptionalLongPredicate empty = mock(OptionalLongPredicate.class); - when(empty.test(1L)).thenReturn(OptionalBoolean.empty()); - assertEquals(false, new DefaultLongPredicate(empty, false).test(1L)); - verify(empty, only()).test(1L); - } + @Test + public void full() { + OptionalLongPredicate full = mock(OptionalLongPredicate.class); + when(full.test(1L)).thenReturn(OptionalBoolean.of(true)); + assertEquals(true, new DefaultLongPredicate(full, false).test(1L)); + verify(full, only()).test(1L); + } + @Test + public void empty() { + OptionalLongPredicate empty = mock(OptionalLongPredicate.class); + when(empty.test(1L)).thenReturn(OptionalBoolean.empty()); + assertEquals(false, new DefaultLongPredicate(empty, false).test(1L)); + verify(empty, only()).test(1L); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultLongSupplierTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultLongSupplierTest.java index 79731f0..20f7746 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultLongSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultLongSupplierTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultLongSupplierTest { - @Test - public void full() { - OptionalLongSupplier full = mock(OptionalLongSupplier.class); - when(full.get()).thenReturn(OptionalLong.of(2L)); - assertEquals(2L, new DefaultLongSupplier(full, 3L).getAsLong()); - verify(full, only()).get(); - } - @Test - public void empty() { - OptionalLongSupplier empty = mock(OptionalLongSupplier.class); - when(empty.get()).thenReturn(OptionalLong.empty()); - assertEquals(3L, new DefaultLongSupplier(empty, 3L).getAsLong()); - verify(empty, only()).get(); - } + @Test + public void full() { + OptionalLongSupplier full = mock(OptionalLongSupplier.class); + when(full.get()).thenReturn(OptionalLong.of(2L)); + assertEquals(2L, new DefaultLongSupplier(full, 3L).getAsLong()); + verify(full, only()).get(); + } + @Test + public void empty() { + OptionalLongSupplier empty = mock(OptionalLongSupplier.class); + when(empty.get()).thenReturn(OptionalLong.empty()); + assertEquals(3L, new DefaultLongSupplier(empty, 3L).getAsLong()); + verify(empty, only()).get(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultLongToDoubleFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultLongToDoubleFunctionTest.java index c5e023e..94ee934 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultLongToDoubleFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultLongToDoubleFunctionTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultLongToDoubleFunctionTest { - @Test - public void full() { - OptionalLongToDoubleFunction full = mock(OptionalLongToDoubleFunction.class); - when(full.apply(1L)).thenReturn(OptionalDouble.of(2.0)); - assertEquals(2.0, new DefaultLongToDoubleFunction(full, 3.0).applyAsDouble(1L), 0.1); - verify(full, only()).apply(1L); - } - @Test - public void empty() { - OptionalLongToDoubleFunction empty = mock(OptionalLongToDoubleFunction.class); - when(empty.apply(1L)).thenReturn(OptionalDouble.empty()); - assertEquals(3.0, new DefaultLongToDoubleFunction(empty, 3.0).applyAsDouble(1L), 0.1); - verify(empty, only()).apply(1L); - } + @Test + public void full() { + OptionalLongToDoubleFunction full = mock(OptionalLongToDoubleFunction.class); + when(full.apply(1L)).thenReturn(OptionalDouble.of(2.0)); + assertEquals(2.0, new DefaultLongToDoubleFunction(full, 3.0).applyAsDouble(1L), 0.1); + verify(full, only()).apply(1L); + } + @Test + public void empty() { + OptionalLongToDoubleFunction empty = mock(OptionalLongToDoubleFunction.class); + when(empty.apply(1L)).thenReturn(OptionalDouble.empty()); + assertEquals(3.0, new DefaultLongToDoubleFunction(empty, 3.0).applyAsDouble(1L), 0.1); + verify(empty, only()).apply(1L); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultLongToIntFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultLongToIntFunctionTest.java index 938b63a..752be0d 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultLongToIntFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultLongToIntFunctionTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultLongToIntFunctionTest { - @Test - public void full() { - OptionalLongToIntFunction full = mock(OptionalLongToIntFunction.class); - when(full.apply(1L)).thenReturn(OptionalInt.of(2)); - assertEquals(2, new DefaultLongToIntFunction(full, 3).applyAsInt(1L)); - verify(full, only()).apply(1L); - } - @Test - public void empty() { - OptionalLongToIntFunction empty = mock(OptionalLongToIntFunction.class); - when(empty.apply(1L)).thenReturn(OptionalInt.empty()); - assertEquals(3, new DefaultLongToIntFunction(empty, 3).applyAsInt(1L)); - verify(empty, only()).apply(1L); - } + @Test + public void full() { + OptionalLongToIntFunction full = mock(OptionalLongToIntFunction.class); + when(full.apply(1L)).thenReturn(OptionalInt.of(2)); + assertEquals(2, new DefaultLongToIntFunction(full, 3).applyAsInt(1L)); + verify(full, only()).apply(1L); + } + @Test + public void empty() { + OptionalLongToIntFunction empty = mock(OptionalLongToIntFunction.class); + when(empty.apply(1L)).thenReturn(OptionalInt.empty()); + assertEquals(3, new DefaultLongToIntFunction(empty, 3).applyAsInt(1L)); + verify(empty, only()).apply(1L); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultLongUnaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultLongUnaryOperatorTest.java index 5dd80cf..45d5434 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultLongUnaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultLongUnaryOperatorTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultLongUnaryOperatorTest { - @Test - public void full() { - OptionalLongUnaryOperator full = mock(OptionalLongUnaryOperator.class); - when(full.apply(1L)).thenReturn(OptionalLong.of(2L)); - assertEquals(2L, new DefaultLongUnaryOperator(full, 3L).applyAsLong(1L)); - verify(full, only()).apply(1L); - } - @Test - public void empty() { - OptionalLongUnaryOperator empty = mock(OptionalLongUnaryOperator.class); - when(empty.apply(1L)).thenReturn(OptionalLong.empty()); - assertEquals(3L, new DefaultLongUnaryOperator(empty, 3L).applyAsLong(1L)); - verify(empty, only()).apply(1L); - } + @Test + public void full() { + OptionalLongUnaryOperator full = mock(OptionalLongUnaryOperator.class); + when(full.apply(1L)).thenReturn(OptionalLong.of(2L)); + assertEquals(2L, new DefaultLongUnaryOperator(full, 3L).applyAsLong(1L)); + verify(full, only()).apply(1L); + } + @Test + public void empty() { + OptionalLongUnaryOperator empty = mock(OptionalLongUnaryOperator.class); + when(empty.apply(1L)).thenReturn(OptionalLong.empty()); + assertEquals(3L, new DefaultLongUnaryOperator(empty, 3L).applyAsLong(1L)); + verify(empty, only()).apply(1L); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultPredicateTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultPredicateTest.java index 7dcaf0a..7ec4565 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultPredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultPredicateTest.java @@ -7,18 +7,18 @@ import org.junit.jupiter.api.*; public class DefaultPredicateTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalPredicate full = mock(OptionalPredicate.class); - when(full.test("input")).thenReturn(OptionalBoolean.of(true)); - assertEquals(true, new DefaultPredicate(full, false).test("input")); - verify(full, only()).test("input"); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalPredicate empty = mock(OptionalPredicate.class); - when(empty.test("input")).thenReturn(OptionalBoolean.empty()); - assertEquals(false, new DefaultPredicate(empty, false).test("input")); - verify(empty, only()).test("input"); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalPredicate full = mock(OptionalPredicate.class); + when(full.test("input")).thenReturn(OptionalBoolean.of(true)); + assertEquals(true, new DefaultPredicate(full, false).test("input")); + verify(full, only()).test("input"); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalPredicate empty = mock(OptionalPredicate.class); + when(empty.test("input")).thenReturn(OptionalBoolean.empty()); + assertEquals(false, new DefaultPredicate(empty, false).test("input")); + verify(empty, only()).test("input"); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultSupplierTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultSupplierTest.java index 8e3f690..f547333 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultSupplierTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultSupplierTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalSupplier full = mock(OptionalSupplier.class); - when(full.get()).thenReturn(Optional.of("value")); - assertEquals("value", new DefaultSupplier(full, "default").get()); - verify(full, only()).get(); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalSupplier empty = mock(OptionalSupplier.class); - when(empty.get()).thenReturn(Optional.empty()); - assertEquals("default", new DefaultSupplier(empty, "default").get()); - verify(empty, only()).get(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalSupplier full = mock(OptionalSupplier.class); + when(full.get()).thenReturn(Optional.of("value")); + assertEquals("value", new DefaultSupplier(full, "default").get()); + verify(full, only()).get(); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalSupplier empty = mock(OptionalSupplier.class); + when(empty.get()).thenReturn(Optional.empty()); + assertEquals("default", new DefaultSupplier(empty, "default").get()); + verify(empty, only()).get(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultToDoubleBiFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultToDoubleBiFunctionTest.java index f3936a2..0ed3c68 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultToDoubleBiFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultToDoubleBiFunctionTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultToDoubleBiFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalToDoubleBiFunction full = mock(OptionalToDoubleBiFunction.class); - when(full.apply("input1", "input2")).thenReturn(OptionalDouble.of(2.0)); - assertEquals(2.0, new DefaultToDoubleBiFunction(full, 3.0).applyAsDouble("input1", "input2"), 0.1); - verify(full, only()).apply("input1", "input2"); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalToDoubleBiFunction empty = mock(OptionalToDoubleBiFunction.class); - when(empty.apply("input1", "input2")).thenReturn(OptionalDouble.empty()); - assertEquals(3.0, new DefaultToDoubleBiFunction(empty, 3.0).applyAsDouble("input1", "input2"), 0.1); - verify(empty, only()).apply("input1", "input2"); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalToDoubleBiFunction full = mock(OptionalToDoubleBiFunction.class); + when(full.apply("input1", "input2")).thenReturn(OptionalDouble.of(2.0)); + assertEquals(2.0, new DefaultToDoubleBiFunction(full, 3.0).applyAsDouble("input1", "input2"), 0.1); + verify(full, only()).apply("input1", "input2"); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalToDoubleBiFunction empty = mock(OptionalToDoubleBiFunction.class); + when(empty.apply("input1", "input2")).thenReturn(OptionalDouble.empty()); + assertEquals(3.0, new DefaultToDoubleBiFunction(empty, 3.0).applyAsDouble("input1", "input2"), 0.1); + verify(empty, only()).apply("input1", "input2"); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultToDoubleFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultToDoubleFunctionTest.java index 3d08253..48b1311 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultToDoubleFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultToDoubleFunctionTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultToDoubleFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalToDoubleFunction full = mock(OptionalToDoubleFunction.class); - when(full.apply("input")).thenReturn(OptionalDouble.of(2.0)); - assertEquals(2.0, new DefaultToDoubleFunction(full, 3.0).applyAsDouble("input"), 0.1); - verify(full, only()).apply("input"); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalToDoubleFunction empty = mock(OptionalToDoubleFunction.class); - when(empty.apply("input")).thenReturn(OptionalDouble.empty()); - assertEquals(3.0, new DefaultToDoubleFunction(empty, 3.0).applyAsDouble("input"), 0.1); - verify(empty, only()).apply("input"); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalToDoubleFunction full = mock(OptionalToDoubleFunction.class); + when(full.apply("input")).thenReturn(OptionalDouble.of(2.0)); + assertEquals(2.0, new DefaultToDoubleFunction(full, 3.0).applyAsDouble("input"), 0.1); + verify(full, only()).apply("input"); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalToDoubleFunction empty = mock(OptionalToDoubleFunction.class); + when(empty.apply("input")).thenReturn(OptionalDouble.empty()); + assertEquals(3.0, new DefaultToDoubleFunction(empty, 3.0).applyAsDouble("input"), 0.1); + verify(empty, only()).apply("input"); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultToIntBiFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultToIntBiFunctionTest.java index 0f858e9..2ebf4b0 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultToIntBiFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultToIntBiFunctionTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultToIntBiFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalToIntBiFunction full = mock(OptionalToIntBiFunction.class); - when(full.apply("input1", "input2")).thenReturn(OptionalInt.of(2)); - assertEquals(2, new DefaultToIntBiFunction(full, 3).applyAsInt("input1", "input2")); - verify(full, only()).apply("input1", "input2"); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalToIntBiFunction empty = mock(OptionalToIntBiFunction.class); - when(empty.apply("input1", "input2")).thenReturn(OptionalInt.empty()); - assertEquals(3, new DefaultToIntBiFunction(empty, 3).applyAsInt("input1", "input2")); - verify(empty, only()).apply("input1", "input2"); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalToIntBiFunction full = mock(OptionalToIntBiFunction.class); + when(full.apply("input1", "input2")).thenReturn(OptionalInt.of(2)); + assertEquals(2, new DefaultToIntBiFunction(full, 3).applyAsInt("input1", "input2")); + verify(full, only()).apply("input1", "input2"); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalToIntBiFunction empty = mock(OptionalToIntBiFunction.class); + when(empty.apply("input1", "input2")).thenReturn(OptionalInt.empty()); + assertEquals(3, new DefaultToIntBiFunction(empty, 3).applyAsInt("input1", "input2")); + verify(empty, only()).apply("input1", "input2"); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultToIntFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultToIntFunctionTest.java index bfb6e6f..7df7079 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultToIntFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultToIntFunctionTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultToIntFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalToIntFunction full = mock(OptionalToIntFunction.class); - when(full.apply("input")).thenReturn(OptionalInt.of(2)); - assertEquals(2, new DefaultToIntFunction(full, 3).applyAsInt("input")); - verify(full, only()).apply("input"); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalToIntFunction empty = mock(OptionalToIntFunction.class); - when(empty.apply("input")).thenReturn(OptionalInt.empty()); - assertEquals(3, new DefaultToIntFunction(empty, 3).applyAsInt("input")); - verify(empty, only()).apply("input"); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalToIntFunction full = mock(OptionalToIntFunction.class); + when(full.apply("input")).thenReturn(OptionalInt.of(2)); + assertEquals(2, new DefaultToIntFunction(full, 3).applyAsInt("input")); + verify(full, only()).apply("input"); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalToIntFunction empty = mock(OptionalToIntFunction.class); + when(empty.apply("input")).thenReturn(OptionalInt.empty()); + assertEquals(3, new DefaultToIntFunction(empty, 3).applyAsInt("input")); + verify(empty, only()).apply("input"); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultToLongBiFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultToLongBiFunctionTest.java index 4953f5d..fe5ccd8 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultToLongBiFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultToLongBiFunctionTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultToLongBiFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalToLongBiFunction full = mock(OptionalToLongBiFunction.class); - when(full.apply("input1", "input2")).thenReturn(OptionalLong.of(2L)); - assertEquals(2L, new DefaultToLongBiFunction(full, 3L).applyAsLong("input1", "input2")); - verify(full, only()).apply("input1", "input2"); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalToLongBiFunction empty = mock(OptionalToLongBiFunction.class); - when(empty.apply("input1", "input2")).thenReturn(OptionalLong.empty()); - assertEquals(3L, new DefaultToLongBiFunction(empty, 3L).applyAsLong("input1", "input2")); - verify(empty, only()).apply("input1", "input2"); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalToLongBiFunction full = mock(OptionalToLongBiFunction.class); + when(full.apply("input1", "input2")).thenReturn(OptionalLong.of(2L)); + assertEquals(2L, new DefaultToLongBiFunction(full, 3L).applyAsLong("input1", "input2")); + verify(full, only()).apply("input1", "input2"); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalToLongBiFunction empty = mock(OptionalToLongBiFunction.class); + when(empty.apply("input1", "input2")).thenReturn(OptionalLong.empty()); + assertEquals(3L, new DefaultToLongBiFunction(empty, 3L).applyAsLong("input1", "input2")); + verify(empty, only()).apply("input1", "input2"); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultToLongFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultToLongFunctionTest.java index e9e0a98..acc4a68 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultToLongFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultToLongFunctionTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultToLongFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalToLongFunction full = mock(OptionalToLongFunction.class); - when(full.apply("input")).thenReturn(OptionalLong.of(2L)); - assertEquals(2L, new DefaultToLongFunction(full, 3L).applyAsLong("input")); - verify(full, only()).apply("input"); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalToLongFunction empty = mock(OptionalToLongFunction.class); - when(empty.apply("input")).thenReturn(OptionalLong.empty()); - assertEquals(3L, new DefaultToLongFunction(empty, 3L).applyAsLong("input")); - verify(empty, only()).apply("input"); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalToLongFunction full = mock(OptionalToLongFunction.class); + when(full.apply("input")).thenReturn(OptionalLong.of(2L)); + assertEquals(2L, new DefaultToLongFunction(full, 3L).applyAsLong("input")); + verify(full, only()).apply("input"); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalToLongFunction empty = mock(OptionalToLongFunction.class); + when(empty.apply("input")).thenReturn(OptionalLong.empty()); + assertEquals(3L, new DefaultToLongFunction(empty, 3L).applyAsLong("input")); + verify(empty, only()).apply("input"); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/DefaultUnaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/DefaultUnaryOperatorTest.java index 3c310f6..8c69319 100644 --- a/src/test/java/com/machinezoo/noexception/optional/DefaultUnaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/DefaultUnaryOperatorTest.java @@ -8,18 +8,18 @@ import org.junit.jupiter.api.*; public class DefaultUnaryOperatorTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalUnaryOperator full = mock(OptionalUnaryOperator.class); - when(full.apply("input")).thenReturn(Optional.of("value")); - assertEquals("value", new DefaultUnaryOperator(full, "default").apply("input")); - verify(full, only()).apply("input"); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalUnaryOperator empty = mock(OptionalUnaryOperator.class); - when(empty.apply("input")).thenReturn(Optional.empty()); - assertEquals("default", new DefaultUnaryOperator(empty, "default").apply("input")); - verify(empty, only()).apply("input"); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalUnaryOperator full = mock(OptionalUnaryOperator.class); + when(full.apply("input")).thenReturn(Optional.of("value")); + assertEquals("value", new DefaultUnaryOperator(full, "default").apply("input")); + verify(full, only()).apply("input"); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalUnaryOperator empty = mock(OptionalUnaryOperator.class); + when(empty.apply("input")).thenReturn(Optional.empty()); + assertEquals("default", new DefaultUnaryOperator(empty, "default").apply("input")); + verify(empty, only()).apply("input"); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackBiFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackBiFunctionTest.java index 305aab1..2ddd1b4 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackBiFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackBiFunctionTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackBiFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalBiFunction full = mock(OptionalBiFunction.class); - when(full.apply("input1", "input2")).thenReturn(Optional.of("value")); - @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); - when(fallback.get()).thenReturn("default"); - assertEquals("value", new FallbackBiFunction(full, fallback).apply("input1", "input2")); - verify(full, only()).apply("input1", "input2"); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalBiFunction empty = mock(OptionalBiFunction.class); - when(empty.apply("input1", "input2")).thenReturn(Optional.empty()); - @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); - when(fallback.get()).thenReturn("default"); - assertEquals("default", new FallbackBiFunction(empty, fallback).apply("input1", "input2")); - verify(empty, only()).apply("input1", "input2"); - verify(fallback, only()).get(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalBiFunction full = mock(OptionalBiFunction.class); + when(full.apply("input1", "input2")).thenReturn(Optional.of("value")); + @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); + when(fallback.get()).thenReturn("default"); + assertEquals("value", new FallbackBiFunction(full, fallback).apply("input1", "input2")); + verify(full, only()).apply("input1", "input2"); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalBiFunction empty = mock(OptionalBiFunction.class); + when(empty.apply("input1", "input2")).thenReturn(Optional.empty()); + @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); + when(fallback.get()).thenReturn("default"); + assertEquals("default", new FallbackBiFunction(empty, fallback).apply("input1", "input2")); + verify(empty, only()).apply("input1", "input2"); + verify(fallback, only()).get(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackBiPredicateTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackBiPredicateTest.java index 4f31508..694fc6f 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackBiPredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackBiPredicateTest.java @@ -8,24 +8,24 @@ import org.junit.jupiter.api.*; public class FallbackBiPredicateTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalBiPredicate full = mock(OptionalBiPredicate.class); - when(full.test("input1", "input2")).thenReturn(OptionalBoolean.of(true)); - BooleanSupplier fallback = mock(BooleanSupplier.class); - when(fallback.getAsBoolean()).thenReturn(false); - assertEquals(true, new FallbackBiPredicate(full, fallback).test("input1", "input2")); - verify(full, only()).test("input1", "input2"); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalBiPredicate empty = mock(OptionalBiPredicate.class); - when(empty.test("input1", "input2")).thenReturn(OptionalBoolean.empty()); - BooleanSupplier fallback = mock(BooleanSupplier.class); - when(fallback.getAsBoolean()).thenReturn(false); - assertEquals(false, new FallbackBiPredicate(empty, fallback).test("input1", "input2")); - verify(empty, only()).test("input1", "input2"); - verify(fallback, only()).getAsBoolean(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalBiPredicate full = mock(OptionalBiPredicate.class); + when(full.test("input1", "input2")).thenReturn(OptionalBoolean.of(true)); + BooleanSupplier fallback = mock(BooleanSupplier.class); + when(fallback.getAsBoolean()).thenReturn(false); + assertEquals(true, new FallbackBiPredicate(full, fallback).test("input1", "input2")); + verify(full, only()).test("input1", "input2"); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalBiPredicate empty = mock(OptionalBiPredicate.class); + when(empty.test("input1", "input2")).thenReturn(OptionalBoolean.empty()); + BooleanSupplier fallback = mock(BooleanSupplier.class); + when(fallback.getAsBoolean()).thenReturn(false); + assertEquals(false, new FallbackBiPredicate(empty, fallback).test("input1", "input2")); + verify(empty, only()).test("input1", "input2"); + verify(fallback, only()).getAsBoolean(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackBinaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackBinaryOperatorTest.java index 023b73b..d6e38c7 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackBinaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackBinaryOperatorTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackBinaryOperatorTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalBinaryOperator full = mock(OptionalBinaryOperator.class); - when(full.apply("input1", "input2")).thenReturn(Optional.of("value")); - @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); - when(fallback.get()).thenReturn("default"); - assertEquals("value", new FallbackBinaryOperator(full, fallback).apply("input1", "input2")); - verify(full, only()).apply("input1", "input2"); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalBinaryOperator empty = mock(OptionalBinaryOperator.class); - when(empty.apply("input1", "input2")).thenReturn(Optional.empty()); - @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); - when(fallback.get()).thenReturn("default"); - assertEquals("default", new FallbackBinaryOperator(empty, fallback).apply("input1", "input2")); - verify(empty, only()).apply("input1", "input2"); - verify(fallback, only()).get(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalBinaryOperator full = mock(OptionalBinaryOperator.class); + when(full.apply("input1", "input2")).thenReturn(Optional.of("value")); + @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); + when(fallback.get()).thenReturn("default"); + assertEquals("value", new FallbackBinaryOperator(full, fallback).apply("input1", "input2")); + verify(full, only()).apply("input1", "input2"); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalBinaryOperator empty = mock(OptionalBinaryOperator.class); + when(empty.apply("input1", "input2")).thenReturn(Optional.empty()); + @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); + when(fallback.get()).thenReturn("default"); + assertEquals("default", new FallbackBinaryOperator(empty, fallback).apply("input1", "input2")); + verify(empty, only()).apply("input1", "input2"); + verify(fallback, only()).get(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackBooleanSupplierTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackBooleanSupplierTest.java index f60484b..a8a8f47 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackBooleanSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackBooleanSupplierTest.java @@ -8,24 +8,24 @@ import org.junit.jupiter.api.*; public class FallbackBooleanSupplierTest { - @Test - public void full() { - OptionalBooleanSupplier full = mock(OptionalBooleanSupplier.class); - when(full.get()).thenReturn(OptionalBoolean.of(true)); - BooleanSupplier fallback = mock(BooleanSupplier.class); - when(fallback.getAsBoolean()).thenReturn(false); - assertEquals(true, new FallbackBooleanSupplier(full, fallback).getAsBoolean()); - verify(full, only()).get(); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalBooleanSupplier empty = mock(OptionalBooleanSupplier.class); - when(empty.get()).thenReturn(OptionalBoolean.empty()); - BooleanSupplier fallback = mock(BooleanSupplier.class); - when(fallback.getAsBoolean()).thenReturn(false); - assertEquals(false, new FallbackBooleanSupplier(empty, fallback).getAsBoolean()); - verify(empty, only()).get(); - verify(fallback, only()).getAsBoolean(); - } + @Test + public void full() { + OptionalBooleanSupplier full = mock(OptionalBooleanSupplier.class); + when(full.get()).thenReturn(OptionalBoolean.of(true)); + BooleanSupplier fallback = mock(BooleanSupplier.class); + when(fallback.getAsBoolean()).thenReturn(false); + assertEquals(true, new FallbackBooleanSupplier(full, fallback).getAsBoolean()); + verify(full, only()).get(); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalBooleanSupplier empty = mock(OptionalBooleanSupplier.class); + when(empty.get()).thenReturn(OptionalBoolean.empty()); + BooleanSupplier fallback = mock(BooleanSupplier.class); + when(fallback.getAsBoolean()).thenReturn(false); + assertEquals(false, new FallbackBooleanSupplier(empty, fallback).getAsBoolean()); + verify(empty, only()).get(); + verify(fallback, only()).getAsBoolean(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackComparatorTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackComparatorTest.java index f916ba0..2cf0e4d 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackComparatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackComparatorTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackComparatorTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalComparator full = mock(OptionalComparator.class); - when(full.compare("input1", "input2")).thenReturn(OptionalInt.of(2)); - IntSupplier fallback = mock(IntSupplier.class); - when(fallback.getAsInt()).thenReturn(3); - assertEquals(2, new FallbackComparator(full, fallback).compare("input1", "input2")); - verify(full, only()).compare("input1", "input2"); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalComparator empty = mock(OptionalComparator.class); - when(empty.compare("input1", "input2")).thenReturn(OptionalInt.empty()); - IntSupplier fallback = mock(IntSupplier.class); - when(fallback.getAsInt()).thenReturn(3); - assertEquals(3, new FallbackComparator(empty, fallback).compare("input1", "input2")); - verify(empty, only()).compare("input1", "input2"); - verify(fallback, only()).getAsInt(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalComparator full = mock(OptionalComparator.class); + when(full.compare("input1", "input2")).thenReturn(OptionalInt.of(2)); + IntSupplier fallback = mock(IntSupplier.class); + when(fallback.getAsInt()).thenReturn(3); + assertEquals(2, new FallbackComparator(full, fallback).compare("input1", "input2")); + verify(full, only()).compare("input1", "input2"); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalComparator empty = mock(OptionalComparator.class); + when(empty.compare("input1", "input2")).thenReturn(OptionalInt.empty()); + IntSupplier fallback = mock(IntSupplier.class); + when(fallback.getAsInt()).thenReturn(3); + assertEquals(3, new FallbackComparator(empty, fallback).compare("input1", "input2")); + verify(empty, only()).compare("input1", "input2"); + verify(fallback, only()).getAsInt(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleBinaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleBinaryOperatorTest.java index 4168582..b70fdf1 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleBinaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleBinaryOperatorTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackDoubleBinaryOperatorTest { - @Test - public void full() { - OptionalDoubleBinaryOperator full = mock(OptionalDoubleBinaryOperator.class); - when(full.apply(1.1, 1.2)).thenReturn(OptionalDouble.of(2.0)); - DoubleSupplier fallback = mock(DoubleSupplier.class); - when(fallback.getAsDouble()).thenReturn(3.0); - assertEquals(2.0, new FallbackDoubleBinaryOperator(full, fallback).applyAsDouble(1.1, 1.2), 0.1); - verify(full, only()).apply(1.1, 1.2); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalDoubleBinaryOperator empty = mock(OptionalDoubleBinaryOperator.class); - when(empty.apply(1.1, 1.2)).thenReturn(OptionalDouble.empty()); - DoubleSupplier fallback = mock(DoubleSupplier.class); - when(fallback.getAsDouble()).thenReturn(3.0); - assertEquals(3.0, new FallbackDoubleBinaryOperator(empty, fallback).applyAsDouble(1.1, 1.2), 0.1); - verify(empty, only()).apply(1.1, 1.2); - verify(fallback, only()).getAsDouble(); - } + @Test + public void full() { + OptionalDoubleBinaryOperator full = mock(OptionalDoubleBinaryOperator.class); + when(full.apply(1.1, 1.2)).thenReturn(OptionalDouble.of(2.0)); + DoubleSupplier fallback = mock(DoubleSupplier.class); + when(fallback.getAsDouble()).thenReturn(3.0); + assertEquals(2.0, new FallbackDoubleBinaryOperator(full, fallback).applyAsDouble(1.1, 1.2), 0.1); + verify(full, only()).apply(1.1, 1.2); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalDoubleBinaryOperator empty = mock(OptionalDoubleBinaryOperator.class); + when(empty.apply(1.1, 1.2)).thenReturn(OptionalDouble.empty()); + DoubleSupplier fallback = mock(DoubleSupplier.class); + when(fallback.getAsDouble()).thenReturn(3.0); + assertEquals(3.0, new FallbackDoubleBinaryOperator(empty, fallback).applyAsDouble(1.1, 1.2), 0.1); + verify(empty, only()).apply(1.1, 1.2); + verify(fallback, only()).getAsDouble(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleFunctionTest.java index d2901a1..7100ded 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleFunctionTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackDoubleFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalDoubleFunction full = mock(OptionalDoubleFunction.class); - when(full.apply(1.0)).thenReturn(Optional.of("value")); - @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); - when(fallback.get()).thenReturn("default"); - assertEquals("value", new FallbackDoubleFunction(full, fallback).apply(1.0)); - verify(full, only()).apply(1.0); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalDoubleFunction empty = mock(OptionalDoubleFunction.class); - when(empty.apply(1.0)).thenReturn(Optional.empty()); - @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); - when(fallback.get()).thenReturn("default"); - assertEquals("default", new FallbackDoubleFunction(empty, fallback).apply(1.0)); - verify(empty, only()).apply(1.0); - verify(fallback, only()).get(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalDoubleFunction full = mock(OptionalDoubleFunction.class); + when(full.apply(1.0)).thenReturn(Optional.of("value")); + @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); + when(fallback.get()).thenReturn("default"); + assertEquals("value", new FallbackDoubleFunction(full, fallback).apply(1.0)); + verify(full, only()).apply(1.0); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalDoubleFunction empty = mock(OptionalDoubleFunction.class); + when(empty.apply(1.0)).thenReturn(Optional.empty()); + @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); + when(fallback.get()).thenReturn("default"); + assertEquals("default", new FallbackDoubleFunction(empty, fallback).apply(1.0)); + verify(empty, only()).apply(1.0); + verify(fallback, only()).get(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackDoublePredicateTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackDoublePredicateTest.java index b499d7d..a8d5db2 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackDoublePredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackDoublePredicateTest.java @@ -8,24 +8,24 @@ import org.junit.jupiter.api.*; public class FallbackDoublePredicateTest { - @Test - public void full() { - OptionalDoublePredicate full = mock(OptionalDoublePredicate.class); - when(full.test(1.0)).thenReturn(OptionalBoolean.of(true)); - BooleanSupplier fallback = mock(BooleanSupplier.class); - when(fallback.getAsBoolean()).thenReturn(false); - assertEquals(true, new FallbackDoublePredicate(full, fallback).test(1.0)); - verify(full, only()).test(1.0); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalDoublePredicate empty = mock(OptionalDoublePredicate.class); - when(empty.test(1.0)).thenReturn(OptionalBoolean.empty()); - BooleanSupplier fallback = mock(BooleanSupplier.class); - when(fallback.getAsBoolean()).thenReturn(false); - assertEquals(false, new FallbackDoublePredicate(empty, fallback).test(1.0)); - verify(empty, only()).test(1.0); - verify(fallback, only()).getAsBoolean(); - } + @Test + public void full() { + OptionalDoublePredicate full = mock(OptionalDoublePredicate.class); + when(full.test(1.0)).thenReturn(OptionalBoolean.of(true)); + BooleanSupplier fallback = mock(BooleanSupplier.class); + when(fallback.getAsBoolean()).thenReturn(false); + assertEquals(true, new FallbackDoublePredicate(full, fallback).test(1.0)); + verify(full, only()).test(1.0); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalDoublePredicate empty = mock(OptionalDoublePredicate.class); + when(empty.test(1.0)).thenReturn(OptionalBoolean.empty()); + BooleanSupplier fallback = mock(BooleanSupplier.class); + when(fallback.getAsBoolean()).thenReturn(false); + assertEquals(false, new FallbackDoublePredicate(empty, fallback).test(1.0)); + verify(empty, only()).test(1.0); + verify(fallback, only()).getAsBoolean(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleSupplierTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleSupplierTest.java index f0f6c80..f0cf67e 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleSupplierTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackDoubleSupplierTest { - @Test - public void full() { - OptionalDoubleSupplier full = mock(OptionalDoubleSupplier.class); - when(full.get()).thenReturn(OptionalDouble.of(2.0)); - DoubleSupplier fallback = mock(DoubleSupplier.class); - when(fallback.getAsDouble()).thenReturn(3.0); - assertEquals(2.0, new FallbackDoubleSupplier(full, fallback).getAsDouble(), 0.1); - verify(full, only()).get(); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalDoubleSupplier empty = mock(OptionalDoubleSupplier.class); - when(empty.get()).thenReturn(OptionalDouble.empty()); - DoubleSupplier fallback = mock(DoubleSupplier.class); - when(fallback.getAsDouble()).thenReturn(3.0); - assertEquals(3.0, new FallbackDoubleSupplier(empty, fallback).getAsDouble(), 0.1); - verify(empty, only()).get(); - verify(fallback, only()).getAsDouble(); - } + @Test + public void full() { + OptionalDoubleSupplier full = mock(OptionalDoubleSupplier.class); + when(full.get()).thenReturn(OptionalDouble.of(2.0)); + DoubleSupplier fallback = mock(DoubleSupplier.class); + when(fallback.getAsDouble()).thenReturn(3.0); + assertEquals(2.0, new FallbackDoubleSupplier(full, fallback).getAsDouble(), 0.1); + verify(full, only()).get(); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalDoubleSupplier empty = mock(OptionalDoubleSupplier.class); + when(empty.get()).thenReturn(OptionalDouble.empty()); + DoubleSupplier fallback = mock(DoubleSupplier.class); + when(fallback.getAsDouble()).thenReturn(3.0); + assertEquals(3.0, new FallbackDoubleSupplier(empty, fallback).getAsDouble(), 0.1); + verify(empty, only()).get(); + verify(fallback, only()).getAsDouble(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleToIntFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleToIntFunctionTest.java index 1a9f58e..5468e14 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleToIntFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleToIntFunctionTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackDoubleToIntFunctionTest { - @Test - public void full() { - OptionalDoubleToIntFunction full = mock(OptionalDoubleToIntFunction.class); - when(full.apply(1.0)).thenReturn(OptionalInt.of(2)); - IntSupplier fallback = mock(IntSupplier.class); - when(fallback.getAsInt()).thenReturn(3); - assertEquals(2, new FallbackDoubleToIntFunction(full, fallback).applyAsInt(1.0)); - verify(full, only()).apply(1.0); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalDoubleToIntFunction empty = mock(OptionalDoubleToIntFunction.class); - when(empty.apply(1.0)).thenReturn(OptionalInt.empty()); - IntSupplier fallback = mock(IntSupplier.class); - when(fallback.getAsInt()).thenReturn(3); - assertEquals(3, new FallbackDoubleToIntFunction(empty, fallback).applyAsInt(1.0)); - verify(empty, only()).apply(1.0); - verify(fallback, only()).getAsInt(); - } + @Test + public void full() { + OptionalDoubleToIntFunction full = mock(OptionalDoubleToIntFunction.class); + when(full.apply(1.0)).thenReturn(OptionalInt.of(2)); + IntSupplier fallback = mock(IntSupplier.class); + when(fallback.getAsInt()).thenReturn(3); + assertEquals(2, new FallbackDoubleToIntFunction(full, fallback).applyAsInt(1.0)); + verify(full, only()).apply(1.0); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalDoubleToIntFunction empty = mock(OptionalDoubleToIntFunction.class); + when(empty.apply(1.0)).thenReturn(OptionalInt.empty()); + IntSupplier fallback = mock(IntSupplier.class); + when(fallback.getAsInt()).thenReturn(3); + assertEquals(3, new FallbackDoubleToIntFunction(empty, fallback).applyAsInt(1.0)); + verify(empty, only()).apply(1.0); + verify(fallback, only()).getAsInt(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleToLongFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleToLongFunctionTest.java index 36b971c..a4256d6 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleToLongFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleToLongFunctionTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackDoubleToLongFunctionTest { - @Test - public void full() { - OptionalDoubleToLongFunction full = mock(OptionalDoubleToLongFunction.class); - when(full.apply(1.0)).thenReturn(OptionalLong.of(2L)); - LongSupplier fallback = mock(LongSupplier.class); - when(fallback.getAsLong()).thenReturn(3L); - assertEquals(2L, new FallbackDoubleToLongFunction(full, fallback).applyAsLong(1.0)); - verify(full, only()).apply(1.0); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalDoubleToLongFunction empty = mock(OptionalDoubleToLongFunction.class); - when(empty.apply(1.0)).thenReturn(OptionalLong.empty()); - LongSupplier fallback = mock(LongSupplier.class); - when(fallback.getAsLong()).thenReturn(3L); - assertEquals(3L, new FallbackDoubleToLongFunction(empty, fallback).applyAsLong(1.0)); - verify(empty, only()).apply(1.0); - verify(fallback, only()).getAsLong(); - } + @Test + public void full() { + OptionalDoubleToLongFunction full = mock(OptionalDoubleToLongFunction.class); + when(full.apply(1.0)).thenReturn(OptionalLong.of(2L)); + LongSupplier fallback = mock(LongSupplier.class); + when(fallback.getAsLong()).thenReturn(3L); + assertEquals(2L, new FallbackDoubleToLongFunction(full, fallback).applyAsLong(1.0)); + verify(full, only()).apply(1.0); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalDoubleToLongFunction empty = mock(OptionalDoubleToLongFunction.class); + when(empty.apply(1.0)).thenReturn(OptionalLong.empty()); + LongSupplier fallback = mock(LongSupplier.class); + when(fallback.getAsLong()).thenReturn(3L); + assertEquals(3L, new FallbackDoubleToLongFunction(empty, fallback).applyAsLong(1.0)); + verify(empty, only()).apply(1.0); + verify(fallback, only()).getAsLong(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleUnaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleUnaryOperatorTest.java index 461ae4b..851c1ef 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleUnaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackDoubleUnaryOperatorTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackDoubleUnaryOperatorTest { - @Test - public void full() { - OptionalDoubleUnaryOperator full = mock(OptionalDoubleUnaryOperator.class); - when(full.apply(1.0)).thenReturn(OptionalDouble.of(2.0)); - DoubleSupplier fallback = mock(DoubleSupplier.class); - when(fallback.getAsDouble()).thenReturn(3.0); - assertEquals(2.0, new FallbackDoubleUnaryOperator(full, fallback).applyAsDouble(1.0), 0.1); - verify(full, only()).apply(1.0); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalDoubleUnaryOperator empty = mock(OptionalDoubleUnaryOperator.class); - when(empty.apply(1.0)).thenReturn(OptionalDouble.empty()); - DoubleSupplier fallback = mock(DoubleSupplier.class); - when(fallback.getAsDouble()).thenReturn(3.0); - assertEquals(3.0, new FallbackDoubleUnaryOperator(empty, fallback).applyAsDouble(1.0), 0.1); - verify(empty, only()).apply(1.0); - verify(fallback, only()).getAsDouble(); - } + @Test + public void full() { + OptionalDoubleUnaryOperator full = mock(OptionalDoubleUnaryOperator.class); + when(full.apply(1.0)).thenReturn(OptionalDouble.of(2.0)); + DoubleSupplier fallback = mock(DoubleSupplier.class); + when(fallback.getAsDouble()).thenReturn(3.0); + assertEquals(2.0, new FallbackDoubleUnaryOperator(full, fallback).applyAsDouble(1.0), 0.1); + verify(full, only()).apply(1.0); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalDoubleUnaryOperator empty = mock(OptionalDoubleUnaryOperator.class); + when(empty.apply(1.0)).thenReturn(OptionalDouble.empty()); + DoubleSupplier fallback = mock(DoubleSupplier.class); + when(fallback.getAsDouble()).thenReturn(3.0); + assertEquals(3.0, new FallbackDoubleUnaryOperator(empty, fallback).applyAsDouble(1.0), 0.1); + verify(empty, only()).apply(1.0); + verify(fallback, only()).getAsDouble(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackFunctionTest.java index d95932e..5e90e0a 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackFunctionTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalFunction full = mock(OptionalFunction.class); - when(full.apply("input")).thenReturn(Optional.of("value")); - @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); - when(fallback.get()).thenReturn("default"); - assertEquals("value", new FallbackFunction(full, fallback).apply("input")); - verify(full, only()).apply("input"); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalFunction empty = mock(OptionalFunction.class); - when(empty.apply("input")).thenReturn(Optional.empty()); - @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); - when(fallback.get()).thenReturn("default"); - assertEquals("default", new FallbackFunction(empty, fallback).apply("input")); - verify(empty, only()).apply("input"); - verify(fallback, only()).get(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalFunction full = mock(OptionalFunction.class); + when(full.apply("input")).thenReturn(Optional.of("value")); + @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); + when(fallback.get()).thenReturn("default"); + assertEquals("value", new FallbackFunction(full, fallback).apply("input")); + verify(full, only()).apply("input"); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalFunction empty = mock(OptionalFunction.class); + when(empty.apply("input")).thenReturn(Optional.empty()); + @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); + when(fallback.get()).thenReturn("default"); + assertEquals("default", new FallbackFunction(empty, fallback).apply("input")); + verify(empty, only()).apply("input"); + verify(fallback, only()).get(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackIntBinaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackIntBinaryOperatorTest.java index 8de6735..8659056 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackIntBinaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackIntBinaryOperatorTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackIntBinaryOperatorTest { - @Test - public void full() { - OptionalIntBinaryOperator full = mock(OptionalIntBinaryOperator.class); - when(full.apply(11, 12)).thenReturn(OptionalInt.of(2)); - IntSupplier fallback = mock(IntSupplier.class); - when(fallback.getAsInt()).thenReturn(3); - assertEquals(2, new FallbackIntBinaryOperator(full, fallback).applyAsInt(11, 12)); - verify(full, only()).apply(11, 12); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalIntBinaryOperator empty = mock(OptionalIntBinaryOperator.class); - when(empty.apply(11, 12)).thenReturn(OptionalInt.empty()); - IntSupplier fallback = mock(IntSupplier.class); - when(fallback.getAsInt()).thenReturn(3); - assertEquals(3, new FallbackIntBinaryOperator(empty, fallback).applyAsInt(11, 12)); - verify(empty, only()).apply(11, 12); - verify(fallback, only()).getAsInt(); - } + @Test + public void full() { + OptionalIntBinaryOperator full = mock(OptionalIntBinaryOperator.class); + when(full.apply(11, 12)).thenReturn(OptionalInt.of(2)); + IntSupplier fallback = mock(IntSupplier.class); + when(fallback.getAsInt()).thenReturn(3); + assertEquals(2, new FallbackIntBinaryOperator(full, fallback).applyAsInt(11, 12)); + verify(full, only()).apply(11, 12); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalIntBinaryOperator empty = mock(OptionalIntBinaryOperator.class); + when(empty.apply(11, 12)).thenReturn(OptionalInt.empty()); + IntSupplier fallback = mock(IntSupplier.class); + when(fallback.getAsInt()).thenReturn(3); + assertEquals(3, new FallbackIntBinaryOperator(empty, fallback).applyAsInt(11, 12)); + verify(empty, only()).apply(11, 12); + verify(fallback, only()).getAsInt(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackIntFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackIntFunctionTest.java index b92ccb5..9e6fecb 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackIntFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackIntFunctionTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackIntFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalIntFunction full = mock(OptionalIntFunction.class); - when(full.apply(1)).thenReturn(Optional.of("value")); - @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); - when(fallback.get()).thenReturn("default"); - assertEquals("value", new FallbackIntFunction(full, fallback).apply(1)); - verify(full, only()).apply(1); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalIntFunction empty = mock(OptionalIntFunction.class); - when(empty.apply(1)).thenReturn(Optional.empty()); - @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); - when(fallback.get()).thenReturn("default"); - assertEquals("default", new FallbackIntFunction(empty, fallback).apply(1)); - verify(empty, only()).apply(1); - verify(fallback, only()).get(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalIntFunction full = mock(OptionalIntFunction.class); + when(full.apply(1)).thenReturn(Optional.of("value")); + @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); + when(fallback.get()).thenReturn("default"); + assertEquals("value", new FallbackIntFunction(full, fallback).apply(1)); + verify(full, only()).apply(1); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalIntFunction empty = mock(OptionalIntFunction.class); + when(empty.apply(1)).thenReturn(Optional.empty()); + @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); + when(fallback.get()).thenReturn("default"); + assertEquals("default", new FallbackIntFunction(empty, fallback).apply(1)); + verify(empty, only()).apply(1); + verify(fallback, only()).get(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackIntPredicateTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackIntPredicateTest.java index ae21b58..ab5f754 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackIntPredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackIntPredicateTest.java @@ -8,24 +8,24 @@ import org.junit.jupiter.api.*; public class FallbackIntPredicateTest { - @Test - public void full() { - OptionalIntPredicate full = mock(OptionalIntPredicate.class); - when(full.test(1)).thenReturn(OptionalBoolean.of(true)); - BooleanSupplier fallback = mock(BooleanSupplier.class); - when(fallback.getAsBoolean()).thenReturn(false); - assertEquals(true, new FallbackIntPredicate(full, fallback).test(1)); - verify(full, only()).test(1); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalIntPredicate empty = mock(OptionalIntPredicate.class); - when(empty.test(1)).thenReturn(OptionalBoolean.empty()); - BooleanSupplier fallback = mock(BooleanSupplier.class); - when(fallback.getAsBoolean()).thenReturn(false); - assertEquals(false, new FallbackIntPredicate(empty, fallback).test(1)); - verify(empty, only()).test(1); - verify(fallback, only()).getAsBoolean(); - } + @Test + public void full() { + OptionalIntPredicate full = mock(OptionalIntPredicate.class); + when(full.test(1)).thenReturn(OptionalBoolean.of(true)); + BooleanSupplier fallback = mock(BooleanSupplier.class); + when(fallback.getAsBoolean()).thenReturn(false); + assertEquals(true, new FallbackIntPredicate(full, fallback).test(1)); + verify(full, only()).test(1); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalIntPredicate empty = mock(OptionalIntPredicate.class); + when(empty.test(1)).thenReturn(OptionalBoolean.empty()); + BooleanSupplier fallback = mock(BooleanSupplier.class); + when(fallback.getAsBoolean()).thenReturn(false); + assertEquals(false, new FallbackIntPredicate(empty, fallback).test(1)); + verify(empty, only()).test(1); + verify(fallback, only()).getAsBoolean(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackIntSupplierTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackIntSupplierTest.java index c06585b..e048b3d 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackIntSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackIntSupplierTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackIntSupplierTest { - @Test - public void full() { - OptionalIntSupplier full = mock(OptionalIntSupplier.class); - when(full.get()).thenReturn(OptionalInt.of(2)); - IntSupplier fallback = mock(IntSupplier.class); - when(fallback.getAsInt()).thenReturn(3); - assertEquals(2, new FallbackIntSupplier(full, fallback).getAsInt()); - verify(full, only()).get(); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalIntSupplier empty = mock(OptionalIntSupplier.class); - when(empty.get()).thenReturn(OptionalInt.empty()); - IntSupplier fallback = mock(IntSupplier.class); - when(fallback.getAsInt()).thenReturn(3); - assertEquals(3, new FallbackIntSupplier(empty, fallback).getAsInt()); - verify(empty, only()).get(); - verify(fallback, only()).getAsInt(); - } + @Test + public void full() { + OptionalIntSupplier full = mock(OptionalIntSupplier.class); + when(full.get()).thenReturn(OptionalInt.of(2)); + IntSupplier fallback = mock(IntSupplier.class); + when(fallback.getAsInt()).thenReturn(3); + assertEquals(2, new FallbackIntSupplier(full, fallback).getAsInt()); + verify(full, only()).get(); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalIntSupplier empty = mock(OptionalIntSupplier.class); + when(empty.get()).thenReturn(OptionalInt.empty()); + IntSupplier fallback = mock(IntSupplier.class); + when(fallback.getAsInt()).thenReturn(3); + assertEquals(3, new FallbackIntSupplier(empty, fallback).getAsInt()); + verify(empty, only()).get(); + verify(fallback, only()).getAsInt(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackIntToDoubleFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackIntToDoubleFunctionTest.java index 0cc3d34..9c0a020 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackIntToDoubleFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackIntToDoubleFunctionTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackIntToDoubleFunctionTest { - @Test - public void full() { - OptionalIntToDoubleFunction full = mock(OptionalIntToDoubleFunction.class); - when(full.apply(1)).thenReturn(OptionalDouble.of(2.0)); - DoubleSupplier fallback = mock(DoubleSupplier.class); - when(fallback.getAsDouble()).thenReturn(3.0); - assertEquals(2.0, new FallbackIntToDoubleFunction(full, fallback).applyAsDouble(1), 0.1); - verify(full, only()).apply(1); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalIntToDoubleFunction empty = mock(OptionalIntToDoubleFunction.class); - when(empty.apply(1)).thenReturn(OptionalDouble.empty()); - DoubleSupplier fallback = mock(DoubleSupplier.class); - when(fallback.getAsDouble()).thenReturn(3.0); - assertEquals(3.0, new FallbackIntToDoubleFunction(empty, fallback).applyAsDouble(1), 0.1); - verify(empty, only()).apply(1); - verify(fallback, only()).getAsDouble(); - } + @Test + public void full() { + OptionalIntToDoubleFunction full = mock(OptionalIntToDoubleFunction.class); + when(full.apply(1)).thenReturn(OptionalDouble.of(2.0)); + DoubleSupplier fallback = mock(DoubleSupplier.class); + when(fallback.getAsDouble()).thenReturn(3.0); + assertEquals(2.0, new FallbackIntToDoubleFunction(full, fallback).applyAsDouble(1), 0.1); + verify(full, only()).apply(1); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalIntToDoubleFunction empty = mock(OptionalIntToDoubleFunction.class); + when(empty.apply(1)).thenReturn(OptionalDouble.empty()); + DoubleSupplier fallback = mock(DoubleSupplier.class); + when(fallback.getAsDouble()).thenReturn(3.0); + assertEquals(3.0, new FallbackIntToDoubleFunction(empty, fallback).applyAsDouble(1), 0.1); + verify(empty, only()).apply(1); + verify(fallback, only()).getAsDouble(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackIntToLongFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackIntToLongFunctionTest.java index 144c124..53cb710 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackIntToLongFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackIntToLongFunctionTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackIntToLongFunctionTest { - @Test - public void full() { - OptionalIntToLongFunction full = mock(OptionalIntToLongFunction.class); - when(full.apply(1)).thenReturn(OptionalLong.of(2L)); - LongSupplier fallback = mock(LongSupplier.class); - when(fallback.getAsLong()).thenReturn(3L); - assertEquals(2L, new FallbackIntToLongFunction(full, fallback).applyAsLong(1)); - verify(full, only()).apply(1); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalIntToLongFunction empty = mock(OptionalIntToLongFunction.class); - when(empty.apply(1)).thenReturn(OptionalLong.empty()); - LongSupplier fallback = mock(LongSupplier.class); - when(fallback.getAsLong()).thenReturn(3L); - assertEquals(3L, new FallbackIntToLongFunction(empty, fallback).applyAsLong(1)); - verify(empty, only()).apply(1); - verify(fallback, only()).getAsLong(); - } + @Test + public void full() { + OptionalIntToLongFunction full = mock(OptionalIntToLongFunction.class); + when(full.apply(1)).thenReturn(OptionalLong.of(2L)); + LongSupplier fallback = mock(LongSupplier.class); + when(fallback.getAsLong()).thenReturn(3L); + assertEquals(2L, new FallbackIntToLongFunction(full, fallback).applyAsLong(1)); + verify(full, only()).apply(1); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalIntToLongFunction empty = mock(OptionalIntToLongFunction.class); + when(empty.apply(1)).thenReturn(OptionalLong.empty()); + LongSupplier fallback = mock(LongSupplier.class); + when(fallback.getAsLong()).thenReturn(3L); + assertEquals(3L, new FallbackIntToLongFunction(empty, fallback).applyAsLong(1)); + verify(empty, only()).apply(1); + verify(fallback, only()).getAsLong(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackIntUnaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackIntUnaryOperatorTest.java index e4f9e8b..78d0a9e 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackIntUnaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackIntUnaryOperatorTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackIntUnaryOperatorTest { - @Test - public void full() { - OptionalIntUnaryOperator full = mock(OptionalIntUnaryOperator.class); - when(full.apply(1)).thenReturn(OptionalInt.of(2)); - IntSupplier fallback = mock(IntSupplier.class); - when(fallback.getAsInt()).thenReturn(3); - assertEquals(2, new FallbackIntUnaryOperator(full, fallback).applyAsInt(1)); - verify(full, only()).apply(1); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalIntUnaryOperator empty = mock(OptionalIntUnaryOperator.class); - when(empty.apply(1)).thenReturn(OptionalInt.empty()); - IntSupplier fallback = mock(IntSupplier.class); - when(fallback.getAsInt()).thenReturn(3); - assertEquals(3, new FallbackIntUnaryOperator(empty, fallback).applyAsInt(1)); - verify(empty, only()).apply(1); - verify(fallback, only()).getAsInt(); - } + @Test + public void full() { + OptionalIntUnaryOperator full = mock(OptionalIntUnaryOperator.class); + when(full.apply(1)).thenReturn(OptionalInt.of(2)); + IntSupplier fallback = mock(IntSupplier.class); + when(fallback.getAsInt()).thenReturn(3); + assertEquals(2, new FallbackIntUnaryOperator(full, fallback).applyAsInt(1)); + verify(full, only()).apply(1); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalIntUnaryOperator empty = mock(OptionalIntUnaryOperator.class); + when(empty.apply(1)).thenReturn(OptionalInt.empty()); + IntSupplier fallback = mock(IntSupplier.class); + when(fallback.getAsInt()).thenReturn(3); + assertEquals(3, new FallbackIntUnaryOperator(empty, fallback).applyAsInt(1)); + verify(empty, only()).apply(1); + verify(fallback, only()).getAsInt(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackLongBinaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackLongBinaryOperatorTest.java index d988c57..0b29c2a 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackLongBinaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackLongBinaryOperatorTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackLongBinaryOperatorTest { - @Test - public void full() { - OptionalLongBinaryOperator full = mock(OptionalLongBinaryOperator.class); - when(full.apply(11L, 12L)).thenReturn(OptionalLong.of(2L)); - LongSupplier fallback = mock(LongSupplier.class); - when(fallback.getAsLong()).thenReturn(3L); - assertEquals(2L, new FallbackLongBinaryOperator(full, fallback).applyAsLong(11L, 12L)); - verify(full, only()).apply(11L, 12L); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalLongBinaryOperator empty = mock(OptionalLongBinaryOperator.class); - when(empty.apply(11L, 12L)).thenReturn(OptionalLong.empty()); - LongSupplier fallback = mock(LongSupplier.class); - when(fallback.getAsLong()).thenReturn(3L); - assertEquals(3L, new FallbackLongBinaryOperator(empty, fallback).applyAsLong(11L, 12L)); - verify(empty, only()).apply(11L, 12L); - verify(fallback, only()).getAsLong(); - } + @Test + public void full() { + OptionalLongBinaryOperator full = mock(OptionalLongBinaryOperator.class); + when(full.apply(11L, 12L)).thenReturn(OptionalLong.of(2L)); + LongSupplier fallback = mock(LongSupplier.class); + when(fallback.getAsLong()).thenReturn(3L); + assertEquals(2L, new FallbackLongBinaryOperator(full, fallback).applyAsLong(11L, 12L)); + verify(full, only()).apply(11L, 12L); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalLongBinaryOperator empty = mock(OptionalLongBinaryOperator.class); + when(empty.apply(11L, 12L)).thenReturn(OptionalLong.empty()); + LongSupplier fallback = mock(LongSupplier.class); + when(fallback.getAsLong()).thenReturn(3L); + assertEquals(3L, new FallbackLongBinaryOperator(empty, fallback).applyAsLong(11L, 12L)); + verify(empty, only()).apply(11L, 12L); + verify(fallback, only()).getAsLong(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackLongFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackLongFunctionTest.java index 97c2aaa..2d38d45 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackLongFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackLongFunctionTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackLongFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalLongFunction full = mock(OptionalLongFunction.class); - when(full.apply(1L)).thenReturn(Optional.of("value")); - @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); - when(fallback.get()).thenReturn("default"); - assertEquals("value", new FallbackLongFunction(full, fallback).apply(1L)); - verify(full, only()).apply(1L); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalLongFunction empty = mock(OptionalLongFunction.class); - when(empty.apply(1L)).thenReturn(Optional.empty()); - @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); - when(fallback.get()).thenReturn("default"); - assertEquals("default", new FallbackLongFunction(empty, fallback).apply(1L)); - verify(empty, only()).apply(1L); - verify(fallback, only()).get(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalLongFunction full = mock(OptionalLongFunction.class); + when(full.apply(1L)).thenReturn(Optional.of("value")); + @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); + when(fallback.get()).thenReturn("default"); + assertEquals("value", new FallbackLongFunction(full, fallback).apply(1L)); + verify(full, only()).apply(1L); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalLongFunction empty = mock(OptionalLongFunction.class); + when(empty.apply(1L)).thenReturn(Optional.empty()); + @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); + when(fallback.get()).thenReturn("default"); + assertEquals("default", new FallbackLongFunction(empty, fallback).apply(1L)); + verify(empty, only()).apply(1L); + verify(fallback, only()).get(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackLongPredicateTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackLongPredicateTest.java index 2656de2..ad04a55 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackLongPredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackLongPredicateTest.java @@ -8,24 +8,24 @@ import org.junit.jupiter.api.*; public class FallbackLongPredicateTest { - @Test - public void full() { - OptionalLongPredicate full = mock(OptionalLongPredicate.class); - when(full.test(1L)).thenReturn(OptionalBoolean.of(true)); - BooleanSupplier fallback = mock(BooleanSupplier.class); - when(fallback.getAsBoolean()).thenReturn(false); - assertEquals(true, new FallbackLongPredicate(full, fallback).test(1L)); - verify(full, only()).test(1L); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalLongPredicate empty = mock(OptionalLongPredicate.class); - when(empty.test(1L)).thenReturn(OptionalBoolean.empty()); - BooleanSupplier fallback = mock(BooleanSupplier.class); - when(fallback.getAsBoolean()).thenReturn(false); - assertEquals(false, new FallbackLongPredicate(empty, fallback).test(1L)); - verify(empty, only()).test(1L); - verify(fallback, only()).getAsBoolean(); - } + @Test + public void full() { + OptionalLongPredicate full = mock(OptionalLongPredicate.class); + when(full.test(1L)).thenReturn(OptionalBoolean.of(true)); + BooleanSupplier fallback = mock(BooleanSupplier.class); + when(fallback.getAsBoolean()).thenReturn(false); + assertEquals(true, new FallbackLongPredicate(full, fallback).test(1L)); + verify(full, only()).test(1L); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalLongPredicate empty = mock(OptionalLongPredicate.class); + when(empty.test(1L)).thenReturn(OptionalBoolean.empty()); + BooleanSupplier fallback = mock(BooleanSupplier.class); + when(fallback.getAsBoolean()).thenReturn(false); + assertEquals(false, new FallbackLongPredicate(empty, fallback).test(1L)); + verify(empty, only()).test(1L); + verify(fallback, only()).getAsBoolean(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackLongSupplierTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackLongSupplierTest.java index 9c12290..0ef4c2b 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackLongSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackLongSupplierTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackLongSupplierTest { - @Test - public void full() { - OptionalLongSupplier full = mock(OptionalLongSupplier.class); - when(full.get()).thenReturn(OptionalLong.of(2L)); - LongSupplier fallback = mock(LongSupplier.class); - when(fallback.getAsLong()).thenReturn(3L); - assertEquals(2L, new FallbackLongSupplier(full, fallback).getAsLong()); - verify(full, only()).get(); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalLongSupplier empty = mock(OptionalLongSupplier.class); - when(empty.get()).thenReturn(OptionalLong.empty()); - LongSupplier fallback = mock(LongSupplier.class); - when(fallback.getAsLong()).thenReturn(3L); - assertEquals(3L, new FallbackLongSupplier(empty, fallback).getAsLong()); - verify(empty, only()).get(); - verify(fallback, only()).getAsLong(); - } + @Test + public void full() { + OptionalLongSupplier full = mock(OptionalLongSupplier.class); + when(full.get()).thenReturn(OptionalLong.of(2L)); + LongSupplier fallback = mock(LongSupplier.class); + when(fallback.getAsLong()).thenReturn(3L); + assertEquals(2L, new FallbackLongSupplier(full, fallback).getAsLong()); + verify(full, only()).get(); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalLongSupplier empty = mock(OptionalLongSupplier.class); + when(empty.get()).thenReturn(OptionalLong.empty()); + LongSupplier fallback = mock(LongSupplier.class); + when(fallback.getAsLong()).thenReturn(3L); + assertEquals(3L, new FallbackLongSupplier(empty, fallback).getAsLong()); + verify(empty, only()).get(); + verify(fallback, only()).getAsLong(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackLongToDoubleFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackLongToDoubleFunctionTest.java index f01b85f..7408a1a 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackLongToDoubleFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackLongToDoubleFunctionTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackLongToDoubleFunctionTest { - @Test - public void full() { - OptionalLongToDoubleFunction full = mock(OptionalLongToDoubleFunction.class); - when(full.apply(1L)).thenReturn(OptionalDouble.of(2.0)); - DoubleSupplier fallback = mock(DoubleSupplier.class); - when(fallback.getAsDouble()).thenReturn(3.0); - assertEquals(2.0, new FallbackLongToDoubleFunction(full, fallback).applyAsDouble(1L), 0.1); - verify(full, only()).apply(1L); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalLongToDoubleFunction empty = mock(OptionalLongToDoubleFunction.class); - when(empty.apply(1L)).thenReturn(OptionalDouble.empty()); - DoubleSupplier fallback = mock(DoubleSupplier.class); - when(fallback.getAsDouble()).thenReturn(3.0); - assertEquals(3.0, new FallbackLongToDoubleFunction(empty, fallback).applyAsDouble(1L), 0.1); - verify(empty, only()).apply(1L); - verify(fallback, only()).getAsDouble(); - } + @Test + public void full() { + OptionalLongToDoubleFunction full = mock(OptionalLongToDoubleFunction.class); + when(full.apply(1L)).thenReturn(OptionalDouble.of(2.0)); + DoubleSupplier fallback = mock(DoubleSupplier.class); + when(fallback.getAsDouble()).thenReturn(3.0); + assertEquals(2.0, new FallbackLongToDoubleFunction(full, fallback).applyAsDouble(1L), 0.1); + verify(full, only()).apply(1L); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalLongToDoubleFunction empty = mock(OptionalLongToDoubleFunction.class); + when(empty.apply(1L)).thenReturn(OptionalDouble.empty()); + DoubleSupplier fallback = mock(DoubleSupplier.class); + when(fallback.getAsDouble()).thenReturn(3.0); + assertEquals(3.0, new FallbackLongToDoubleFunction(empty, fallback).applyAsDouble(1L), 0.1); + verify(empty, only()).apply(1L); + verify(fallback, only()).getAsDouble(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackLongToIntFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackLongToIntFunctionTest.java index dcf15d5..7b02c98 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackLongToIntFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackLongToIntFunctionTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackLongToIntFunctionTest { - @Test - public void full() { - OptionalLongToIntFunction full = mock(OptionalLongToIntFunction.class); - when(full.apply(1L)).thenReturn(OptionalInt.of(2)); - IntSupplier fallback = mock(IntSupplier.class); - when(fallback.getAsInt()).thenReturn(3); - assertEquals(2, new FallbackLongToIntFunction(full, fallback).applyAsInt(1L)); - verify(full, only()).apply(1L); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalLongToIntFunction empty = mock(OptionalLongToIntFunction.class); - when(empty.apply(1L)).thenReturn(OptionalInt.empty()); - IntSupplier fallback = mock(IntSupplier.class); - when(fallback.getAsInt()).thenReturn(3); - assertEquals(3, new FallbackLongToIntFunction(empty, fallback).applyAsInt(1L)); - verify(empty, only()).apply(1L); - verify(fallback, only()).getAsInt(); - } + @Test + public void full() { + OptionalLongToIntFunction full = mock(OptionalLongToIntFunction.class); + when(full.apply(1L)).thenReturn(OptionalInt.of(2)); + IntSupplier fallback = mock(IntSupplier.class); + when(fallback.getAsInt()).thenReturn(3); + assertEquals(2, new FallbackLongToIntFunction(full, fallback).applyAsInt(1L)); + verify(full, only()).apply(1L); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalLongToIntFunction empty = mock(OptionalLongToIntFunction.class); + when(empty.apply(1L)).thenReturn(OptionalInt.empty()); + IntSupplier fallback = mock(IntSupplier.class); + when(fallback.getAsInt()).thenReturn(3); + assertEquals(3, new FallbackLongToIntFunction(empty, fallback).applyAsInt(1L)); + verify(empty, only()).apply(1L); + verify(fallback, only()).getAsInt(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackLongUnaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackLongUnaryOperatorTest.java index 7861fe5..7a1d7d3 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackLongUnaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackLongUnaryOperatorTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackLongUnaryOperatorTest { - @Test - public void full() { - OptionalLongUnaryOperator full = mock(OptionalLongUnaryOperator.class); - when(full.apply(1L)).thenReturn(OptionalLong.of(2L)); - LongSupplier fallback = mock(LongSupplier.class); - when(fallback.getAsLong()).thenReturn(3L); - assertEquals(2L, new FallbackLongUnaryOperator(full, fallback).applyAsLong(1L)); - verify(full, only()).apply(1L); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - OptionalLongUnaryOperator empty = mock(OptionalLongUnaryOperator.class); - when(empty.apply(1L)).thenReturn(OptionalLong.empty()); - LongSupplier fallback = mock(LongSupplier.class); - when(fallback.getAsLong()).thenReturn(3L); - assertEquals(3L, new FallbackLongUnaryOperator(empty, fallback).applyAsLong(1L)); - verify(empty, only()).apply(1L); - verify(fallback, only()).getAsLong(); - } + @Test + public void full() { + OptionalLongUnaryOperator full = mock(OptionalLongUnaryOperator.class); + when(full.apply(1L)).thenReturn(OptionalLong.of(2L)); + LongSupplier fallback = mock(LongSupplier.class); + when(fallback.getAsLong()).thenReturn(3L); + assertEquals(2L, new FallbackLongUnaryOperator(full, fallback).applyAsLong(1L)); + verify(full, only()).apply(1L); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + OptionalLongUnaryOperator empty = mock(OptionalLongUnaryOperator.class); + when(empty.apply(1L)).thenReturn(OptionalLong.empty()); + LongSupplier fallback = mock(LongSupplier.class); + when(fallback.getAsLong()).thenReturn(3L); + assertEquals(3L, new FallbackLongUnaryOperator(empty, fallback).applyAsLong(1L)); + verify(empty, only()).apply(1L); + verify(fallback, only()).getAsLong(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackPredicateTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackPredicateTest.java index c1da413..d2eccfa 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackPredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackPredicateTest.java @@ -8,24 +8,24 @@ import org.junit.jupiter.api.*; public class FallbackPredicateTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalPredicate full = mock(OptionalPredicate.class); - when(full.test("input")).thenReturn(OptionalBoolean.of(true)); - BooleanSupplier fallback = mock(BooleanSupplier.class); - when(fallback.getAsBoolean()).thenReturn(false); - assertEquals(true, new FallbackPredicate(full, fallback).test("input")); - verify(full, only()).test("input"); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalPredicate empty = mock(OptionalPredicate.class); - when(empty.test("input")).thenReturn(OptionalBoolean.empty()); - BooleanSupplier fallback = mock(BooleanSupplier.class); - when(fallback.getAsBoolean()).thenReturn(false); - assertEquals(false, new FallbackPredicate(empty, fallback).test("input")); - verify(empty, only()).test("input"); - verify(fallback, only()).getAsBoolean(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalPredicate full = mock(OptionalPredicate.class); + when(full.test("input")).thenReturn(OptionalBoolean.of(true)); + BooleanSupplier fallback = mock(BooleanSupplier.class); + when(fallback.getAsBoolean()).thenReturn(false); + assertEquals(true, new FallbackPredicate(full, fallback).test("input")); + verify(full, only()).test("input"); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalPredicate empty = mock(OptionalPredicate.class); + when(empty.test("input")).thenReturn(OptionalBoolean.empty()); + BooleanSupplier fallback = mock(BooleanSupplier.class); + when(fallback.getAsBoolean()).thenReturn(false); + assertEquals(false, new FallbackPredicate(empty, fallback).test("input")); + verify(empty, only()).test("input"); + verify(fallback, only()).getAsBoolean(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackSupplierTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackSupplierTest.java index 3c123a2..6e513c9 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackSupplierTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackSupplierTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalSupplier full = mock(OptionalSupplier.class); - when(full.get()).thenReturn(Optional.of("value")); - @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); - when(fallback.get()).thenReturn("default"); - assertEquals("value", new FallbackSupplier(full, fallback).get()); - verify(full, only()).get(); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalSupplier empty = mock(OptionalSupplier.class); - when(empty.get()).thenReturn(Optional.empty()); - @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); - when(fallback.get()).thenReturn("default"); - assertEquals("default", new FallbackSupplier(empty, fallback).get()); - verify(empty, only()).get(); - verify(fallback, only()).get(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalSupplier full = mock(OptionalSupplier.class); + when(full.get()).thenReturn(Optional.of("value")); + @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); + when(fallback.get()).thenReturn("default"); + assertEquals("value", new FallbackSupplier(full, fallback).get()); + verify(full, only()).get(); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalSupplier empty = mock(OptionalSupplier.class); + when(empty.get()).thenReturn(Optional.empty()); + @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); + when(fallback.get()).thenReturn("default"); + assertEquals("default", new FallbackSupplier(empty, fallback).get()); + verify(empty, only()).get(); + verify(fallback, only()).get(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackToDoubleBiFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackToDoubleBiFunctionTest.java index 4c29946..4a2ac70 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackToDoubleBiFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackToDoubleBiFunctionTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackToDoubleBiFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalToDoubleBiFunction full = mock(OptionalToDoubleBiFunction.class); - when(full.apply("input1", "input2")).thenReturn(OptionalDouble.of(2.0)); - DoubleSupplier fallback = mock(DoubleSupplier.class); - when(fallback.getAsDouble()).thenReturn(3.0); - assertEquals(2.0, new FallbackToDoubleBiFunction(full, fallback).applyAsDouble("input1", "input2"), 0.1); - verify(full, only()).apply("input1", "input2"); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalToDoubleBiFunction empty = mock(OptionalToDoubleBiFunction.class); - when(empty.apply("input1", "input2")).thenReturn(OptionalDouble.empty()); - DoubleSupplier fallback = mock(DoubleSupplier.class); - when(fallback.getAsDouble()).thenReturn(3.0); - assertEquals(3.0, new FallbackToDoubleBiFunction(empty, fallback).applyAsDouble("input1", "input2"), 0.1); - verify(empty, only()).apply("input1", "input2"); - verify(fallback, only()).getAsDouble(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalToDoubleBiFunction full = mock(OptionalToDoubleBiFunction.class); + when(full.apply("input1", "input2")).thenReturn(OptionalDouble.of(2.0)); + DoubleSupplier fallback = mock(DoubleSupplier.class); + when(fallback.getAsDouble()).thenReturn(3.0); + assertEquals(2.0, new FallbackToDoubleBiFunction(full, fallback).applyAsDouble("input1", "input2"), 0.1); + verify(full, only()).apply("input1", "input2"); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalToDoubleBiFunction empty = mock(OptionalToDoubleBiFunction.class); + when(empty.apply("input1", "input2")).thenReturn(OptionalDouble.empty()); + DoubleSupplier fallback = mock(DoubleSupplier.class); + when(fallback.getAsDouble()).thenReturn(3.0); + assertEquals(3.0, new FallbackToDoubleBiFunction(empty, fallback).applyAsDouble("input1", "input2"), 0.1); + verify(empty, only()).apply("input1", "input2"); + verify(fallback, only()).getAsDouble(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackToDoubleFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackToDoubleFunctionTest.java index 5cd92b7..dfc78c2 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackToDoubleFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackToDoubleFunctionTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackToDoubleFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalToDoubleFunction full = mock(OptionalToDoubleFunction.class); - when(full.apply("input")).thenReturn(OptionalDouble.of(2.0)); - DoubleSupplier fallback = mock(DoubleSupplier.class); - when(fallback.getAsDouble()).thenReturn(3.0); - assertEquals(2.0, new FallbackToDoubleFunction(full, fallback).applyAsDouble("input"), 0.1); - verify(full, only()).apply("input"); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalToDoubleFunction empty = mock(OptionalToDoubleFunction.class); - when(empty.apply("input")).thenReturn(OptionalDouble.empty()); - DoubleSupplier fallback = mock(DoubleSupplier.class); - when(fallback.getAsDouble()).thenReturn(3.0); - assertEquals(3.0, new FallbackToDoubleFunction(empty, fallback).applyAsDouble("input"), 0.1); - verify(empty, only()).apply("input"); - verify(fallback, only()).getAsDouble(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalToDoubleFunction full = mock(OptionalToDoubleFunction.class); + when(full.apply("input")).thenReturn(OptionalDouble.of(2.0)); + DoubleSupplier fallback = mock(DoubleSupplier.class); + when(fallback.getAsDouble()).thenReturn(3.0); + assertEquals(2.0, new FallbackToDoubleFunction(full, fallback).applyAsDouble("input"), 0.1); + verify(full, only()).apply("input"); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalToDoubleFunction empty = mock(OptionalToDoubleFunction.class); + when(empty.apply("input")).thenReturn(OptionalDouble.empty()); + DoubleSupplier fallback = mock(DoubleSupplier.class); + when(fallback.getAsDouble()).thenReturn(3.0); + assertEquals(3.0, new FallbackToDoubleFunction(empty, fallback).applyAsDouble("input"), 0.1); + verify(empty, only()).apply("input"); + verify(fallback, only()).getAsDouble(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackToIntBiFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackToIntBiFunctionTest.java index 2902f00..21a5b03 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackToIntBiFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackToIntBiFunctionTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackToIntBiFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalToIntBiFunction full = mock(OptionalToIntBiFunction.class); - when(full.apply("input1", "input2")).thenReturn(OptionalInt.of(2)); - IntSupplier fallback = mock(IntSupplier.class); - when(fallback.getAsInt()).thenReturn(3); - assertEquals(2, new FallbackToIntBiFunction(full, fallback).applyAsInt("input1", "input2")); - verify(full, only()).apply("input1", "input2"); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalToIntBiFunction empty = mock(OptionalToIntBiFunction.class); - when(empty.apply("input1", "input2")).thenReturn(OptionalInt.empty()); - IntSupplier fallback = mock(IntSupplier.class); - when(fallback.getAsInt()).thenReturn(3); - assertEquals(3, new FallbackToIntBiFunction(empty, fallback).applyAsInt("input1", "input2")); - verify(empty, only()).apply("input1", "input2"); - verify(fallback, only()).getAsInt(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalToIntBiFunction full = mock(OptionalToIntBiFunction.class); + when(full.apply("input1", "input2")).thenReturn(OptionalInt.of(2)); + IntSupplier fallback = mock(IntSupplier.class); + when(fallback.getAsInt()).thenReturn(3); + assertEquals(2, new FallbackToIntBiFunction(full, fallback).applyAsInt("input1", "input2")); + verify(full, only()).apply("input1", "input2"); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalToIntBiFunction empty = mock(OptionalToIntBiFunction.class); + when(empty.apply("input1", "input2")).thenReturn(OptionalInt.empty()); + IntSupplier fallback = mock(IntSupplier.class); + when(fallback.getAsInt()).thenReturn(3); + assertEquals(3, new FallbackToIntBiFunction(empty, fallback).applyAsInt("input1", "input2")); + verify(empty, only()).apply("input1", "input2"); + verify(fallback, only()).getAsInt(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackToIntFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackToIntFunctionTest.java index 008385b..99db637 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackToIntFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackToIntFunctionTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackToIntFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalToIntFunction full = mock(OptionalToIntFunction.class); - when(full.apply("input")).thenReturn(OptionalInt.of(2)); - IntSupplier fallback = mock(IntSupplier.class); - when(fallback.getAsInt()).thenReturn(3); - assertEquals(2, new FallbackToIntFunction(full, fallback).applyAsInt("input")); - verify(full, only()).apply("input"); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalToIntFunction empty = mock(OptionalToIntFunction.class); - when(empty.apply("input")).thenReturn(OptionalInt.empty()); - IntSupplier fallback = mock(IntSupplier.class); - when(fallback.getAsInt()).thenReturn(3); - assertEquals(3, new FallbackToIntFunction(empty, fallback).applyAsInt("input")); - verify(empty, only()).apply("input"); - verify(fallback, only()).getAsInt(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalToIntFunction full = mock(OptionalToIntFunction.class); + when(full.apply("input")).thenReturn(OptionalInt.of(2)); + IntSupplier fallback = mock(IntSupplier.class); + when(fallback.getAsInt()).thenReturn(3); + assertEquals(2, new FallbackToIntFunction(full, fallback).applyAsInt("input")); + verify(full, only()).apply("input"); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalToIntFunction empty = mock(OptionalToIntFunction.class); + when(empty.apply("input")).thenReturn(OptionalInt.empty()); + IntSupplier fallback = mock(IntSupplier.class); + when(fallback.getAsInt()).thenReturn(3); + assertEquals(3, new FallbackToIntFunction(empty, fallback).applyAsInt("input")); + verify(empty, only()).apply("input"); + verify(fallback, only()).getAsInt(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackToLongBiFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackToLongBiFunctionTest.java index c054531..47e0b06 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackToLongBiFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackToLongBiFunctionTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackToLongBiFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalToLongBiFunction full = mock(OptionalToLongBiFunction.class); - when(full.apply("input1", "input2")).thenReturn(OptionalLong.of(2L)); - LongSupplier fallback = mock(LongSupplier.class); - when(fallback.getAsLong()).thenReturn(3L); - assertEquals(2L, new FallbackToLongBiFunction(full, fallback).applyAsLong("input1", "input2")); - verify(full, only()).apply("input1", "input2"); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalToLongBiFunction empty = mock(OptionalToLongBiFunction.class); - when(empty.apply("input1", "input2")).thenReturn(OptionalLong.empty()); - LongSupplier fallback = mock(LongSupplier.class); - when(fallback.getAsLong()).thenReturn(3L); - assertEquals(3L, new FallbackToLongBiFunction(empty, fallback).applyAsLong("input1", "input2")); - verify(empty, only()).apply("input1", "input2"); - verify(fallback, only()).getAsLong(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalToLongBiFunction full = mock(OptionalToLongBiFunction.class); + when(full.apply("input1", "input2")).thenReturn(OptionalLong.of(2L)); + LongSupplier fallback = mock(LongSupplier.class); + when(fallback.getAsLong()).thenReturn(3L); + assertEquals(2L, new FallbackToLongBiFunction(full, fallback).applyAsLong("input1", "input2")); + verify(full, only()).apply("input1", "input2"); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalToLongBiFunction empty = mock(OptionalToLongBiFunction.class); + when(empty.apply("input1", "input2")).thenReturn(OptionalLong.empty()); + LongSupplier fallback = mock(LongSupplier.class); + when(fallback.getAsLong()).thenReturn(3L); + assertEquals(3L, new FallbackToLongBiFunction(empty, fallback).applyAsLong("input1", "input2")); + verify(empty, only()).apply("input1", "input2"); + verify(fallback, only()).getAsLong(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackToLongFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackToLongFunctionTest.java index 799e2a1..1b39159 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackToLongFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackToLongFunctionTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackToLongFunctionTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalToLongFunction full = mock(OptionalToLongFunction.class); - when(full.apply("input")).thenReturn(OptionalLong.of(2L)); - LongSupplier fallback = mock(LongSupplier.class); - when(fallback.getAsLong()).thenReturn(3L); - assertEquals(2L, new FallbackToLongFunction(full, fallback).applyAsLong("input")); - verify(full, only()).apply("input"); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalToLongFunction empty = mock(OptionalToLongFunction.class); - when(empty.apply("input")).thenReturn(OptionalLong.empty()); - LongSupplier fallback = mock(LongSupplier.class); - when(fallback.getAsLong()).thenReturn(3L); - assertEquals(3L, new FallbackToLongFunction(empty, fallback).applyAsLong("input")); - verify(empty, only()).apply("input"); - verify(fallback, only()).getAsLong(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalToLongFunction full = mock(OptionalToLongFunction.class); + when(full.apply("input")).thenReturn(OptionalLong.of(2L)); + LongSupplier fallback = mock(LongSupplier.class); + when(fallback.getAsLong()).thenReturn(3L); + assertEquals(2L, new FallbackToLongFunction(full, fallback).applyAsLong("input")); + verify(full, only()).apply("input"); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalToLongFunction empty = mock(OptionalToLongFunction.class); + when(empty.apply("input")).thenReturn(OptionalLong.empty()); + LongSupplier fallback = mock(LongSupplier.class); + when(fallback.getAsLong()).thenReturn(3L); + assertEquals(3L, new FallbackToLongFunction(empty, fallback).applyAsLong("input")); + verify(empty, only()).apply("input"); + verify(fallback, only()).getAsLong(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/FallbackUnaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/FallbackUnaryOperatorTest.java index b935f10..78dea33 100644 --- a/src/test/java/com/machinezoo/noexception/optional/FallbackUnaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/FallbackUnaryOperatorTest.java @@ -9,24 +9,24 @@ import org.junit.jupiter.api.*; public class FallbackUnaryOperatorTest { - @Test - public void full() { - @SuppressWarnings("unchecked") OptionalUnaryOperator full = mock(OptionalUnaryOperator.class); - when(full.apply("input")).thenReturn(Optional.of("value")); - @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); - when(fallback.get()).thenReturn("default"); - assertEquals("value", new FallbackUnaryOperator(full, fallback).apply("input")); - verify(full, only()).apply("input"); - verifyNoMoreInteractions(fallback); - } - @Test - public void empty() { - @SuppressWarnings("unchecked") OptionalUnaryOperator empty = mock(OptionalUnaryOperator.class); - when(empty.apply("input")).thenReturn(Optional.empty()); - @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); - when(fallback.get()).thenReturn("default"); - assertEquals("default", new FallbackUnaryOperator(empty, fallback).apply("input")); - verify(empty, only()).apply("input"); - verify(fallback, only()).get(); - } + @Test + public void full() { + @SuppressWarnings("unchecked") OptionalUnaryOperator full = mock(OptionalUnaryOperator.class); + when(full.apply("input")).thenReturn(Optional.of("value")); + @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); + when(fallback.get()).thenReturn("default"); + assertEquals("value", new FallbackUnaryOperator(full, fallback).apply("input")); + verify(full, only()).apply("input"); + verifyNoMoreInteractions(fallback); + } + @Test + public void empty() { + @SuppressWarnings("unchecked") OptionalUnaryOperator empty = mock(OptionalUnaryOperator.class); + when(empty.apply("input")).thenReturn(Optional.empty()); + @SuppressWarnings("unchecked") Supplier fallback = mock(Supplier.class); + when(fallback.get()).thenReturn("default"); + assertEquals("default", new FallbackUnaryOperator(empty, fallback).apply("input")); + verify(empty, only()).apply("input"); + verify(fallback, only()).get(); + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalBiFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalBiFunctionTest.java index 9a98dd3..5f2c591 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalBiFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalBiFunctionTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalBiFunctionTest { - @Test - public void conversions() { - assertEquals(Optional.of("value"), create((t, u) -> Optional.of("value")).apply("input1", "input2")); - assertEquals("value", create((t, u) -> Optional.of("value")).orElse("default").apply("input1", "input2")); - assertEquals("value", create((t, u) -> Optional.of("value")).orElseGet(() -> "value").apply("input1", "input2")); - assertEquals(Optional.empty(), create((t, u) -> Optional.empty()).apply("input1", "input2")); - assertEquals("default", create((t, u) -> Optional.empty()).orElse("default").apply("input1", "input2")); - assertEquals("default", create((t, u) -> Optional.empty()).orElseGet(() -> "default").apply("input1", "input2")); - } - private OptionalBiFunction create(OptionalBiFunction lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(Optional.of("value"), create((t, u) -> Optional.of("value")).apply("input1", "input2")); + assertEquals("value", create((t, u) -> Optional.of("value")).orElse("default").apply("input1", "input2")); + assertEquals("value", create((t, u) -> Optional.of("value")).orElseGet(() -> "value").apply("input1", "input2")); + assertEquals(Optional.empty(), create((t, u) -> Optional.empty()).apply("input1", "input2")); + assertEquals("default", create((t, u) -> Optional.empty()).orElse("default").apply("input1", "input2")); + assertEquals("default", create((t, u) -> Optional.empty()).orElseGet(() -> "default").apply("input1", "input2")); + } + private OptionalBiFunction create(OptionalBiFunction lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalBiPredicateTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalBiPredicateTest.java index 6dd52d7..9cd521c 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalBiPredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalBiPredicateTest.java @@ -6,16 +6,16 @@ import org.junit.jupiter.api.*; public class OptionalBiPredicateTest { - @Test - public void conversions() { - assertEquals(OptionalBoolean.of(true), create((t, u) -> OptionalBoolean.of(true)).test("input1", "input2")); - assertEquals(true, create((t, u) -> OptionalBoolean.of(true)).orElse(false).test("input1", "input2")); - assertEquals(true, create((t, u) -> OptionalBoolean.of(true)).orElseGet(() -> true).test("input1", "input2")); - assertEquals(OptionalBoolean.empty(), create((t, u) -> OptionalBoolean.empty()).test("input1", "input2")); - assertEquals(false, create((t, u) -> OptionalBoolean.empty()).orElse(false).test("input1", "input2")); - assertEquals(false, create((t, u) -> OptionalBoolean.empty()).orElseGet(() -> false).test("input1", "input2")); - } - private OptionalBiPredicate create(OptionalBiPredicate lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalBoolean.of(true), create((t, u) -> OptionalBoolean.of(true)).test("input1", "input2")); + assertEquals(true, create((t, u) -> OptionalBoolean.of(true)).orElse(false).test("input1", "input2")); + assertEquals(true, create((t, u) -> OptionalBoolean.of(true)).orElseGet(() -> true).test("input1", "input2")); + assertEquals(OptionalBoolean.empty(), create((t, u) -> OptionalBoolean.empty()).test("input1", "input2")); + assertEquals(false, create((t, u) -> OptionalBoolean.empty()).orElse(false).test("input1", "input2")); + assertEquals(false, create((t, u) -> OptionalBoolean.empty()).orElseGet(() -> false).test("input1", "input2")); + } + private OptionalBiPredicate create(OptionalBiPredicate lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalBinaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalBinaryOperatorTest.java index 3e647ff..290e41a 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalBinaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalBinaryOperatorTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalBinaryOperatorTest { - @Test - public void conversions() { - assertEquals(Optional.of("value"), create((l, r) -> Optional.of("value")).apply("input1", "input2")); - assertEquals("value", create((l, r) -> Optional.of("value")).orElse("default").apply("input1", "input2")); - assertEquals("value", create((l, r) -> Optional.of("value")).orElseGet(() -> "value").apply("input1", "input2")); - assertEquals(Optional.empty(), create((l, r) -> Optional.empty()).apply("input1", "input2")); - assertEquals("default", create((l, r) -> Optional.empty()).orElse("default").apply("input1", "input2")); - assertEquals("default", create((l, r) -> Optional.empty()).orElseGet(() -> "default").apply("input1", "input2")); - } - private OptionalBinaryOperator create(OptionalBinaryOperator lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(Optional.of("value"), create((l, r) -> Optional.of("value")).apply("input1", "input2")); + assertEquals("value", create((l, r) -> Optional.of("value")).orElse("default").apply("input1", "input2")); + assertEquals("value", create((l, r) -> Optional.of("value")).orElseGet(() -> "value").apply("input1", "input2")); + assertEquals(Optional.empty(), create((l, r) -> Optional.empty()).apply("input1", "input2")); + assertEquals("default", create((l, r) -> Optional.empty()).orElse("default").apply("input1", "input2")); + assertEquals("default", create((l, r) -> Optional.empty()).orElseGet(() -> "default").apply("input1", "input2")); + } + private OptionalBinaryOperator create(OptionalBinaryOperator lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalBooleanSupplierTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalBooleanSupplierTest.java index 9057adf..6f69e67 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalBooleanSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalBooleanSupplierTest.java @@ -6,16 +6,16 @@ import org.junit.jupiter.api.*; public class OptionalBooleanSupplierTest { - @Test - public void conversions() { - assertEquals(OptionalBoolean.of(true), create(() -> OptionalBoolean.of(true)).get()); - assertEquals(true, create(() -> OptionalBoolean.of(true)).orElse(false).getAsBoolean()); - assertEquals(true, create(() -> OptionalBoolean.of(true)).orElseGet(() -> true).getAsBoolean()); - assertEquals(OptionalBoolean.empty(), create(() -> OptionalBoolean.empty()).get()); - assertEquals(false, create(() -> OptionalBoolean.empty()).orElse(false).getAsBoolean()); - assertEquals(false, create(() -> OptionalBoolean.empty()).orElseGet(() -> false).getAsBoolean()); - } - private OptionalBooleanSupplier create(OptionalBooleanSupplier lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalBoolean.of(true), create(() -> OptionalBoolean.of(true)).get()); + assertEquals(true, create(() -> OptionalBoolean.of(true)).orElse(false).getAsBoolean()); + assertEquals(true, create(() -> OptionalBoolean.of(true)).orElseGet(() -> true).getAsBoolean()); + assertEquals(OptionalBoolean.empty(), create(() -> OptionalBoolean.empty()).get()); + assertEquals(false, create(() -> OptionalBoolean.empty()).orElse(false).getAsBoolean()); + assertEquals(false, create(() -> OptionalBoolean.empty()).orElseGet(() -> false).getAsBoolean()); + } + private OptionalBooleanSupplier create(OptionalBooleanSupplier lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalComparatorTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalComparatorTest.java index 6b8a5f2..9e61cb6 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalComparatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalComparatorTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalComparatorTest { - @Test - public void conversions() { - assertEquals(OptionalInt.of(2), create((l, r) -> OptionalInt.of(2)).compare("input1", "input2")); - assertEquals(2, create((l, r) -> OptionalInt.of(2)).orElse(3).compare("input1", "input2")); - assertEquals(2, create((l, r) -> OptionalInt.of(2)).orElseGet(() -> 2).compare("input1", "input2")); - assertEquals(OptionalInt.empty(), create((l, r) -> OptionalInt.empty()).compare("input1", "input2")); - assertEquals(3, create((l, r) -> OptionalInt.empty()).orElse(3).compare("input1", "input2")); - assertEquals(3, create((l, r) -> OptionalInt.empty()).orElseGet(() -> 3).compare("input1", "input2")); - } - private OptionalComparator create(OptionalComparator lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalInt.of(2), create((l, r) -> OptionalInt.of(2)).compare("input1", "input2")); + assertEquals(2, create((l, r) -> OptionalInt.of(2)).orElse(3).compare("input1", "input2")); + assertEquals(2, create((l, r) -> OptionalInt.of(2)).orElseGet(() -> 2).compare("input1", "input2")); + assertEquals(OptionalInt.empty(), create((l, r) -> OptionalInt.empty()).compare("input1", "input2")); + assertEquals(3, create((l, r) -> OptionalInt.empty()).orElse(3).compare("input1", "input2")); + assertEquals(3, create((l, r) -> OptionalInt.empty()).orElseGet(() -> 3).compare("input1", "input2")); + } + private OptionalComparator create(OptionalComparator lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleBinaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleBinaryOperatorTest.java index 4b3c321..0015ced 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleBinaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleBinaryOperatorTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalDoubleBinaryOperatorTest { - @Test - public void conversions() { - assertEquals(OptionalDouble.of(2.0), create((l, r) -> OptionalDouble.of(2.0)).apply(1.1, 1.2)); - assertEquals(2.0, create((l, r) -> OptionalDouble.of(2.0)).orElse(3.0).applyAsDouble(1.1, 1.2), 0.1); - assertEquals(2.0, create((l, r) -> OptionalDouble.of(2.0)).orElseGet(() -> 2.0).applyAsDouble(1.1, 1.2), 0.1); - assertEquals(OptionalDouble.empty(), create((l, r) -> OptionalDouble.empty()).apply(1.1, 1.2)); - assertEquals(3.0, create((l, r) -> OptionalDouble.empty()).orElse(3.0).applyAsDouble(1.1, 1.2), 0.1); - assertEquals(3.0, create((l, r) -> OptionalDouble.empty()).orElseGet(() -> 3.0).applyAsDouble(1.1, 1.2), 0.1); - } - private OptionalDoubleBinaryOperator create(OptionalDoubleBinaryOperator lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalDouble.of(2.0), create((l, r) -> OptionalDouble.of(2.0)).apply(1.1, 1.2)); + assertEquals(2.0, create((l, r) -> OptionalDouble.of(2.0)).orElse(3.0).applyAsDouble(1.1, 1.2), 0.1); + assertEquals(2.0, create((l, r) -> OptionalDouble.of(2.0)).orElseGet(() -> 2.0).applyAsDouble(1.1, 1.2), 0.1); + assertEquals(OptionalDouble.empty(), create((l, r) -> OptionalDouble.empty()).apply(1.1, 1.2)); + assertEquals(3.0, create((l, r) -> OptionalDouble.empty()).orElse(3.0).applyAsDouble(1.1, 1.2), 0.1); + assertEquals(3.0, create((l, r) -> OptionalDouble.empty()).orElseGet(() -> 3.0).applyAsDouble(1.1, 1.2), 0.1); + } + private OptionalDoubleBinaryOperator create(OptionalDoubleBinaryOperator lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleFunctionTest.java index 238bc79..4714950 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleFunctionTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalDoubleFunctionTest { - @Test - public void conversions() { - assertEquals(Optional.of("value"), create(v -> Optional.of("value")).apply(1.0)); - assertEquals("value", create(v -> Optional.of("value")).orElse("default").apply(1.0)); - assertEquals("value", create(v -> Optional.of("value")).orElseGet(() -> "value").apply(1.0)); - assertEquals(Optional.empty(), create(v -> Optional.empty()).apply(1.0)); - assertEquals("default", create(v -> Optional.empty()).orElse("default").apply(1.0)); - assertEquals("default", create(v -> Optional.empty()).orElseGet(() -> "default").apply(1.0)); - } - private OptionalDoubleFunction create(OptionalDoubleFunction lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(Optional.of("value"), create(v -> Optional.of("value")).apply(1.0)); + assertEquals("value", create(v -> Optional.of("value")).orElse("default").apply(1.0)); + assertEquals("value", create(v -> Optional.of("value")).orElseGet(() -> "value").apply(1.0)); + assertEquals(Optional.empty(), create(v -> Optional.empty()).apply(1.0)); + assertEquals("default", create(v -> Optional.empty()).orElse("default").apply(1.0)); + assertEquals("default", create(v -> Optional.empty()).orElseGet(() -> "default").apply(1.0)); + } + private OptionalDoubleFunction create(OptionalDoubleFunction lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalDoublePredicateTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalDoublePredicateTest.java index 5e45d89..e89efc3 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalDoublePredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalDoublePredicateTest.java @@ -6,16 +6,16 @@ import org.junit.jupiter.api.*; public class OptionalDoublePredicateTest { - @Test - public void conversions() { - assertEquals(OptionalBoolean.of(true), create(v -> OptionalBoolean.of(true)).test(1.0)); - assertEquals(true, create(v -> OptionalBoolean.of(true)).orElse(false).test(1.0)); - assertEquals(true, create(v -> OptionalBoolean.of(true)).orElseGet(() -> true).test(1.0)); - assertEquals(OptionalBoolean.empty(), create(v -> OptionalBoolean.empty()).test(1.0)); - assertEquals(false, create(v -> OptionalBoolean.empty()).orElse(false).test(1.0)); - assertEquals(false, create(v -> OptionalBoolean.empty()).orElseGet(() -> false).test(1.0)); - } - private OptionalDoublePredicate create(OptionalDoublePredicate lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalBoolean.of(true), create(v -> OptionalBoolean.of(true)).test(1.0)); + assertEquals(true, create(v -> OptionalBoolean.of(true)).orElse(false).test(1.0)); + assertEquals(true, create(v -> OptionalBoolean.of(true)).orElseGet(() -> true).test(1.0)); + assertEquals(OptionalBoolean.empty(), create(v -> OptionalBoolean.empty()).test(1.0)); + assertEquals(false, create(v -> OptionalBoolean.empty()).orElse(false).test(1.0)); + assertEquals(false, create(v -> OptionalBoolean.empty()).orElseGet(() -> false).test(1.0)); + } + private OptionalDoublePredicate create(OptionalDoublePredicate lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleSupplierTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleSupplierTest.java index cc98120..47d2436 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleSupplierTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalDoubleSupplierTest { - @Test - public void conversions() { - assertEquals(OptionalDouble.of(2.0), create(() -> OptionalDouble.of(2.0)).get()); - assertEquals(2.0, create(() -> OptionalDouble.of(2.0)).orElse(3.0).getAsDouble(), 0.1); - assertEquals(2.0, create(() -> OptionalDouble.of(2.0)).orElseGet(() -> 2.0).getAsDouble(), 0.1); - assertEquals(OptionalDouble.empty(), create(() -> OptionalDouble.empty()).get()); - assertEquals(3.0, create(() -> OptionalDouble.empty()).orElse(3.0).getAsDouble(), 0.1); - assertEquals(3.0, create(() -> OptionalDouble.empty()).orElseGet(() -> 3.0).getAsDouble(), 0.1); - } - private OptionalDoubleSupplier create(OptionalDoubleSupplier lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalDouble.of(2.0), create(() -> OptionalDouble.of(2.0)).get()); + assertEquals(2.0, create(() -> OptionalDouble.of(2.0)).orElse(3.0).getAsDouble(), 0.1); + assertEquals(2.0, create(() -> OptionalDouble.of(2.0)).orElseGet(() -> 2.0).getAsDouble(), 0.1); + assertEquals(OptionalDouble.empty(), create(() -> OptionalDouble.empty()).get()); + assertEquals(3.0, create(() -> OptionalDouble.empty()).orElse(3.0).getAsDouble(), 0.1); + assertEquals(3.0, create(() -> OptionalDouble.empty()).orElseGet(() -> 3.0).getAsDouble(), 0.1); + } + private OptionalDoubleSupplier create(OptionalDoubleSupplier lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleToIntFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleToIntFunctionTest.java index d0eb5ad..283301e 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleToIntFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleToIntFunctionTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalDoubleToIntFunctionTest { - @Test - public void conversions() { - assertEquals(OptionalInt.of(2), create(v -> OptionalInt.of(2)).apply(1.0)); - assertEquals(2, create(v -> OptionalInt.of(2)).orElse(3).applyAsInt(1.0)); - assertEquals(2, create(v -> OptionalInt.of(2)).orElseGet(() -> 2).applyAsInt(1.0)); - assertEquals(OptionalInt.empty(), create(v -> OptionalInt.empty()).apply(1.0)); - assertEquals(3, create(v -> OptionalInt.empty()).orElse(3).applyAsInt(1.0)); - assertEquals(3, create(v -> OptionalInt.empty()).orElseGet(() -> 3).applyAsInt(1.0)); - } - private OptionalDoubleToIntFunction create(OptionalDoubleToIntFunction lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalInt.of(2), create(v -> OptionalInt.of(2)).apply(1.0)); + assertEquals(2, create(v -> OptionalInt.of(2)).orElse(3).applyAsInt(1.0)); + assertEquals(2, create(v -> OptionalInt.of(2)).orElseGet(() -> 2).applyAsInt(1.0)); + assertEquals(OptionalInt.empty(), create(v -> OptionalInt.empty()).apply(1.0)); + assertEquals(3, create(v -> OptionalInt.empty()).orElse(3).applyAsInt(1.0)); + assertEquals(3, create(v -> OptionalInt.empty()).orElseGet(() -> 3).applyAsInt(1.0)); + } + private OptionalDoubleToIntFunction create(OptionalDoubleToIntFunction lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleToLongFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleToLongFunctionTest.java index 78034d8..767be6c 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleToLongFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleToLongFunctionTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalDoubleToLongFunctionTest { - @Test - public void conversions() { - assertEquals(OptionalLong.of(2L), create(v -> OptionalLong.of(2L)).apply(1.0)); - assertEquals(2L, create(v -> OptionalLong.of(2L)).orElse(3L).applyAsLong(1.0)); - assertEquals(2L, create(v -> OptionalLong.of(2L)).orElseGet(() -> 2L).applyAsLong(1.0)); - assertEquals(OptionalLong.empty(), create(v -> OptionalLong.empty()).apply(1.0)); - assertEquals(3L, create(v -> OptionalLong.empty()).orElse(3L).applyAsLong(1.0)); - assertEquals(3L, create(v -> OptionalLong.empty()).orElseGet(() -> 3L).applyAsLong(1.0)); - } - private OptionalDoubleToLongFunction create(OptionalDoubleToLongFunction lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalLong.of(2L), create(v -> OptionalLong.of(2L)).apply(1.0)); + assertEquals(2L, create(v -> OptionalLong.of(2L)).orElse(3L).applyAsLong(1.0)); + assertEquals(2L, create(v -> OptionalLong.of(2L)).orElseGet(() -> 2L).applyAsLong(1.0)); + assertEquals(OptionalLong.empty(), create(v -> OptionalLong.empty()).apply(1.0)); + assertEquals(3L, create(v -> OptionalLong.empty()).orElse(3L).applyAsLong(1.0)); + assertEquals(3L, create(v -> OptionalLong.empty()).orElseGet(() -> 3L).applyAsLong(1.0)); + } + private OptionalDoubleToLongFunction create(OptionalDoubleToLongFunction lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleUnaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleUnaryOperatorTest.java index d502ac9..23b24a6 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleUnaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalDoubleUnaryOperatorTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalDoubleUnaryOperatorTest { - @Test - public void conversions() { - assertEquals(OptionalDouble.of(2.0), create(o -> OptionalDouble.of(2.0)).apply(1.0)); - assertEquals(2.0, create(o -> OptionalDouble.of(2.0)).orElse(3.0).applyAsDouble(1.0), 0.1); - assertEquals(2.0, create(o -> OptionalDouble.of(2.0)).orElseGet(() -> 2.0).applyAsDouble(1.0), 0.1); - assertEquals(OptionalDouble.empty(), create(o -> OptionalDouble.empty()).apply(1.0)); - assertEquals(3.0, create(o -> OptionalDouble.empty()).orElse(3.0).applyAsDouble(1.0), 0.1); - assertEquals(3.0, create(o -> OptionalDouble.empty()).orElseGet(() -> 3.0).applyAsDouble(1.0), 0.1); - } - private OptionalDoubleUnaryOperator create(OptionalDoubleUnaryOperator lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalDouble.of(2.0), create(o -> OptionalDouble.of(2.0)).apply(1.0)); + assertEquals(2.0, create(o -> OptionalDouble.of(2.0)).orElse(3.0).applyAsDouble(1.0), 0.1); + assertEquals(2.0, create(o -> OptionalDouble.of(2.0)).orElseGet(() -> 2.0).applyAsDouble(1.0), 0.1); + assertEquals(OptionalDouble.empty(), create(o -> OptionalDouble.empty()).apply(1.0)); + assertEquals(3.0, create(o -> OptionalDouble.empty()).orElse(3.0).applyAsDouble(1.0), 0.1); + assertEquals(3.0, create(o -> OptionalDouble.empty()).orElseGet(() -> 3.0).applyAsDouble(1.0), 0.1); + } + private OptionalDoubleUnaryOperator create(OptionalDoubleUnaryOperator lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalFunctionTest.java index 868c727..76f4b58 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalFunctionTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalFunctionTest { - @Test - public void conversions() { - assertEquals(Optional.of("value"), create(t -> Optional.of("value")).apply("input")); - assertEquals("value", create(t -> Optional.of("value")).orElse("default").apply("input")); - assertEquals("value", create(t -> Optional.of("value")).orElseGet(() -> "value").apply("input")); - assertEquals(Optional.empty(), create(t -> Optional.empty()).apply("input")); - assertEquals("default", create(t -> Optional.empty()).orElse("default").apply("input")); - assertEquals("default", create(t -> Optional.empty()).orElseGet(() -> "default").apply("input")); - } - private OptionalFunction create(OptionalFunction lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(Optional.of("value"), create(t -> Optional.of("value")).apply("input")); + assertEquals("value", create(t -> Optional.of("value")).orElse("default").apply("input")); + assertEquals("value", create(t -> Optional.of("value")).orElseGet(() -> "value").apply("input")); + assertEquals(Optional.empty(), create(t -> Optional.empty()).apply("input")); + assertEquals("default", create(t -> Optional.empty()).orElse("default").apply("input")); + assertEquals("default", create(t -> Optional.empty()).orElseGet(() -> "default").apply("input")); + } + private OptionalFunction create(OptionalFunction lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalIntBinaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalIntBinaryOperatorTest.java index ca1072e..94b48c3 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalIntBinaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalIntBinaryOperatorTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalIntBinaryOperatorTest { - @Test - public void conversions() { - assertEquals(OptionalInt.of(2), create((l, r) -> OptionalInt.of(2)).apply(11, 12)); - assertEquals(2, create((l, r) -> OptionalInt.of(2)).orElse(3).applyAsInt(11, 12)); - assertEquals(2, create((l, r) -> OptionalInt.of(2)).orElseGet(() -> 2).applyAsInt(11, 12)); - assertEquals(OptionalInt.empty(), create((l, r) -> OptionalInt.empty()).apply(11, 12)); - assertEquals(3, create((l, r) -> OptionalInt.empty()).orElse(3).applyAsInt(11, 12)); - assertEquals(3, create((l, r) -> OptionalInt.empty()).orElseGet(() -> 3).applyAsInt(11, 12)); - } - private OptionalIntBinaryOperator create(OptionalIntBinaryOperator lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalInt.of(2), create((l, r) -> OptionalInt.of(2)).apply(11, 12)); + assertEquals(2, create((l, r) -> OptionalInt.of(2)).orElse(3).applyAsInt(11, 12)); + assertEquals(2, create((l, r) -> OptionalInt.of(2)).orElseGet(() -> 2).applyAsInt(11, 12)); + assertEquals(OptionalInt.empty(), create((l, r) -> OptionalInt.empty()).apply(11, 12)); + assertEquals(3, create((l, r) -> OptionalInt.empty()).orElse(3).applyAsInt(11, 12)); + assertEquals(3, create((l, r) -> OptionalInt.empty()).orElseGet(() -> 3).applyAsInt(11, 12)); + } + private OptionalIntBinaryOperator create(OptionalIntBinaryOperator lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalIntFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalIntFunctionTest.java index 59a9115..17be53d 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalIntFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalIntFunctionTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalIntFunctionTest { - @Test - public void conversions() { - assertEquals(Optional.of("value"), create(v -> Optional.of("value")).apply(1)); - assertEquals("value", create(v -> Optional.of("value")).orElse("default").apply(1)); - assertEquals("value", create(v -> Optional.of("value")).orElseGet(() -> "value").apply(1)); - assertEquals(Optional.empty(), create(v -> Optional.empty()).apply(1)); - assertEquals("default", create(v -> Optional.empty()).orElse("default").apply(1)); - assertEquals("default", create(v -> Optional.empty()).orElseGet(() -> "default").apply(1)); - } - private OptionalIntFunction create(OptionalIntFunction lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(Optional.of("value"), create(v -> Optional.of("value")).apply(1)); + assertEquals("value", create(v -> Optional.of("value")).orElse("default").apply(1)); + assertEquals("value", create(v -> Optional.of("value")).orElseGet(() -> "value").apply(1)); + assertEquals(Optional.empty(), create(v -> Optional.empty()).apply(1)); + assertEquals("default", create(v -> Optional.empty()).orElse("default").apply(1)); + assertEquals("default", create(v -> Optional.empty()).orElseGet(() -> "default").apply(1)); + } + private OptionalIntFunction create(OptionalIntFunction lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalIntPredicateTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalIntPredicateTest.java index 799e17d..82f50dc 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalIntPredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalIntPredicateTest.java @@ -6,16 +6,16 @@ import org.junit.jupiter.api.*; public class OptionalIntPredicateTest { - @Test - public void conversions() { - assertEquals(OptionalBoolean.of(true), create(v -> OptionalBoolean.of(true)).test(1)); - assertEquals(true, create(v -> OptionalBoolean.of(true)).orElse(false).test(1)); - assertEquals(true, create(v -> OptionalBoolean.of(true)).orElseGet(() -> true).test(1)); - assertEquals(OptionalBoolean.empty(), create(v -> OptionalBoolean.empty()).test(1)); - assertEquals(false, create(v -> OptionalBoolean.empty()).orElse(false).test(1)); - assertEquals(false, create(v -> OptionalBoolean.empty()).orElseGet(() -> false).test(1)); - } - private OptionalIntPredicate create(OptionalIntPredicate lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalBoolean.of(true), create(v -> OptionalBoolean.of(true)).test(1)); + assertEquals(true, create(v -> OptionalBoolean.of(true)).orElse(false).test(1)); + assertEquals(true, create(v -> OptionalBoolean.of(true)).orElseGet(() -> true).test(1)); + assertEquals(OptionalBoolean.empty(), create(v -> OptionalBoolean.empty()).test(1)); + assertEquals(false, create(v -> OptionalBoolean.empty()).orElse(false).test(1)); + assertEquals(false, create(v -> OptionalBoolean.empty()).orElseGet(() -> false).test(1)); + } + private OptionalIntPredicate create(OptionalIntPredicate lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalIntSupplierTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalIntSupplierTest.java index 3e40e61..58172c6 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalIntSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalIntSupplierTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalIntSupplierTest { - @Test - public void conversions() { - assertEquals(OptionalInt.of(2), create(() -> OptionalInt.of(2)).get()); - assertEquals(2, create(() -> OptionalInt.of(2)).orElse(3).getAsInt()); - assertEquals(2, create(() -> OptionalInt.of(2)).orElseGet(() -> 2).getAsInt()); - assertEquals(OptionalInt.empty(), create(() -> OptionalInt.empty()).get()); - assertEquals(3, create(() -> OptionalInt.empty()).orElse(3).getAsInt()); - assertEquals(3, create(() -> OptionalInt.empty()).orElseGet(() -> 3).getAsInt()); - } - private OptionalIntSupplier create(OptionalIntSupplier lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalInt.of(2), create(() -> OptionalInt.of(2)).get()); + assertEquals(2, create(() -> OptionalInt.of(2)).orElse(3).getAsInt()); + assertEquals(2, create(() -> OptionalInt.of(2)).orElseGet(() -> 2).getAsInt()); + assertEquals(OptionalInt.empty(), create(() -> OptionalInt.empty()).get()); + assertEquals(3, create(() -> OptionalInt.empty()).orElse(3).getAsInt()); + assertEquals(3, create(() -> OptionalInt.empty()).orElseGet(() -> 3).getAsInt()); + } + private OptionalIntSupplier create(OptionalIntSupplier lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalIntToDoubleFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalIntToDoubleFunctionTest.java index cdc84f3..57f09a7 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalIntToDoubleFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalIntToDoubleFunctionTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalIntToDoubleFunctionTest { - @Test - public void conversions() { - assertEquals(OptionalDouble.of(2.0), create(v -> OptionalDouble.of(2.0)).apply(1)); - assertEquals(2.0, create(v -> OptionalDouble.of(2.0)).orElse(3.0).applyAsDouble(1), 0.1); - assertEquals(2.0, create(v -> OptionalDouble.of(2.0)).orElseGet(() -> 2.0).applyAsDouble(1), 0.1); - assertEquals(OptionalDouble.empty(), create(v -> OptionalDouble.empty()).apply(1)); - assertEquals(3.0, create(v -> OptionalDouble.empty()).orElse(3.0).applyAsDouble(1), 0.1); - assertEquals(3.0, create(v -> OptionalDouble.empty()).orElseGet(() -> 3.0).applyAsDouble(1), 0.1); - } - private OptionalIntToDoubleFunction create(OptionalIntToDoubleFunction lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalDouble.of(2.0), create(v -> OptionalDouble.of(2.0)).apply(1)); + assertEquals(2.0, create(v -> OptionalDouble.of(2.0)).orElse(3.0).applyAsDouble(1), 0.1); + assertEquals(2.0, create(v -> OptionalDouble.of(2.0)).orElseGet(() -> 2.0).applyAsDouble(1), 0.1); + assertEquals(OptionalDouble.empty(), create(v -> OptionalDouble.empty()).apply(1)); + assertEquals(3.0, create(v -> OptionalDouble.empty()).orElse(3.0).applyAsDouble(1), 0.1); + assertEquals(3.0, create(v -> OptionalDouble.empty()).orElseGet(() -> 3.0).applyAsDouble(1), 0.1); + } + private OptionalIntToDoubleFunction create(OptionalIntToDoubleFunction lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalIntToLongFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalIntToLongFunctionTest.java index ed40fcf..787e216 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalIntToLongFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalIntToLongFunctionTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalIntToLongFunctionTest { - @Test - public void conversions() { - assertEquals(OptionalLong.of(2L), create(v -> OptionalLong.of(2L)).apply(1)); - assertEquals(2L, create(v -> OptionalLong.of(2L)).orElse(3L).applyAsLong(1)); - assertEquals(2L, create(v -> OptionalLong.of(2L)).orElseGet(() -> 2L).applyAsLong(1)); - assertEquals(OptionalLong.empty(), create(v -> OptionalLong.empty()).apply(1)); - assertEquals(3L, create(v -> OptionalLong.empty()).orElse(3L).applyAsLong(1)); - assertEquals(3L, create(v -> OptionalLong.empty()).orElseGet(() -> 3L).applyAsLong(1)); - } - private OptionalIntToLongFunction create(OptionalIntToLongFunction lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalLong.of(2L), create(v -> OptionalLong.of(2L)).apply(1)); + assertEquals(2L, create(v -> OptionalLong.of(2L)).orElse(3L).applyAsLong(1)); + assertEquals(2L, create(v -> OptionalLong.of(2L)).orElseGet(() -> 2L).applyAsLong(1)); + assertEquals(OptionalLong.empty(), create(v -> OptionalLong.empty()).apply(1)); + assertEquals(3L, create(v -> OptionalLong.empty()).orElse(3L).applyAsLong(1)); + assertEquals(3L, create(v -> OptionalLong.empty()).orElseGet(() -> 3L).applyAsLong(1)); + } + private OptionalIntToLongFunction create(OptionalIntToLongFunction lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalIntUnaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalIntUnaryOperatorTest.java index 2636c6e..8ad2eda 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalIntUnaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalIntUnaryOperatorTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalIntUnaryOperatorTest { - @Test - public void conversions() { - assertEquals(OptionalInt.of(2), create(o -> OptionalInt.of(2)).apply(1)); - assertEquals(2, create(o -> OptionalInt.of(2)).orElse(3).applyAsInt(1)); - assertEquals(2, create(o -> OptionalInt.of(2)).orElseGet(() -> 2).applyAsInt(1)); - assertEquals(OptionalInt.empty(), create(o -> OptionalInt.empty()).apply(1)); - assertEquals(3, create(o -> OptionalInt.empty()).orElse(3).applyAsInt(1)); - assertEquals(3, create(o -> OptionalInt.empty()).orElseGet(() -> 3).applyAsInt(1)); - } - private OptionalIntUnaryOperator create(OptionalIntUnaryOperator lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalInt.of(2), create(o -> OptionalInt.of(2)).apply(1)); + assertEquals(2, create(o -> OptionalInt.of(2)).orElse(3).applyAsInt(1)); + assertEquals(2, create(o -> OptionalInt.of(2)).orElseGet(() -> 2).applyAsInt(1)); + assertEquals(OptionalInt.empty(), create(o -> OptionalInt.empty()).apply(1)); + assertEquals(3, create(o -> OptionalInt.empty()).orElse(3).applyAsInt(1)); + assertEquals(3, create(o -> OptionalInt.empty()).orElseGet(() -> 3).applyAsInt(1)); + } + private OptionalIntUnaryOperator create(OptionalIntUnaryOperator lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalLongBinaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalLongBinaryOperatorTest.java index 96ec764..b47b5ee 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalLongBinaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalLongBinaryOperatorTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalLongBinaryOperatorTest { - @Test - public void conversions() { - assertEquals(OptionalLong.of(2L), create((l, r) -> OptionalLong.of(2L)).apply(11L, 12L)); - assertEquals(2L, create((l, r) -> OptionalLong.of(2L)).orElse(3L).applyAsLong(11L, 12L)); - assertEquals(2L, create((l, r) -> OptionalLong.of(2L)).orElseGet(() -> 2L).applyAsLong(11L, 12L)); - assertEquals(OptionalLong.empty(), create((l, r) -> OptionalLong.empty()).apply(11L, 12L)); - assertEquals(3L, create((l, r) -> OptionalLong.empty()).orElse(3L).applyAsLong(11L, 12L)); - assertEquals(3L, create((l, r) -> OptionalLong.empty()).orElseGet(() -> 3L).applyAsLong(11L, 12L)); - } - private OptionalLongBinaryOperator create(OptionalLongBinaryOperator lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalLong.of(2L), create((l, r) -> OptionalLong.of(2L)).apply(11L, 12L)); + assertEquals(2L, create((l, r) -> OptionalLong.of(2L)).orElse(3L).applyAsLong(11L, 12L)); + assertEquals(2L, create((l, r) -> OptionalLong.of(2L)).orElseGet(() -> 2L).applyAsLong(11L, 12L)); + assertEquals(OptionalLong.empty(), create((l, r) -> OptionalLong.empty()).apply(11L, 12L)); + assertEquals(3L, create((l, r) -> OptionalLong.empty()).orElse(3L).applyAsLong(11L, 12L)); + assertEquals(3L, create((l, r) -> OptionalLong.empty()).orElseGet(() -> 3L).applyAsLong(11L, 12L)); + } + private OptionalLongBinaryOperator create(OptionalLongBinaryOperator lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalLongFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalLongFunctionTest.java index f1136e3..6953bee 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalLongFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalLongFunctionTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalLongFunctionTest { - @Test - public void conversions() { - assertEquals(Optional.of("value"), create(v -> Optional.of("value")).apply(1L)); - assertEquals("value", create(v -> Optional.of("value")).orElse("default").apply(1L)); - assertEquals("value", create(v -> Optional.of("value")).orElseGet(() -> "value").apply(1L)); - assertEquals(Optional.empty(), create(v -> Optional.empty()).apply(1L)); - assertEquals("default", create(v -> Optional.empty()).orElse("default").apply(1L)); - assertEquals("default", create(v -> Optional.empty()).orElseGet(() -> "default").apply(1L)); - } - private OptionalLongFunction create(OptionalLongFunction lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(Optional.of("value"), create(v -> Optional.of("value")).apply(1L)); + assertEquals("value", create(v -> Optional.of("value")).orElse("default").apply(1L)); + assertEquals("value", create(v -> Optional.of("value")).orElseGet(() -> "value").apply(1L)); + assertEquals(Optional.empty(), create(v -> Optional.empty()).apply(1L)); + assertEquals("default", create(v -> Optional.empty()).orElse("default").apply(1L)); + assertEquals("default", create(v -> Optional.empty()).orElseGet(() -> "default").apply(1L)); + } + private OptionalLongFunction create(OptionalLongFunction lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalLongPredicateTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalLongPredicateTest.java index 79008c4..cf892b7 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalLongPredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalLongPredicateTest.java @@ -6,16 +6,16 @@ import org.junit.jupiter.api.*; public class OptionalLongPredicateTest { - @Test - public void conversions() { - assertEquals(OptionalBoolean.of(true), create(v -> OptionalBoolean.of(true)).test(1L)); - assertEquals(true, create(v -> OptionalBoolean.of(true)).orElse(false).test(1L)); - assertEquals(true, create(v -> OptionalBoolean.of(true)).orElseGet(() -> true).test(1L)); - assertEquals(OptionalBoolean.empty(), create(v -> OptionalBoolean.empty()).test(1L)); - assertEquals(false, create(v -> OptionalBoolean.empty()).orElse(false).test(1L)); - assertEquals(false, create(v -> OptionalBoolean.empty()).orElseGet(() -> false).test(1L)); - } - private OptionalLongPredicate create(OptionalLongPredicate lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalBoolean.of(true), create(v -> OptionalBoolean.of(true)).test(1L)); + assertEquals(true, create(v -> OptionalBoolean.of(true)).orElse(false).test(1L)); + assertEquals(true, create(v -> OptionalBoolean.of(true)).orElseGet(() -> true).test(1L)); + assertEquals(OptionalBoolean.empty(), create(v -> OptionalBoolean.empty()).test(1L)); + assertEquals(false, create(v -> OptionalBoolean.empty()).orElse(false).test(1L)); + assertEquals(false, create(v -> OptionalBoolean.empty()).orElseGet(() -> false).test(1L)); + } + private OptionalLongPredicate create(OptionalLongPredicate lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalLongSupplierTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalLongSupplierTest.java index f6bd7bc..16aec17 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalLongSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalLongSupplierTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalLongSupplierTest { - @Test - public void conversions() { - assertEquals(OptionalLong.of(2L), create(() -> OptionalLong.of(2L)).get()); - assertEquals(2L, create(() -> OptionalLong.of(2L)).orElse(3L).getAsLong()); - assertEquals(2L, create(() -> OptionalLong.of(2L)).orElseGet(() -> 2L).getAsLong()); - assertEquals(OptionalLong.empty(), create(() -> OptionalLong.empty()).get()); - assertEquals(3L, create(() -> OptionalLong.empty()).orElse(3L).getAsLong()); - assertEquals(3L, create(() -> OptionalLong.empty()).orElseGet(() -> 3L).getAsLong()); - } - private OptionalLongSupplier create(OptionalLongSupplier lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalLong.of(2L), create(() -> OptionalLong.of(2L)).get()); + assertEquals(2L, create(() -> OptionalLong.of(2L)).orElse(3L).getAsLong()); + assertEquals(2L, create(() -> OptionalLong.of(2L)).orElseGet(() -> 2L).getAsLong()); + assertEquals(OptionalLong.empty(), create(() -> OptionalLong.empty()).get()); + assertEquals(3L, create(() -> OptionalLong.empty()).orElse(3L).getAsLong()); + assertEquals(3L, create(() -> OptionalLong.empty()).orElseGet(() -> 3L).getAsLong()); + } + private OptionalLongSupplier create(OptionalLongSupplier lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalLongToDoubleFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalLongToDoubleFunctionTest.java index 1384eab..d92dfd7 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalLongToDoubleFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalLongToDoubleFunctionTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalLongToDoubleFunctionTest { - @Test - public void conversions() { - assertEquals(OptionalDouble.of(2.0), create(v -> OptionalDouble.of(2.0)).apply(1L)); - assertEquals(2.0, create(v -> OptionalDouble.of(2.0)).orElse(3.0).applyAsDouble(1L), 0.1); - assertEquals(2.0, create(v -> OptionalDouble.of(2.0)).orElseGet(() -> 2.0).applyAsDouble(1L), 0.1); - assertEquals(OptionalDouble.empty(), create(v -> OptionalDouble.empty()).apply(1L)); - assertEquals(3.0, create(v -> OptionalDouble.empty()).orElse(3.0).applyAsDouble(1L), 0.1); - assertEquals(3.0, create(v -> OptionalDouble.empty()).orElseGet(() -> 3.0).applyAsDouble(1L), 0.1); - } - private OptionalLongToDoubleFunction create(OptionalLongToDoubleFunction lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalDouble.of(2.0), create(v -> OptionalDouble.of(2.0)).apply(1L)); + assertEquals(2.0, create(v -> OptionalDouble.of(2.0)).orElse(3.0).applyAsDouble(1L), 0.1); + assertEquals(2.0, create(v -> OptionalDouble.of(2.0)).orElseGet(() -> 2.0).applyAsDouble(1L), 0.1); + assertEquals(OptionalDouble.empty(), create(v -> OptionalDouble.empty()).apply(1L)); + assertEquals(3.0, create(v -> OptionalDouble.empty()).orElse(3.0).applyAsDouble(1L), 0.1); + assertEquals(3.0, create(v -> OptionalDouble.empty()).orElseGet(() -> 3.0).applyAsDouble(1L), 0.1); + } + private OptionalLongToDoubleFunction create(OptionalLongToDoubleFunction lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalLongToIntFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalLongToIntFunctionTest.java index 0685a34..9dc4a72 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalLongToIntFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalLongToIntFunctionTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalLongToIntFunctionTest { - @Test - public void conversions() { - assertEquals(OptionalInt.of(2), create(v -> OptionalInt.of(2)).apply(1L)); - assertEquals(2, create(v -> OptionalInt.of(2)).orElse(3).applyAsInt(1L)); - assertEquals(2, create(v -> OptionalInt.of(2)).orElseGet(() -> 2).applyAsInt(1L)); - assertEquals(OptionalInt.empty(), create(v -> OptionalInt.empty()).apply(1L)); - assertEquals(3, create(v -> OptionalInt.empty()).orElse(3).applyAsInt(1L)); - assertEquals(3, create(v -> OptionalInt.empty()).orElseGet(() -> 3).applyAsInt(1L)); - } - private OptionalLongToIntFunction create(OptionalLongToIntFunction lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalInt.of(2), create(v -> OptionalInt.of(2)).apply(1L)); + assertEquals(2, create(v -> OptionalInt.of(2)).orElse(3).applyAsInt(1L)); + assertEquals(2, create(v -> OptionalInt.of(2)).orElseGet(() -> 2).applyAsInt(1L)); + assertEquals(OptionalInt.empty(), create(v -> OptionalInt.empty()).apply(1L)); + assertEquals(3, create(v -> OptionalInt.empty()).orElse(3).applyAsInt(1L)); + assertEquals(3, create(v -> OptionalInt.empty()).orElseGet(() -> 3).applyAsInt(1L)); + } + private OptionalLongToIntFunction create(OptionalLongToIntFunction lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalLongUnaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalLongUnaryOperatorTest.java index ac4fac9..ee3df44 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalLongUnaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalLongUnaryOperatorTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalLongUnaryOperatorTest { - @Test - public void conversions() { - assertEquals(OptionalLong.of(2L), create(o -> OptionalLong.of(2L)).apply(1L)); - assertEquals(2L, create(o -> OptionalLong.of(2L)).orElse(3L).applyAsLong(1L)); - assertEquals(2L, create(o -> OptionalLong.of(2L)).orElseGet(() -> 2L).applyAsLong(1L)); - assertEquals(OptionalLong.empty(), create(o -> OptionalLong.empty()).apply(1L)); - assertEquals(3L, create(o -> OptionalLong.empty()).orElse(3L).applyAsLong(1L)); - assertEquals(3L, create(o -> OptionalLong.empty()).orElseGet(() -> 3L).applyAsLong(1L)); - } - private OptionalLongUnaryOperator create(OptionalLongUnaryOperator lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalLong.of(2L), create(o -> OptionalLong.of(2L)).apply(1L)); + assertEquals(2L, create(o -> OptionalLong.of(2L)).orElse(3L).applyAsLong(1L)); + assertEquals(2L, create(o -> OptionalLong.of(2L)).orElseGet(() -> 2L).applyAsLong(1L)); + assertEquals(OptionalLong.empty(), create(o -> OptionalLong.empty()).apply(1L)); + assertEquals(3L, create(o -> OptionalLong.empty()).orElse(3L).applyAsLong(1L)); + assertEquals(3L, create(o -> OptionalLong.empty()).orElseGet(() -> 3L).applyAsLong(1L)); + } + private OptionalLongUnaryOperator create(OptionalLongUnaryOperator lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalPredicateTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalPredicateTest.java index cf487e8..be0fa8e 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalPredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalPredicateTest.java @@ -6,16 +6,16 @@ import org.junit.jupiter.api.*; public class OptionalPredicateTest { - @Test - public void conversions() { - assertEquals(OptionalBoolean.of(true), create(t -> OptionalBoolean.of(true)).test("input")); - assertEquals(true, create(t -> OptionalBoolean.of(true)).orElse(false).test("input")); - assertEquals(true, create(t -> OptionalBoolean.of(true)).orElseGet(() -> true).test("input")); - assertEquals(OptionalBoolean.empty(), create(t -> OptionalBoolean.empty()).test("input")); - assertEquals(false, create(t -> OptionalBoolean.empty()).orElse(false).test("input")); - assertEquals(false, create(t -> OptionalBoolean.empty()).orElseGet(() -> false).test("input")); - } - private OptionalPredicate create(OptionalPredicate lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalBoolean.of(true), create(t -> OptionalBoolean.of(true)).test("input")); + assertEquals(true, create(t -> OptionalBoolean.of(true)).orElse(false).test("input")); + assertEquals(true, create(t -> OptionalBoolean.of(true)).orElseGet(() -> true).test("input")); + assertEquals(OptionalBoolean.empty(), create(t -> OptionalBoolean.empty()).test("input")); + assertEquals(false, create(t -> OptionalBoolean.empty()).orElse(false).test("input")); + assertEquals(false, create(t -> OptionalBoolean.empty()).orElseGet(() -> false).test("input")); + } + private OptionalPredicate create(OptionalPredicate lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalSupplierTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalSupplierTest.java index 441e9a6..9302c7d 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalSupplierTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalSupplierTest { - @Test - public void conversions() { - assertEquals(Optional.of("value"), create(() -> Optional.of("value")).get()); - assertEquals("value", create(() -> Optional.of("value")).orElse("default").get()); - assertEquals("value", create(() -> Optional.of("value")).orElseGet(() -> "value").get()); - assertEquals(Optional.empty(), create(() -> Optional.empty()).get()); - assertEquals("default", create(() -> Optional.empty()).orElse("default").get()); - assertEquals("default", create(() -> Optional.empty()).orElseGet(() -> "default").get()); - } - private OptionalSupplier create(OptionalSupplier lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(Optional.of("value"), create(() -> Optional.of("value")).get()); + assertEquals("value", create(() -> Optional.of("value")).orElse("default").get()); + assertEquals("value", create(() -> Optional.of("value")).orElseGet(() -> "value").get()); + assertEquals(Optional.empty(), create(() -> Optional.empty()).get()); + assertEquals("default", create(() -> Optional.empty()).orElse("default").get()); + assertEquals("default", create(() -> Optional.empty()).orElseGet(() -> "default").get()); + } + private OptionalSupplier create(OptionalSupplier lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalToDoubleBiFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalToDoubleBiFunctionTest.java index 8287637..7da3c91 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalToDoubleBiFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalToDoubleBiFunctionTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalToDoubleBiFunctionTest { - @Test - public void conversions() { - assertEquals(OptionalDouble.of(2.0), create((t, u) -> OptionalDouble.of(2.0)).apply("input1", "input2")); - assertEquals(2.0, create((t, u) -> OptionalDouble.of(2.0)).orElse(3.0).applyAsDouble("input1", "input2"), 0.1); - assertEquals(2.0, create((t, u) -> OptionalDouble.of(2.0)).orElseGet(() -> 2.0).applyAsDouble("input1", "input2"), 0.1); - assertEquals(OptionalDouble.empty(), create((t, u) -> OptionalDouble.empty()).apply("input1", "input2")); - assertEquals(3.0, create((t, u) -> OptionalDouble.empty()).orElse(3.0).applyAsDouble("input1", "input2"), 0.1); - assertEquals(3.0, create((t, u) -> OptionalDouble.empty()).orElseGet(() -> 3.0).applyAsDouble("input1", "input2"), 0.1); - } - private OptionalToDoubleBiFunction create(OptionalToDoubleBiFunction lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalDouble.of(2.0), create((t, u) -> OptionalDouble.of(2.0)).apply("input1", "input2")); + assertEquals(2.0, create((t, u) -> OptionalDouble.of(2.0)).orElse(3.0).applyAsDouble("input1", "input2"), 0.1); + assertEquals(2.0, create((t, u) -> OptionalDouble.of(2.0)).orElseGet(() -> 2.0).applyAsDouble("input1", "input2"), 0.1); + assertEquals(OptionalDouble.empty(), create((t, u) -> OptionalDouble.empty()).apply("input1", "input2")); + assertEquals(3.0, create((t, u) -> OptionalDouble.empty()).orElse(3.0).applyAsDouble("input1", "input2"), 0.1); + assertEquals(3.0, create((t, u) -> OptionalDouble.empty()).orElseGet(() -> 3.0).applyAsDouble("input1", "input2"), 0.1); + } + private OptionalToDoubleBiFunction create(OptionalToDoubleBiFunction lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalToDoubleFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalToDoubleFunctionTest.java index b121f91..368b8ad 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalToDoubleFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalToDoubleFunctionTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalToDoubleFunctionTest { - @Test - public void conversions() { - assertEquals(OptionalDouble.of(2.0), create(v -> OptionalDouble.of(2.0)).apply("input")); - assertEquals(2.0, create(v -> OptionalDouble.of(2.0)).orElse(3.0).applyAsDouble("input"), 0.1); - assertEquals(2.0, create(v -> OptionalDouble.of(2.0)).orElseGet(() -> 2.0).applyAsDouble("input"), 0.1); - assertEquals(OptionalDouble.empty(), create(v -> OptionalDouble.empty()).apply("input")); - assertEquals(3.0, create(v -> OptionalDouble.empty()).orElse(3.0).applyAsDouble("input"), 0.1); - assertEquals(3.0, create(v -> OptionalDouble.empty()).orElseGet(() -> 3.0).applyAsDouble("input"), 0.1); - } - private OptionalToDoubleFunction create(OptionalToDoubleFunction lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalDouble.of(2.0), create(v -> OptionalDouble.of(2.0)).apply("input")); + assertEquals(2.0, create(v -> OptionalDouble.of(2.0)).orElse(3.0).applyAsDouble("input"), 0.1); + assertEquals(2.0, create(v -> OptionalDouble.of(2.0)).orElseGet(() -> 2.0).applyAsDouble("input"), 0.1); + assertEquals(OptionalDouble.empty(), create(v -> OptionalDouble.empty()).apply("input")); + assertEquals(3.0, create(v -> OptionalDouble.empty()).orElse(3.0).applyAsDouble("input"), 0.1); + assertEquals(3.0, create(v -> OptionalDouble.empty()).orElseGet(() -> 3.0).applyAsDouble("input"), 0.1); + } + private OptionalToDoubleFunction create(OptionalToDoubleFunction lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalToIntBiFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalToIntBiFunctionTest.java index d20ff72..6f72feb 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalToIntBiFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalToIntBiFunctionTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalToIntBiFunctionTest { - @Test - public void conversions() { - assertEquals(OptionalInt.of(2), create((t, u) -> OptionalInt.of(2)).apply("input1", "input2")); - assertEquals(2, create((t, u) -> OptionalInt.of(2)).orElse(3).applyAsInt("input1", "input2")); - assertEquals(2, create((t, u) -> OptionalInt.of(2)).orElseGet(() -> 2).applyAsInt("input1", "input2")); - assertEquals(OptionalInt.empty(), create((t, u) -> OptionalInt.empty()).apply("input1", "input2")); - assertEquals(3, create((t, u) -> OptionalInt.empty()).orElse(3).applyAsInt("input1", "input2")); - assertEquals(3, create((t, u) -> OptionalInt.empty()).orElseGet(() -> 3).applyAsInt("input1", "input2")); - } - private OptionalToIntBiFunction create(OptionalToIntBiFunction lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalInt.of(2), create((t, u) -> OptionalInt.of(2)).apply("input1", "input2")); + assertEquals(2, create((t, u) -> OptionalInt.of(2)).orElse(3).applyAsInt("input1", "input2")); + assertEquals(2, create((t, u) -> OptionalInt.of(2)).orElseGet(() -> 2).applyAsInt("input1", "input2")); + assertEquals(OptionalInt.empty(), create((t, u) -> OptionalInt.empty()).apply("input1", "input2")); + assertEquals(3, create((t, u) -> OptionalInt.empty()).orElse(3).applyAsInt("input1", "input2")); + assertEquals(3, create((t, u) -> OptionalInt.empty()).orElseGet(() -> 3).applyAsInt("input1", "input2")); + } + private OptionalToIntBiFunction create(OptionalToIntBiFunction lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalToIntFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalToIntFunctionTest.java index 9777157..80887f2 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalToIntFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalToIntFunctionTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalToIntFunctionTest { - @Test - public void conversions() { - assertEquals(OptionalInt.of(2), create(v -> OptionalInt.of(2)).apply("input")); - assertEquals(2, create(v -> OptionalInt.of(2)).orElse(3).applyAsInt("input")); - assertEquals(2, create(v -> OptionalInt.of(2)).orElseGet(() -> 2).applyAsInt("input")); - assertEquals(OptionalInt.empty(), create(v -> OptionalInt.empty()).apply("input")); - assertEquals(3, create(v -> OptionalInt.empty()).orElse(3).applyAsInt("input")); - assertEquals(3, create(v -> OptionalInt.empty()).orElseGet(() -> 3).applyAsInt("input")); - } - private OptionalToIntFunction create(OptionalToIntFunction lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalInt.of(2), create(v -> OptionalInt.of(2)).apply("input")); + assertEquals(2, create(v -> OptionalInt.of(2)).orElse(3).applyAsInt("input")); + assertEquals(2, create(v -> OptionalInt.of(2)).orElseGet(() -> 2).applyAsInt("input")); + assertEquals(OptionalInt.empty(), create(v -> OptionalInt.empty()).apply("input")); + assertEquals(3, create(v -> OptionalInt.empty()).orElse(3).applyAsInt("input")); + assertEquals(3, create(v -> OptionalInt.empty()).orElseGet(() -> 3).applyAsInt("input")); + } + private OptionalToIntFunction create(OptionalToIntFunction lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalToLongBiFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalToLongBiFunctionTest.java index 878b43d..5322539 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalToLongBiFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalToLongBiFunctionTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalToLongBiFunctionTest { - @Test - public void conversions() { - assertEquals(OptionalLong.of(2L), create((t, u) -> OptionalLong.of(2L)).apply("input1", "input2")); - assertEquals(2L, create((t, u) -> OptionalLong.of(2L)).orElse(3L).applyAsLong("input1", "input2")); - assertEquals(2L, create((t, u) -> OptionalLong.of(2L)).orElseGet(() -> 2L).applyAsLong("input1", "input2")); - assertEquals(OptionalLong.empty(), create((t, u) -> OptionalLong.empty()).apply("input1", "input2")); - assertEquals(3L, create((t, u) -> OptionalLong.empty()).orElse(3L).applyAsLong("input1", "input2")); - assertEquals(3L, create((t, u) -> OptionalLong.empty()).orElseGet(() -> 3L).applyAsLong("input1", "input2")); - } - private OptionalToLongBiFunction create(OptionalToLongBiFunction lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalLong.of(2L), create((t, u) -> OptionalLong.of(2L)).apply("input1", "input2")); + assertEquals(2L, create((t, u) -> OptionalLong.of(2L)).orElse(3L).applyAsLong("input1", "input2")); + assertEquals(2L, create((t, u) -> OptionalLong.of(2L)).orElseGet(() -> 2L).applyAsLong("input1", "input2")); + assertEquals(OptionalLong.empty(), create((t, u) -> OptionalLong.empty()).apply("input1", "input2")); + assertEquals(3L, create((t, u) -> OptionalLong.empty()).orElse(3L).applyAsLong("input1", "input2")); + assertEquals(3L, create((t, u) -> OptionalLong.empty()).orElseGet(() -> 3L).applyAsLong("input1", "input2")); + } + private OptionalToLongBiFunction create(OptionalToLongBiFunction lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalToLongFunctionTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalToLongFunctionTest.java index 532920d..77bdf1f 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalToLongFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalToLongFunctionTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalToLongFunctionTest { - @Test - public void conversions() { - assertEquals(OptionalLong.of(2L), create(v -> OptionalLong.of(2L)).apply("input")); - assertEquals(2L, create(v -> OptionalLong.of(2L)).orElse(3L).applyAsLong("input")); - assertEquals(2L, create(v -> OptionalLong.of(2L)).orElseGet(() -> 2L).applyAsLong("input")); - assertEquals(OptionalLong.empty(), create(v -> OptionalLong.empty()).apply("input")); - assertEquals(3L, create(v -> OptionalLong.empty()).orElse(3L).applyAsLong("input")); - assertEquals(3L, create(v -> OptionalLong.empty()).orElseGet(() -> 3L).applyAsLong("input")); - } - private OptionalToLongFunction create(OptionalToLongFunction lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(OptionalLong.of(2L), create(v -> OptionalLong.of(2L)).apply("input")); + assertEquals(2L, create(v -> OptionalLong.of(2L)).orElse(3L).applyAsLong("input")); + assertEquals(2L, create(v -> OptionalLong.of(2L)).orElseGet(() -> 2L).applyAsLong("input")); + assertEquals(OptionalLong.empty(), create(v -> OptionalLong.empty()).apply("input")); + assertEquals(3L, create(v -> OptionalLong.empty()).orElse(3L).applyAsLong("input")); + assertEquals(3L, create(v -> OptionalLong.empty()).orElseGet(() -> 3L).applyAsLong("input")); + } + private OptionalToLongFunction create(OptionalToLongFunction lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/optional/OptionalUnaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/optional/OptionalUnaryOperatorTest.java index 5e5b377..a445783 100644 --- a/src/test/java/com/machinezoo/noexception/optional/OptionalUnaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/optional/OptionalUnaryOperatorTest.java @@ -7,16 +7,16 @@ import org.junit.jupiter.api.*; public class OptionalUnaryOperatorTest { - @Test - public void conversions() { - assertEquals(Optional.of("value"), create(o -> Optional.of("value")).apply("input")); - assertEquals("value", create(o -> Optional.of("value")).orElse("default").apply("input")); - assertEquals("value", create(o -> Optional.of("value")).orElseGet(() -> "value").apply("input")); - assertEquals(Optional.empty(), create(o -> Optional.empty()).apply("input")); - assertEquals("default", create(o -> Optional.empty()).orElse("default").apply("input")); - assertEquals("default", create(o -> Optional.empty()).orElseGet(() -> "default").apply("input")); - } - private OptionalUnaryOperator create(OptionalUnaryOperator lambda) { - return lambda; - } + @Test + public void conversions() { + assertEquals(Optional.of("value"), create(o -> Optional.of("value")).apply("input")); + assertEquals("value", create(o -> Optional.of("value")).orElse("default").apply("input")); + assertEquals("value", create(o -> Optional.of("value")).orElseGet(() -> "value").apply("input")); + assertEquals(Optional.empty(), create(o -> Optional.empty()).apply("input")); + assertEquals("default", create(o -> Optional.empty()).orElse("default").apply("input")); + assertEquals("default", create(o -> Optional.empty()).orElseGet(() -> "default").apply("input")); + } + private OptionalUnaryOperator create(OptionalUnaryOperator lambda) { + return lambda; + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingBiConsumerTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingBiConsumerTest.java index e6b8607..7b7ebef 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingBiConsumerTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingBiConsumerTest.java @@ -8,28 +8,28 @@ import org.junit.jupiter.api.*; public class ThrowingBiConsumerTest { - void takeThrowing(ThrowingBiConsumer functional) { - } - void takeNonThrowing(BiConsumer functional) { - } - @Test - public void lambdas() { - takeNonThrowing((t, u) -> { - }); - takeThrowing((t, u) -> { - }); - takeThrowing((t, u) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return; - }); - Throwable throwable = new IOException(); - takeThrowing((t, u) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return; - }); - } + void takeThrowing(ThrowingBiConsumer functional) { + } + void takeNonThrowing(BiConsumer functional) { + } + @Test + public void lambdas() { + takeNonThrowing((t, u) -> { + }); + takeThrowing((t, u) -> { + }); + takeThrowing((t, u) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return; + }); + Throwable throwable = new IOException(); + takeThrowing((t, u) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingBiFunctionTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingBiFunctionTest.java index 5e0fd6f..26dd16f 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingBiFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingBiFunctionTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingBiFunctionTest { - void takeThrowing(ThrowingBiFunction functional) { - } - void takeNonThrowing(BiFunction functional) { - } - @Test - public void lambdas() { - takeNonThrowing((t, u) -> "value"); - takeThrowing((t, u) -> "value"); - takeThrowing((t, u) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return "value"; - }); - Throwable throwable = new IOException(); - takeThrowing((t, u) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return "value"; - }); - } + void takeThrowing(ThrowingBiFunction functional) { + } + void takeNonThrowing(BiFunction functional) { + } + @Test + public void lambdas() { + takeNonThrowing((t, u) -> "value"); + takeThrowing((t, u) -> "value"); + takeThrowing((t, u) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return "value"; + }); + Throwable throwable = new IOException(); + takeThrowing((t, u) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return "value"; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingBiPredicateTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingBiPredicateTest.java index 0fc5925..d4011d7 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingBiPredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingBiPredicateTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingBiPredicateTest { - void takeThrowing(ThrowingBiPredicate functional) { - } - void takeNonThrowing(BiPredicate functional) { - } - @Test - public void lambdas() { - takeNonThrowing((t, u) -> true); - takeThrowing((t, u) -> true); - takeThrowing((t, u) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return true; - }); - Throwable throwable = new IOException(); - takeThrowing((t, u) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return true; - }); - } + void takeThrowing(ThrowingBiPredicate functional) { + } + void takeNonThrowing(BiPredicate functional) { + } + @Test + public void lambdas() { + takeNonThrowing((t, u) -> true); + takeThrowing((t, u) -> true); + takeThrowing((t, u) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return true; + }); + Throwable throwable = new IOException(); + takeThrowing((t, u) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return true; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingBinaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingBinaryOperatorTest.java index d6cb835..b50fd34 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingBinaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingBinaryOperatorTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingBinaryOperatorTest { - void takeThrowing(ThrowingBinaryOperator functional) { - } - void takeNonThrowing(BinaryOperator functional) { - } - @Test - public void lambdas() { - takeNonThrowing((l, r) -> "value"); - takeThrowing((l, r) -> "value"); - takeThrowing((l, r) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return "value"; - }); - Throwable throwable = new IOException(); - takeThrowing((l, r) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return "value"; - }); - } + void takeThrowing(ThrowingBinaryOperator functional) { + } + void takeNonThrowing(BinaryOperator functional) { + } + @Test + public void lambdas() { + takeNonThrowing((l, r) -> "value"); + takeThrowing((l, r) -> "value"); + takeThrowing((l, r) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return "value"; + }); + Throwable throwable = new IOException(); + takeThrowing((l, r) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return "value"; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingBooleanSupplierTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingBooleanSupplierTest.java index bcb5c76..170125e 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingBooleanSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingBooleanSupplierTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingBooleanSupplierTest { - void takeThrowing(ThrowingBooleanSupplier functional) { - } - void takeNonThrowing(BooleanSupplier functional) { - } - @Test - public void lambdas() { - takeNonThrowing(() -> true); - takeThrowing(() -> true); - takeThrowing(() -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return true; - }); - Throwable throwable = new IOException(); - takeThrowing(() -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return true; - }); - } + void takeThrowing(ThrowingBooleanSupplier functional) { + } + void takeNonThrowing(BooleanSupplier functional) { + } + @Test + public void lambdas() { + takeNonThrowing(() -> true); + takeThrowing(() -> true); + takeThrowing(() -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return true; + }); + Throwable throwable = new IOException(); + takeThrowing(() -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return true; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingComparatorTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingComparatorTest.java index f95677b..fa66953 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingComparatorTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingComparatorTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingComparatorTest { - void takeThrowing(ThrowingComparator functional) { - } - void takeNonThrowing(Comparator functional) { - } - @Test - public void lambdas() { - takeNonThrowing((l, r) -> 2); - takeThrowing((l, r) -> 2); - takeThrowing((l, r) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2; - }); - Throwable throwable = new IOException(); - takeThrowing((l, r) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2; - }); - } + void takeThrowing(ThrowingComparator functional) { + } + void takeNonThrowing(Comparator functional) { + } + @Test + public void lambdas() { + takeNonThrowing((l, r) -> 2); + takeThrowing((l, r) -> 2); + takeThrowing((l, r) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2; + }); + Throwable throwable = new IOException(); + takeThrowing((l, r) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingConsumerTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingConsumerTest.java index 664357d..3a57314 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingConsumerTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingConsumerTest.java @@ -8,28 +8,28 @@ import org.junit.jupiter.api.*; public class ThrowingConsumerTest { - void takeThrowing(ThrowingConsumer functional) { - } - void takeNonThrowing(Consumer functional) { - } - @Test - public void lambdas() { - takeNonThrowing(t -> { - }); - takeThrowing(t -> { - }); - takeThrowing(t -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return; - }); - Throwable throwable = new IOException(); - takeThrowing(t -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return; - }); - } + void takeThrowing(ThrowingConsumer functional) { + } + void takeNonThrowing(Consumer functional) { + } + @Test + public void lambdas() { + takeNonThrowing(t -> { + }); + takeThrowing(t -> { + }); + takeThrowing(t -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return; + }); + Throwable throwable = new IOException(); + takeThrowing(t -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleBinaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleBinaryOperatorTest.java index 6f0ae1f..5a33cb7 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleBinaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleBinaryOperatorTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingDoubleBinaryOperatorTest { - void takeThrowing(ThrowingDoubleBinaryOperator functional) { - } - void takeNonThrowing(DoubleBinaryOperator functional) { - } - @Test - public void lambdas() { - takeNonThrowing((l, r) -> 2.0); - takeThrowing((l, r) -> 2.0); - takeThrowing((l, r) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2.0; - }); - Throwable throwable = new IOException(); - takeThrowing((l, r) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2.0; - }); - } + void takeThrowing(ThrowingDoubleBinaryOperator functional) { + } + void takeNonThrowing(DoubleBinaryOperator functional) { + } + @Test + public void lambdas() { + takeNonThrowing((l, r) -> 2.0); + takeThrowing((l, r) -> 2.0); + takeThrowing((l, r) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2.0; + }); + Throwable throwable = new IOException(); + takeThrowing((l, r) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2.0; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleConsumerTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleConsumerTest.java index 31d3f97..23943b4 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleConsumerTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleConsumerTest.java @@ -8,28 +8,28 @@ import org.junit.jupiter.api.*; public class ThrowingDoubleConsumerTest { - void takeThrowing(ThrowingDoubleConsumer functional) { - } - void takeNonThrowing(DoubleConsumer functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> { - }); - takeThrowing(v -> { - }); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return; - }); - } + void takeThrowing(ThrowingDoubleConsumer functional) { + } + void takeNonThrowing(DoubleConsumer functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> { + }); + takeThrowing(v -> { + }); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleFunctionTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleFunctionTest.java index 34f146a..cd498a5 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleFunctionTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingDoubleFunctionTest { - void takeThrowing(ThrowingDoubleFunction functional) { - } - void takeNonThrowing(DoubleFunction functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> "value"); - takeThrowing(v -> "value"); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return "value"; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return "value"; - }); - } + void takeThrowing(ThrowingDoubleFunction functional) { + } + void takeNonThrowing(DoubleFunction functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> "value"); + takeThrowing(v -> "value"); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return "value"; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return "value"; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoublePredicateTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoublePredicateTest.java index 4d0df2e..50718c9 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoublePredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoublePredicateTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingDoublePredicateTest { - void takeThrowing(ThrowingDoublePredicate functional) { - } - void takeNonThrowing(DoublePredicate functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> true); - takeThrowing(v -> true); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return true; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return true; - }); - } + void takeThrowing(ThrowingDoublePredicate functional) { + } + void takeNonThrowing(DoublePredicate functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> true); + takeThrowing(v -> true); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return true; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return true; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleSupplierTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleSupplierTest.java index e54ef2a..99b9f4b 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleSupplierTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingDoubleSupplierTest { - void takeThrowing(ThrowingDoubleSupplier functional) { - } - void takeNonThrowing(DoubleSupplier functional) { - } - @Test - public void lambdas() { - takeNonThrowing(() -> 2.0); - takeThrowing(() -> 2.0); - takeThrowing(() -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2.0; - }); - Throwable throwable = new IOException(); - takeThrowing(() -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2.0; - }); - } + void takeThrowing(ThrowingDoubleSupplier functional) { + } + void takeNonThrowing(DoubleSupplier functional) { + } + @Test + public void lambdas() { + takeNonThrowing(() -> 2.0); + takeThrowing(() -> 2.0); + takeThrowing(() -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2.0; + }); + Throwable throwable = new IOException(); + takeThrowing(() -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2.0; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleToIntFunctionTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleToIntFunctionTest.java index 7cfafa7..596a2de 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleToIntFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleToIntFunctionTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingDoubleToIntFunctionTest { - void takeThrowing(ThrowingDoubleToIntFunction functional) { - } - void takeNonThrowing(DoubleToIntFunction functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> 2); - takeThrowing(v -> 2); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2; - }); - } + void takeThrowing(ThrowingDoubleToIntFunction functional) { + } + void takeNonThrowing(DoubleToIntFunction functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> 2); + takeThrowing(v -> 2); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleToLongFunctionTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleToLongFunctionTest.java index 953e8b2..b3a3a81 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleToLongFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleToLongFunctionTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingDoubleToLongFunctionTest { - void takeThrowing(ThrowingDoubleToLongFunction functional) { - } - void takeNonThrowing(DoubleToLongFunction functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> 2L); - takeThrowing(v -> 2L); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2L; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2L; - }); - } + void takeThrowing(ThrowingDoubleToLongFunction functional) { + } + void takeNonThrowing(DoubleToLongFunction functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> 2L); + takeThrowing(v -> 2L); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2L; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2L; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleUnaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleUnaryOperatorTest.java index 58f2047..83e6310 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleUnaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingDoubleUnaryOperatorTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingDoubleUnaryOperatorTest { - void takeThrowing(ThrowingDoubleUnaryOperator functional) { - } - void takeNonThrowing(DoubleUnaryOperator functional) { - } - @Test - public void lambdas() { - takeNonThrowing(o -> 2.0); - takeThrowing(o -> 2.0); - takeThrowing(o -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2.0; - }); - Throwable throwable = new IOException(); - takeThrowing(o -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2.0; - }); - } + void takeThrowing(ThrowingDoubleUnaryOperator functional) { + } + void takeNonThrowing(DoubleUnaryOperator functional) { + } + @Test + public void lambdas() { + takeNonThrowing(o -> 2.0); + takeThrowing(o -> 2.0); + takeThrowing(o -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2.0; + }); + Throwable throwable = new IOException(); + takeThrowing(o -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2.0; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingFunctionTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingFunctionTest.java index f8bc7e8..f6677aa 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingFunctionTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingFunctionTest { - void takeThrowing(ThrowingFunction functional) { - } - void takeNonThrowing(Function functional) { - } - @Test - public void lambdas() { - takeNonThrowing(t -> "value"); - takeThrowing(t -> "value"); - takeThrowing(t -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return "value"; - }); - Throwable throwable = new IOException(); - takeThrowing(t -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return "value"; - }); - } + void takeThrowing(ThrowingFunction functional) { + } + void takeNonThrowing(Function functional) { + } + @Test + public void lambdas() { + takeNonThrowing(t -> "value"); + takeThrowing(t -> "value"); + takeThrowing(t -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return "value"; + }); + Throwable throwable = new IOException(); + takeThrowing(t -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return "value"; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntBinaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntBinaryOperatorTest.java index 3535c0a..af66a8d 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntBinaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntBinaryOperatorTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingIntBinaryOperatorTest { - void takeThrowing(ThrowingIntBinaryOperator functional) { - } - void takeNonThrowing(IntBinaryOperator functional) { - } - @Test - public void lambdas() { - takeNonThrowing((l, r) -> 2); - takeThrowing((l, r) -> 2); - takeThrowing((l, r) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2; - }); - Throwable throwable = new IOException(); - takeThrowing((l, r) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2; - }); - } + void takeThrowing(ThrowingIntBinaryOperator functional) { + } + void takeNonThrowing(IntBinaryOperator functional) { + } + @Test + public void lambdas() { + takeNonThrowing((l, r) -> 2); + takeThrowing((l, r) -> 2); + takeThrowing((l, r) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2; + }); + Throwable throwable = new IOException(); + takeThrowing((l, r) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntConsumerTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntConsumerTest.java index eed9c4f..e4a6826 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntConsumerTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntConsumerTest.java @@ -8,28 +8,28 @@ import org.junit.jupiter.api.*; public class ThrowingIntConsumerTest { - void takeThrowing(ThrowingIntConsumer functional) { - } - void takeNonThrowing(IntConsumer functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> { - }); - takeThrowing(v -> { - }); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return; - }); - } + void takeThrowing(ThrowingIntConsumer functional) { + } + void takeNonThrowing(IntConsumer functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> { + }); + takeThrowing(v -> { + }); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntFunctionTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntFunctionTest.java index f7ddda8..eff77e6 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntFunctionTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingIntFunctionTest { - void takeThrowing(ThrowingIntFunction functional) { - } - void takeNonThrowing(IntFunction functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> "value"); - takeThrowing(v -> "value"); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return "value"; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return "value"; - }); - } + void takeThrowing(ThrowingIntFunction functional) { + } + void takeNonThrowing(IntFunction functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> "value"); + takeThrowing(v -> "value"); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return "value"; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return "value"; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntPredicateTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntPredicateTest.java index 83a15b7..7c78051 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntPredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntPredicateTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingIntPredicateTest { - void takeThrowing(ThrowingIntPredicate functional) { - } - void takeNonThrowing(IntPredicate functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> true); - takeThrowing(v -> true); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return true; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return true; - }); - } + void takeThrowing(ThrowingIntPredicate functional) { + } + void takeNonThrowing(IntPredicate functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> true); + takeThrowing(v -> true); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return true; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return true; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntSupplierTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntSupplierTest.java index 6ebfaff..536062a 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntSupplierTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingIntSupplierTest { - void takeThrowing(ThrowingIntSupplier functional) { - } - void takeNonThrowing(IntSupplier functional) { - } - @Test - public void lambdas() { - takeNonThrowing(() -> 2); - takeThrowing(() -> 2); - takeThrowing(() -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2; - }); - Throwable throwable = new IOException(); - takeThrowing(() -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2; - }); - } + void takeThrowing(ThrowingIntSupplier functional) { + } + void takeNonThrowing(IntSupplier functional) { + } + @Test + public void lambdas() { + takeNonThrowing(() -> 2); + takeThrowing(() -> 2); + takeThrowing(() -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2; + }); + Throwable throwable = new IOException(); + takeThrowing(() -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntToDoubleFunctionTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntToDoubleFunctionTest.java index f94a93a..ddb8475 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntToDoubleFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntToDoubleFunctionTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingIntToDoubleFunctionTest { - void takeThrowing(ThrowingIntToDoubleFunction functional) { - } - void takeNonThrowing(IntToDoubleFunction functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> 2.0); - takeThrowing(v -> 2.0); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2.0; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2.0; - }); - } + void takeThrowing(ThrowingIntToDoubleFunction functional) { + } + void takeNonThrowing(IntToDoubleFunction functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> 2.0); + takeThrowing(v -> 2.0); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2.0; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2.0; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntToLongFunctionTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntToLongFunctionTest.java index 114d66c..1c5ed56 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntToLongFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntToLongFunctionTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingIntToLongFunctionTest { - void takeThrowing(ThrowingIntToLongFunction functional) { - } - void takeNonThrowing(IntToLongFunction functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> 2L); - takeThrowing(v -> 2L); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2L; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2L; - }); - } + void takeThrowing(ThrowingIntToLongFunction functional) { + } + void takeNonThrowing(IntToLongFunction functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> 2L); + takeThrowing(v -> 2L); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2L; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2L; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntUnaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntUnaryOperatorTest.java index f9b06f5..e786d05 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntUnaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingIntUnaryOperatorTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingIntUnaryOperatorTest { - void takeThrowing(ThrowingIntUnaryOperator functional) { - } - void takeNonThrowing(IntUnaryOperator functional) { - } - @Test - public void lambdas() { - takeNonThrowing(o -> 2); - takeThrowing(o -> 2); - takeThrowing(o -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2; - }); - Throwable throwable = new IOException(); - takeThrowing(o -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2; - }); - } + void takeThrowing(ThrowingIntUnaryOperator functional) { + } + void takeNonThrowing(IntUnaryOperator functional) { + } + @Test + public void lambdas() { + takeNonThrowing(o -> 2); + takeThrowing(o -> 2); + takeThrowing(o -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2; + }); + Throwable throwable = new IOException(); + takeThrowing(o -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongBinaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongBinaryOperatorTest.java index 0417f13..5e0a0b6 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongBinaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongBinaryOperatorTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingLongBinaryOperatorTest { - void takeThrowing(ThrowingLongBinaryOperator functional) { - } - void takeNonThrowing(LongBinaryOperator functional) { - } - @Test - public void lambdas() { - takeNonThrowing((l, r) -> 2L); - takeThrowing((l, r) -> 2L); - takeThrowing((l, r) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2L; - }); - Throwable throwable = new IOException(); - takeThrowing((l, r) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2L; - }); - } + void takeThrowing(ThrowingLongBinaryOperator functional) { + } + void takeNonThrowing(LongBinaryOperator functional) { + } + @Test + public void lambdas() { + takeNonThrowing((l, r) -> 2L); + takeThrowing((l, r) -> 2L); + takeThrowing((l, r) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2L; + }); + Throwable throwable = new IOException(); + takeThrowing((l, r) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2L; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongConsumerTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongConsumerTest.java index e108e7b..d3198fb 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongConsumerTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongConsumerTest.java @@ -8,28 +8,28 @@ import org.junit.jupiter.api.*; public class ThrowingLongConsumerTest { - void takeThrowing(ThrowingLongConsumer functional) { - } - void takeNonThrowing(LongConsumer functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> { - }); - takeThrowing(v -> { - }); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return; - }); - } + void takeThrowing(ThrowingLongConsumer functional) { + } + void takeNonThrowing(LongConsumer functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> { + }); + takeThrowing(v -> { + }); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongFunctionTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongFunctionTest.java index 06b156e..faa4891 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongFunctionTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingLongFunctionTest { - void takeThrowing(ThrowingLongFunction functional) { - } - void takeNonThrowing(LongFunction functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> "value"); - takeThrowing(v -> "value"); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return "value"; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return "value"; - }); - } + void takeThrowing(ThrowingLongFunction functional) { + } + void takeNonThrowing(LongFunction functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> "value"); + takeThrowing(v -> "value"); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return "value"; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return "value"; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongPredicateTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongPredicateTest.java index a890642..2e9933a 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongPredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongPredicateTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingLongPredicateTest { - void takeThrowing(ThrowingLongPredicate functional) { - } - void takeNonThrowing(LongPredicate functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> true); - takeThrowing(v -> true); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return true; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return true; - }); - } + void takeThrowing(ThrowingLongPredicate functional) { + } + void takeNonThrowing(LongPredicate functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> true); + takeThrowing(v -> true); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return true; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return true; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongSupplierTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongSupplierTest.java index ac36c78..84f044b 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongSupplierTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingLongSupplierTest { - void takeThrowing(ThrowingLongSupplier functional) { - } - void takeNonThrowing(LongSupplier functional) { - } - @Test - public void lambdas() { - takeNonThrowing(() -> 2L); - takeThrowing(() -> 2L); - takeThrowing(() -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2L; - }); - Throwable throwable = new IOException(); - takeThrowing(() -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2L; - }); - } + void takeThrowing(ThrowingLongSupplier functional) { + } + void takeNonThrowing(LongSupplier functional) { + } + @Test + public void lambdas() { + takeNonThrowing(() -> 2L); + takeThrowing(() -> 2L); + takeThrowing(() -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2L; + }); + Throwable throwable = new IOException(); + takeThrowing(() -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2L; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongToDoubleFunctionTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongToDoubleFunctionTest.java index 469973d..a37ebbd 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongToDoubleFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongToDoubleFunctionTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingLongToDoubleFunctionTest { - void takeThrowing(ThrowingLongToDoubleFunction functional) { - } - void takeNonThrowing(LongToDoubleFunction functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> 2.0); - takeThrowing(v -> 2.0); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2.0; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2.0; - }); - } + void takeThrowing(ThrowingLongToDoubleFunction functional) { + } + void takeNonThrowing(LongToDoubleFunction functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> 2.0); + takeThrowing(v -> 2.0); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2.0; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2.0; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongToIntFunctionTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongToIntFunctionTest.java index 050d16b..abdebfc 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongToIntFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongToIntFunctionTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingLongToIntFunctionTest { - void takeThrowing(ThrowingLongToIntFunction functional) { - } - void takeNonThrowing(LongToIntFunction functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> 2); - takeThrowing(v -> 2); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2; - }); - } + void takeThrowing(ThrowingLongToIntFunction functional) { + } + void takeNonThrowing(LongToIntFunction functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> 2); + takeThrowing(v -> 2); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongUnaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongUnaryOperatorTest.java index ad91b6d..6289c41 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongUnaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingLongUnaryOperatorTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingLongUnaryOperatorTest { - void takeThrowing(ThrowingLongUnaryOperator functional) { - } - void takeNonThrowing(LongUnaryOperator functional) { - } - @Test - public void lambdas() { - takeNonThrowing(o -> 2L); - takeThrowing(o -> 2L); - takeThrowing(o -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2L; - }); - Throwable throwable = new IOException(); - takeThrowing(o -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2L; - }); - } + void takeThrowing(ThrowingLongUnaryOperator functional) { + } + void takeNonThrowing(LongUnaryOperator functional) { + } + @Test + public void lambdas() { + takeNonThrowing(o -> 2L); + takeThrowing(o -> 2L); + takeThrowing(o -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2L; + }); + Throwable throwable = new IOException(); + takeThrowing(o -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2L; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingObjDoubleConsumerTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingObjDoubleConsumerTest.java index b91c777..d52a7d7 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingObjDoubleConsumerTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingObjDoubleConsumerTest.java @@ -8,28 +8,28 @@ import org.junit.jupiter.api.*; public class ThrowingObjDoubleConsumerTest { - void takeThrowing(ThrowingObjDoubleConsumer functional) { - } - void takeNonThrowing(ObjDoubleConsumer functional) { - } - @Test - public void lambdas() { - takeNonThrowing((t, v) -> { - }); - takeThrowing((t, v) -> { - }); - takeThrowing((t, v) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return; - }); - Throwable throwable = new IOException(); - takeThrowing((t, v) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return; - }); - } + void takeThrowing(ThrowingObjDoubleConsumer functional) { + } + void takeNonThrowing(ObjDoubleConsumer functional) { + } + @Test + public void lambdas() { + takeNonThrowing((t, v) -> { + }); + takeThrowing((t, v) -> { + }); + takeThrowing((t, v) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return; + }); + Throwable throwable = new IOException(); + takeThrowing((t, v) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingObjIntConsumerTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingObjIntConsumerTest.java index bef5684..25246d0 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingObjIntConsumerTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingObjIntConsumerTest.java @@ -8,28 +8,28 @@ import org.junit.jupiter.api.*; public class ThrowingObjIntConsumerTest { - void takeThrowing(ThrowingObjIntConsumer functional) { - } - void takeNonThrowing(ObjIntConsumer functional) { - } - @Test - public void lambdas() { - takeNonThrowing((t, v) -> { - }); - takeThrowing((t, v) -> { - }); - takeThrowing((t, v) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return; - }); - Throwable throwable = new IOException(); - takeThrowing((t, v) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return; - }); - } + void takeThrowing(ThrowingObjIntConsumer functional) { + } + void takeNonThrowing(ObjIntConsumer functional) { + } + @Test + public void lambdas() { + takeNonThrowing((t, v) -> { + }); + takeThrowing((t, v) -> { + }); + takeThrowing((t, v) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return; + }); + Throwable throwable = new IOException(); + takeThrowing((t, v) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingObjLongConsumerTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingObjLongConsumerTest.java index 56b78d5..c22be74 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingObjLongConsumerTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingObjLongConsumerTest.java @@ -8,28 +8,28 @@ import org.junit.jupiter.api.*; public class ThrowingObjLongConsumerTest { - void takeThrowing(ThrowingObjLongConsumer functional) { - } - void takeNonThrowing(ObjLongConsumer functional) { - } - @Test - public void lambdas() { - takeNonThrowing((t, v) -> { - }); - takeThrowing((t, v) -> { - }); - takeThrowing((t, v) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return; - }); - Throwable throwable = new IOException(); - takeThrowing((t, v) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return; - }); - } + void takeThrowing(ThrowingObjLongConsumer functional) { + } + void takeNonThrowing(ObjLongConsumer functional) { + } + @Test + public void lambdas() { + takeNonThrowing((t, v) -> { + }); + takeThrowing((t, v) -> { + }); + takeThrowing((t, v) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return; + }); + Throwable throwable = new IOException(); + takeThrowing((t, v) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingPredicateTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingPredicateTest.java index da8ccee..35b9a12 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingPredicateTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingPredicateTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingPredicateTest { - void takeThrowing(ThrowingPredicate functional) { - } - void takeNonThrowing(Predicate functional) { - } - @Test - public void lambdas() { - takeNonThrowing(t -> true); - takeThrowing(t -> true); - takeThrowing(t -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return true; - }); - Throwable throwable = new IOException(); - takeThrowing(t -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return true; - }); - } + void takeThrowing(ThrowingPredicate functional) { + } + void takeNonThrowing(Predicate functional) { + } + @Test + public void lambdas() { + takeNonThrowing(t -> true); + takeThrowing(t -> true); + takeThrowing(t -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return true; + }); + Throwable throwable = new IOException(); + takeThrowing(t -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return true; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingRunnableTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingRunnableTest.java index c8e069d..f3f72d2 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingRunnableTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingRunnableTest.java @@ -7,28 +7,28 @@ import org.junit.jupiter.api.*; public class ThrowingRunnableTest { - void takeThrowing(ThrowingRunnable functional) { - } - void takeNonThrowing(Runnable functional) { - } - @Test - public void lambdas() { - takeNonThrowing(() -> { - }); - takeThrowing(() -> { - }); - takeThrowing(() -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return; - }); - Throwable throwable = new IOException(); - takeThrowing(() -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return; - }); - } + void takeThrowing(ThrowingRunnable functional) { + } + void takeNonThrowing(Runnable functional) { + } + @Test + public void lambdas() { + takeNonThrowing(() -> { + }); + takeThrowing(() -> { + }); + takeThrowing(() -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return; + }); + Throwable throwable = new IOException(); + takeThrowing(() -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingSupplierTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingSupplierTest.java index 1f24da3..5869046 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingSupplierTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingSupplierTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingSupplierTest { - void takeThrowing(ThrowingSupplier functional) { - } - void takeNonThrowing(Supplier functional) { - } - @Test - public void lambdas() { - takeNonThrowing(() -> "value"); - takeThrowing(() -> "value"); - takeThrowing(() -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return "value"; - }); - Throwable throwable = new IOException(); - takeThrowing(() -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return "value"; - }); - } + void takeThrowing(ThrowingSupplier functional) { + } + void takeNonThrowing(Supplier functional) { + } + @Test + public void lambdas() { + takeNonThrowing(() -> "value"); + takeThrowing(() -> "value"); + takeThrowing(() -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return "value"; + }); + Throwable throwable = new IOException(); + takeThrowing(() -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return "value"; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingToDoubleBiFunctionTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingToDoubleBiFunctionTest.java index 085b436..981ff09 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingToDoubleBiFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingToDoubleBiFunctionTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingToDoubleBiFunctionTest { - void takeThrowing(ThrowingToDoubleBiFunction functional) { - } - void takeNonThrowing(ToDoubleBiFunction functional) { - } - @Test - public void lambdas() { - takeNonThrowing((t, u) -> 2.0); - takeThrowing((t, u) -> 2.0); - takeThrowing((t, u) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2.0; - }); - Throwable throwable = new IOException(); - takeThrowing((t, u) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2.0; - }); - } + void takeThrowing(ThrowingToDoubleBiFunction functional) { + } + void takeNonThrowing(ToDoubleBiFunction functional) { + } + @Test + public void lambdas() { + takeNonThrowing((t, u) -> 2.0); + takeThrowing((t, u) -> 2.0); + takeThrowing((t, u) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2.0; + }); + Throwable throwable = new IOException(); + takeThrowing((t, u) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2.0; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingToDoubleFunctionTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingToDoubleFunctionTest.java index 95387e4..1937d44 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingToDoubleFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingToDoubleFunctionTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingToDoubleFunctionTest { - void takeThrowing(ThrowingToDoubleFunction functional) { - } - void takeNonThrowing(ToDoubleFunction functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> 2.0); - takeThrowing(v -> 2.0); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2.0; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2.0; - }); - } + void takeThrowing(ThrowingToDoubleFunction functional) { + } + void takeNonThrowing(ToDoubleFunction functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> 2.0); + takeThrowing(v -> 2.0); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2.0; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2.0; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingToIntBiFunctionTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingToIntBiFunctionTest.java index 5844797..a1e0297 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingToIntBiFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingToIntBiFunctionTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingToIntBiFunctionTest { - void takeThrowing(ThrowingToIntBiFunction functional) { - } - void takeNonThrowing(ToIntBiFunction functional) { - } - @Test - public void lambdas() { - takeNonThrowing((t, u) -> 2); - takeThrowing((t, u) -> 2); - takeThrowing((t, u) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2; - }); - Throwable throwable = new IOException(); - takeThrowing((t, u) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2; - }); - } + void takeThrowing(ThrowingToIntBiFunction functional) { + } + void takeNonThrowing(ToIntBiFunction functional) { + } + @Test + public void lambdas() { + takeNonThrowing((t, u) -> 2); + takeThrowing((t, u) -> 2); + takeThrowing((t, u) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2; + }); + Throwable throwable = new IOException(); + takeThrowing((t, u) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingToIntFunctionTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingToIntFunctionTest.java index f5b3261..cf33116 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingToIntFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingToIntFunctionTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingToIntFunctionTest { - void takeThrowing(ThrowingToIntFunction functional) { - } - void takeNonThrowing(ToIntFunction functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> 2); - takeThrowing(v -> 2); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2; - }); - } + void takeThrowing(ThrowingToIntFunction functional) { + } + void takeNonThrowing(ToIntFunction functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> 2); + takeThrowing(v -> 2); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingToLongBiFunctionTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingToLongBiFunctionTest.java index d6bcda1..63705a6 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingToLongBiFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingToLongBiFunctionTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingToLongBiFunctionTest { - void takeThrowing(ThrowingToLongBiFunction functional) { - } - void takeNonThrowing(ToLongBiFunction functional) { - } - @Test - public void lambdas() { - takeNonThrowing((t, u) -> 2L); - takeThrowing((t, u) -> 2L); - takeThrowing((t, u) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2L; - }); - Throwable throwable = new IOException(); - takeThrowing((t, u) -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2L; - }); - } + void takeThrowing(ThrowingToLongBiFunction functional) { + } + void takeNonThrowing(ToLongBiFunction functional) { + } + @Test + public void lambdas() { + takeNonThrowing((t, u) -> 2L); + takeThrowing((t, u) -> 2L); + takeThrowing((t, u) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2L; + }); + Throwable throwable = new IOException(); + takeThrowing((t, u) -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2L; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingToLongFunctionTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingToLongFunctionTest.java index ec68dd9..59da1c7 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingToLongFunctionTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingToLongFunctionTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingToLongFunctionTest { - void takeThrowing(ThrowingToLongFunction functional) { - } - void takeNonThrowing(ToLongFunction functional) { - } - @Test - public void lambdas() { - takeNonThrowing(v -> 2L); - takeThrowing(v -> 2L); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return 2L; - }); - Throwable throwable = new IOException(); - takeThrowing(v -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return 2L; - }); - } + void takeThrowing(ThrowingToLongFunction functional) { + } + void takeNonThrowing(ToLongFunction functional) { + } + @Test + public void lambdas() { + takeNonThrowing(v -> 2L); + takeThrowing(v -> 2L); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return 2L; + }); + Throwable throwable = new IOException(); + takeThrowing(v -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return 2L; + }); + } } diff --git a/src/test/java/com/machinezoo/noexception/throwing/ThrowingUnaryOperatorTest.java b/src/test/java/com/machinezoo/noexception/throwing/ThrowingUnaryOperatorTest.java index 8daa9b5..4cbfdec 100644 --- a/src/test/java/com/machinezoo/noexception/throwing/ThrowingUnaryOperatorTest.java +++ b/src/test/java/com/machinezoo/noexception/throwing/ThrowingUnaryOperatorTest.java @@ -8,26 +8,26 @@ import org.junit.jupiter.api.*; public class ThrowingUnaryOperatorTest { - void takeThrowing(ThrowingUnaryOperator functional) { - } - void takeNonThrowing(UnaryOperator functional) { - } - @Test - public void lambdas() { - takeNonThrowing(o -> "value"); - takeThrowing(o -> "value"); - takeThrowing(o -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw new IOException(); - else - return "value"; - }); - Throwable throwable = new IOException(); - takeThrowing(o -> { - if (ThreadLocalRandom.current().nextBoolean()) - throw throwable; - else - return "value"; - }); - } + void takeThrowing(ThrowingUnaryOperator functional) { + } + void takeNonThrowing(UnaryOperator functional) { + } + @Test + public void lambdas() { + takeNonThrowing(o -> "value"); + takeThrowing(o -> "value"); + takeThrowing(o -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw new IOException(); + else + return "value"; + }); + Throwable throwable = new IOException(); + takeThrowing(o -> { + if (ThreadLocalRandom.current().nextBoolean()) + throw throwable; + else + return "value"; + }); + } }