Checked exceptions are one of Java's biggest flaws. Due to backwards-compatibility, we're inheriting all the checked exception trouble back from JDK 1.0. This becomes even more obvious when using lambda expressions, most of which are not allowed to throw checked exceptions.
This library tries to ease some pain and wraps / unwraps a variety of API elements from the JDK 8 to improve interoperability with checked exceptions.
- Author:
- Lukas Eder
-
Field Summary
Modifier and TypeFieldDescriptionAConsumer
that rethrows all exceptions, including checked exceptions. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T,
U> BiConsumer<T, U> biConsumer
(CheckedBiConsumer<T, U> consumer) Wrap aCheckedBiConsumer
in aBiConsumer
.static <T,
U> BiConsumer<T, U> biConsumer
(CheckedBiConsumer<T, U> consumer, Consumer<Throwable> handler) Wrap aCheckedBiConsumer
in aBiConsumer
with a custom handler for checked exceptions.static <T,
U, R> BiFunction<T, U, R> biFunction
(CheckedBiFunction<T, U, R> function) Wrap aCheckedBiFunction
in aBiFunction
.static <T,
U, R> BiFunction<T, U, R> biFunction
(CheckedBiFunction<T, U, R> function, Consumer<Throwable> handler) Wrap aCheckedBiFunction
in aBiFunction
with a custom handler for checked exceptions.static <T> BinaryOperator<T>
binaryOperator
(CheckedBinaryOperator<T> operator) Wrap aCheckedBinaryOperator
in aBinaryOperator
.static <T> BinaryOperator<T>
binaryOperator
(CheckedBinaryOperator<T> operator, Consumer<Throwable> handler) Wrap aCheckedBinaryOperator
in aBinaryOperator
with a custom handler for checked exceptions.static <T,
U> BiPredicate<T, U> biPredicate
(CheckedBiPredicate<T, U> predicate) Wrap aCheckedBiPredicate
in aBiPredicate
.static <T,
U> BiPredicate<T, U> biPredicate
(CheckedBiPredicate<T, U> predicate, Consumer<Throwable> handler) Wrap aCheckedBiPredicate
in aBiPredicate
with a custom handler for checked exceptions.static BooleanSupplier
booleanSupplier
(CheckedBooleanSupplier supplier) Wrap aCheckedBooleanSupplier
in aBooleanSupplier
.static BooleanSupplier
booleanSupplier
(CheckedBooleanSupplier supplier, Consumer<Throwable> handler) Wrap aCheckedBooleanSupplier
in aBooleanSupplier
with a custom handler for checked exceptions.static <T> Callable<T>
callable
(CheckedCallable<T> callable) Wrap aCheckedCallable<T>
in aCallable<T>
.static <T> Callable<T>
callable
(CheckedCallable<T> callable, Consumer<Throwable> handler) Wrap aCheckedCallable<T>
in aCallable<T>
with a custom handler for checked exceptions.static <T> Comparator<T>
comparator
(CheckedComparator<T> comparator) Wrap aCheckedComparator
in aComparator
.static <T> Comparator<T>
comparator
(CheckedComparator<T> comparator, Consumer<Throwable> handler) Wrap aCheckedComparator
in aComparator
with a custom handler for checked exceptions.static <T> Consumer<T>
consumer
(CheckedConsumer<T> consumer) Wrap aCheckedConsumer
in aConsumer
.static <T> Consumer<T>
consumer
(CheckedConsumer<T> consumer, Consumer<Throwable> handler) Wrap aCheckedConsumer
in aConsumer
with a custom handler for checked exceptions.static DoubleBinaryOperator
Wrap aCheckedDoubleBinaryOperator
in aDoubleBinaryOperator
.static DoubleBinaryOperator
doubleBinaryOperator
(CheckedDoubleBinaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedDoubleBinaryOperator
in aDoubleBinaryOperator
with a custom handler for checked exceptions.static DoubleConsumer
doubleConsumer
(CheckedDoubleConsumer consumer) Wrap aCheckedDoubleConsumer
in aDoubleConsumer
.static DoubleConsumer
doubleConsumer
(CheckedDoubleConsumer consumer, Consumer<Throwable> handler) Wrap aCheckedDoubleConsumer
in aDoubleConsumer
with a custom handler for checked exceptions.static <R> DoubleFunction<R>
doubleFunction
(CheckedDoubleFunction<R> function) Wrap aCheckedDoubleFunction
in aDoubleFunction
.static <R> DoubleFunction<R>
doubleFunction
(CheckedDoubleFunction<R> function, Consumer<Throwable> handler) Wrap aCheckedDoubleFunction
in aDoubleFunction
with a custom handler for checked exceptions.static DoublePredicate
doublePredicate
(CheckedDoublePredicate predicate) Wrap aCheckedDoublePredicate
in aDoublePredicate
.static DoublePredicate
doublePredicate
(CheckedDoublePredicate function, Consumer<Throwable> handler) Wrap aCheckedDoublePredicate
in aDoublePredicate
with a custom handler for checked exceptions.static DoubleSupplier
doubleSupplier
(CheckedDoubleSupplier supplier) Wrap aCheckedDoubleSupplier
in aDoubleSupplier
.static DoubleSupplier
doubleSupplier
(CheckedDoubleSupplier supplier, Consumer<Throwable> handler) Wrap aCheckedDoubleSupplier
in aDoubleSupplier
with a custom handler for checked exceptions.static DoubleToIntFunction
Wrap aCheckedDoubleToIntFunction
in aDoubleToIntFunction
.static DoubleToIntFunction
doubleToIntFunction
(CheckedDoubleToIntFunction function, Consumer<Throwable> handler) Wrap aCheckedDoubleToIntFunction
in aDoubleToIntFunction
with a custom handler for checked exceptions.static DoubleToLongFunction
Wrap aCheckedDoubleToLongFunction
in aDoubleToLongFunction
.static DoubleToLongFunction
doubleToLongFunction
(CheckedDoubleToLongFunction function, Consumer<Throwable> handler) Wrap aCheckedDoubleToLongFunction
in aDoubleToLongFunction
with a custom handler for checked exceptions.static DoubleUnaryOperator
Wrap aCheckedDoubleUnaryOperator
in aDoubleUnaryOperator
.static DoubleUnaryOperator
doubleUnaryOperator
(CheckedDoubleUnaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedDoubleUnaryOperator
in aDoubleUnaryOperator
with a custom handler for checked exceptions.static <T,
R> Function<T, R> function
(CheckedFunction<T, R> function) Wrap aCheckedFunction
in aFunction
.static <T,
R> Function<T, R> function
(CheckedFunction<T, R> function, Consumer<Throwable> handler) Wrap aCheckedFunction
in aFunction
with a custom handler for checked exceptions.static IntBinaryOperator
intBinaryOperator
(CheckedIntBinaryOperator operator) Wrap aCheckedIntBinaryOperator
in aIntBinaryOperator
.static IntBinaryOperator
intBinaryOperator
(CheckedIntBinaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedIntBinaryOperator
in aIntBinaryOperator
with a custom handler for checked exceptions.static IntConsumer
intConsumer
(CheckedIntConsumer consumer) Wrap aCheckedIntConsumer
in aIntConsumer
.static IntConsumer
intConsumer
(CheckedIntConsumer consumer, Consumer<Throwable> handler) Wrap aCheckedIntConsumer
in aIntConsumer
with a custom handler for checked exceptions.static <R> IntFunction<R>
intFunction
(CheckedIntFunction<R> function) Wrap aCheckedIntFunction
in aIntFunction
.static <R> IntFunction<R>
intFunction
(CheckedIntFunction<R> function, Consumer<Throwable> handler) Wrap aCheckedIntFunction
in aIntFunction
with a custom handler for checked exceptions.static IntPredicate
intPredicate
(CheckedIntPredicate predicate) Wrap aCheckedPredicate
in aIntPredicate
.static IntPredicate
intPredicate
(CheckedIntPredicate function, Consumer<Throwable> handler) Wrap aCheckedPredicate
in aIntPredicate
with a custom handler for checked exceptions.static IntSupplier
intSupplier
(CheckedIntSupplier supplier) Wrap aCheckedIntSupplier
in aIntSupplier
.static IntSupplier
intSupplier
(CheckedIntSupplier supplier, Consumer<Throwable> handler) Wrap aCheckedIntSupplier
in aIntSupplier
with a custom handler for checked exceptions.static IntToDoubleFunction
Wrap aCheckedIntToDoubleFunction
in aIntToDoubleFunction
.static IntToDoubleFunction
intToDoubleFunction
(CheckedIntToDoubleFunction function, Consumer<Throwable> handler) Wrap aCheckedIntToDoubleFunction
in aIntToDoubleFunction
with a custom handler for checked exceptions.static IntToLongFunction
intToLongFunction
(CheckedIntToLongFunction function) Wrap aCheckedIntToLongFunction
in aIntToLongFunction
.static IntToLongFunction
intToLongFunction
(CheckedIntToLongFunction function, Consumer<Throwable> handler) Wrap aCheckedIntToLongFunction
in aIntToLongFunction
with a custom handler for checked exceptions.static IntUnaryOperator
intUnaryOperator
(CheckedIntUnaryOperator operator) Wrap aCheckedIntUnaryOperator
in aIntUnaryOperator
.static IntUnaryOperator
intUnaryOperator
(CheckedIntUnaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedIntUnaryOperator
in aIntUnaryOperator
with a custom handler for checked exceptions.static LongBinaryOperator
longBinaryOperator
(CheckedLongBinaryOperator operator) Wrap aCheckedLongBinaryOperator
in aLongBinaryOperator
.static LongBinaryOperator
longBinaryOperator
(CheckedLongBinaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedLongBinaryOperator
in aLongBinaryOperator
with a custom handler for checked exceptions.static LongConsumer
longConsumer
(CheckedLongConsumer consumer) Wrap aCheckedLongConsumer
in aLongConsumer
.static LongConsumer
longConsumer
(CheckedLongConsumer consumer, Consumer<Throwable> handler) Wrap aCheckedLongConsumer
in aLongConsumer
with a custom handler for checked exceptions.static <R> LongFunction<R>
longFunction
(CheckedLongFunction<R> function) Wrap aCheckedLongFunction
in aLongFunction
.static <R> LongFunction<R>
longFunction
(CheckedLongFunction<R> function, Consumer<Throwable> handler) Wrap aCheckedLongFunction
in aLongFunction
with a custom handler for checked exceptions.static LongPredicate
longPredicate
(CheckedLongPredicate predicate) Wrap aCheckedLongPredicate
in aLongPredicate
.static LongPredicate
longPredicate
(CheckedLongPredicate function, Consumer<Throwable> handler) Wrap aCheckedLongPredicate
in aLongPredicate
with a custom handler for checked exceptions.static LongSupplier
longSupplier
(CheckedLongSupplier supplier) Wrap aCheckedLongSupplier
in aLongSupplier
.static LongSupplier
longSupplier
(CheckedLongSupplier supplier, Consumer<Throwable> handler) Wrap aCheckedLongSupplier
in aLongSupplier
with a custom handler for checked exceptions.static LongToDoubleFunction
Wrap aCheckedLongToDoubleFunction
in aLongToDoubleFunction
.static LongToDoubleFunction
longToDoubleFunction
(CheckedLongToDoubleFunction function, Consumer<Throwable> handler) Wrap aCheckedLongToDoubleFunction
in aLongToDoubleFunction
with a custom handler for checked exceptions.static LongToIntFunction
longToIntFunction
(CheckedLongToIntFunction function) Wrap aCheckedLongToIntFunction
in aLongToIntFunction
.static LongToIntFunction
longToIntFunction
(CheckedLongToIntFunction function, Consumer<Throwable> handler) Wrap aCheckedLongToIntFunction
in aLongToIntFunction
with a custom handler for checked exceptions.static LongUnaryOperator
longUnaryOperator
(CheckedLongUnaryOperator operator) Wrap aCheckedLongUnaryOperator
in aLongUnaryOperator
.static LongUnaryOperator
longUnaryOperator
(CheckedLongUnaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedLongUnaryOperator
in aLongUnaryOperator
with a custom handler for checked exceptions.static <T> ObjDoubleConsumer<T>
objDoubleConsumer
(CheckedObjDoubleConsumer<T> consumer) Wrap aCheckedObjDoubleConsumer
in aObjDoubleConsumer
.static <T> ObjDoubleConsumer<T>
objDoubleConsumer
(CheckedObjDoubleConsumer<T> consumer, Consumer<Throwable> handler) Wrap aCheckedObjDoubleConsumer
in aObjDoubleConsumer
with a custom handler for checked exceptions.static <T> ObjIntConsumer<T>
objIntConsumer
(CheckedObjIntConsumer<T> consumer) Wrap aCheckedObjIntConsumer
in aObjIntConsumer
.static <T> ObjIntConsumer<T>
objIntConsumer
(CheckedObjIntConsumer<T> consumer, Consumer<Throwable> handler) Wrap aCheckedObjIntConsumer
in aObjIntConsumer
with a custom handler for checked exceptions.static <T> ObjLongConsumer<T>
objLongConsumer
(CheckedObjLongConsumer<T> consumer) Wrap aCheckedObjLongConsumer
in aObjLongConsumer
.static <T> ObjLongConsumer<T>
objLongConsumer
(CheckedObjLongConsumer<T> consumer, Consumer<Throwable> handler) Wrap aCheckedObjLongConsumer
in aObjLongConsumer
with a custom handler for checked exceptions.static <T> Predicate<T>
predicate
(CheckedPredicate<T> predicate) Wrap aCheckedPredicate
in aPredicate
.static <T> Predicate<T>
predicate
(CheckedPredicate<T> function, Consumer<Throwable> handler) Wrap aCheckedPredicate
in aPredicate
with a custom handler for checked exceptions.static Runnable
runnable
(CheckedRunnable runnable) Wrap aCheckedRunnable
in aRunnable
.static Runnable
runnable
(CheckedRunnable runnable, Consumer<Throwable> handler) Wrap aCheckedRunnable
in aRunnable
with a custom handler for checked exceptions.static <T> Supplier<T>
supplier
(CheckedSupplier<T> supplier) Wrap aCheckedSupplier
in aSupplier
.static <T> Supplier<T>
supplier
(CheckedSupplier<T> supplier, Consumer<Throwable> handler) Wrap aCheckedSupplier
in aSupplier
with a custom handler for checked exceptions.static void
"sneaky-throw" a checked exception or throwable.static <T,
U> ToDoubleBiFunction<T, U> toDoubleBiFunction
(CheckedToDoubleBiFunction<T, U> function) Wrap aCheckedToDoubleBiFunction
in aToDoubleBiFunction
.static <T,
U> ToDoubleBiFunction<T, U> toDoubleBiFunction
(CheckedToDoubleBiFunction<T, U> function, Consumer<Throwable> handler) Wrap aCheckedToDoubleBiFunction
in aToDoubleBiFunction
with a custom handler for checked exceptions.static <T> ToDoubleFunction<T>
toDoubleFunction
(CheckedToDoubleFunction<T> function) Wrap aCheckedToDoubleFunction
in aToDoubleFunction
.static <T> ToDoubleFunction<T>
toDoubleFunction
(CheckedToDoubleFunction<T> function, Consumer<Throwable> handler) Wrap aCheckedToDoubleFunction
in aToDoubleFunction
with a custom handler for checked exceptions.static <T,
U> ToIntBiFunction<T, U> toIntBiFunction
(CheckedToIntBiFunction<T, U> function) Wrap aCheckedToIntBiFunction
in aToIntBiFunction
.static <T,
U> ToIntBiFunction<T, U> toIntBiFunction
(CheckedToIntBiFunction<T, U> function, Consumer<Throwable> handler) Wrap aCheckedToIntBiFunction
in aToIntBiFunction
with a custom handler for checked exceptions.static <T> ToIntFunction<T>
toIntFunction
(CheckedToIntFunction<T> function) Wrap aCheckedToIntFunction
in aToIntFunction
.static <T> ToIntFunction<T>
toIntFunction
(CheckedToIntFunction<T> function, Consumer<Throwable> handler) Wrap aCheckedToIntFunction
in aToIntFunction
with a custom handler for checked exceptions.static <T,
U> ToLongBiFunction<T, U> toLongBiFunction
(CheckedToLongBiFunction<T, U> function) Wrap aCheckedToLongBiFunction
in aToLongBiFunction
.static <T,
U> ToLongBiFunction<T, U> toLongBiFunction
(CheckedToLongBiFunction<T, U> function, Consumer<Throwable> handler) Wrap aCheckedToLongBiFunction
in aToLongBiFunction
with a custom handler for checked exceptions.static <T> ToLongFunction<T>
toLongFunction
(CheckedToLongFunction<T> function) Wrap aCheckedToLongFunction
in aToLongFunction
.static <T> ToLongFunction<T>
toLongFunction
(CheckedToLongFunction<T> function, Consumer<Throwable> handler) Wrap aCheckedToLongFunction
in aToLongFunction
with a custom handler for checked exceptions.static <T> UnaryOperator<T>
unaryOperator
(CheckedUnaryOperator<T> operator) Wrap aCheckedUnaryOperator
in aUnaryOperator
.static <T> UnaryOperator<T>
unaryOperator
(CheckedUnaryOperator<T> operator, Consumer<Throwable> handler) Wrap aCheckedUnaryOperator
in aUnaryOperator
with a custom handler for checked exceptions.
-
Field Details
-
THROWABLE_TO_RUNTIME_EXCEPTION
-
RETHROW_ALL
AConsumer
that rethrows all exceptions, including checked exceptions.
-
-
Method Details
-
throwChecked
"sneaky-throw" a checked exception or throwable. -
runnable
Wrap aCheckedRunnable
in aRunnable
.Example:
new Thread(Unchecked.runnable(() -> { throw new Exception("Cannot run this thread"); })).start();
-
runnable
Wrap aCheckedRunnable
in aRunnable
with a custom handler for checked exceptions.Example:
new Thread(Unchecked.runnable( () -> { throw new Exception("Cannot run this thread"); }, e -> { throw new IllegalStateException(e); } )).start();
-
callable
Wrap aCheckedCallable<T>
in aCallable<T>
.Example:
Executors.newFixedThreadPool(1).submit(Unchecked.callable(() -> { throw new Exception("Cannot execute this task"); })).get();
-
callable
Wrap aCheckedCallable<T>
in aCallable<T>
with a custom handler for checked exceptions.Example:
Executors.newFixedThreadPool(1).submit(Unchecked.callable( () -> { throw new Exception("Cannot execute this task"); }, e -> { throw new IllegalStateException(e); } )).get();
-
comparator
Wrap aCheckedComparator
in aComparator
. -
comparator
public static <T> Comparator<T> comparator(CheckedComparator<T> comparator, Consumer<Throwable> handler) Wrap aCheckedComparator
in aComparator
with a custom handler for checked exceptions. -
biConsumer
Wrap aCheckedBiConsumer
in aBiConsumer
.Example:
map.forEach(Unchecked.biConsumer((k, v) -> { if (k == null || v == null) throw new Exception("No nulls allowed in map"); }));
-
biConsumer
public static <T,U> BiConsumer<T,U> biConsumer(CheckedBiConsumer<T, U> consumer, Consumer<Throwable> handler) Wrap aCheckedBiConsumer
in aBiConsumer
with a custom handler for checked exceptions.Example:
map.forEach(Unchecked.biConsumer( (k, v) -> { if (k == null || v == null) throw new Exception("No nulls allowed in map"); }, e -> { throw new IllegalStateException(e); } ));
-
objIntConsumer
Wrap aCheckedObjIntConsumer
in aObjIntConsumer
. -
objIntConsumer
public static <T> ObjIntConsumer<T> objIntConsumer(CheckedObjIntConsumer<T> consumer, Consumer<Throwable> handler) Wrap aCheckedObjIntConsumer
in aObjIntConsumer
with a custom handler for checked exceptions. -
objLongConsumer
Wrap aCheckedObjLongConsumer
in aObjLongConsumer
. -
objLongConsumer
public static <T> ObjLongConsumer<T> objLongConsumer(CheckedObjLongConsumer<T> consumer, Consumer<Throwable> handler) Wrap aCheckedObjLongConsumer
in aObjLongConsumer
with a custom handler for checked exceptions. -
objDoubleConsumer
Wrap aCheckedObjDoubleConsumer
in aObjDoubleConsumer
. -
objDoubleConsumer
public static <T> ObjDoubleConsumer<T> objDoubleConsumer(CheckedObjDoubleConsumer<T> consumer, Consumer<Throwable> handler) Wrap aCheckedObjDoubleConsumer
in aObjDoubleConsumer
with a custom handler for checked exceptions. -
biFunction
Wrap aCheckedBiFunction
in aBiFunction
.Example:
map.computeIfPresent("key", Unchecked.biFunction((k, v) -> { if (k == null || v == null) throw new Exception("No nulls allowed in map"); return 42; }));
-
biFunction
public static <T,U, BiFunction<T,R> U, biFunctionR> (CheckedBiFunction<T, U, R> function, Consumer<Throwable> handler) Wrap aCheckedBiFunction
in aBiFunction
with a custom handler for checked exceptions.Example:
map.computeIfPresent("key", Unchecked.biFunction( (k, v) -> { if (k == null || v == null) throw new Exception("No nulls allowed in map"); return 42; }, e -> { throw new IllegalStateException(e); } ));
-
toIntBiFunction
Wrap aCheckedToIntBiFunction
in aToIntBiFunction
. -
toIntBiFunction
public static <T,U> ToIntBiFunction<T,U> toIntBiFunction(CheckedToIntBiFunction<T, U> function, Consumer<Throwable> handler) Wrap aCheckedToIntBiFunction
in aToIntBiFunction
with a custom handler for checked exceptions. -
toLongBiFunction
Wrap aCheckedToLongBiFunction
in aToLongBiFunction
. -
toLongBiFunction
public static <T,U> ToLongBiFunction<T,U> toLongBiFunction(CheckedToLongBiFunction<T, U> function, Consumer<Throwable> handler) Wrap aCheckedToLongBiFunction
in aToLongBiFunction
with a custom handler for checked exceptions. -
toDoubleBiFunction
public static <T,U> ToDoubleBiFunction<T,U> toDoubleBiFunction(CheckedToDoubleBiFunction<T, U> function) Wrap aCheckedToDoubleBiFunction
in aToDoubleBiFunction
. -
toDoubleBiFunction
public static <T,U> ToDoubleBiFunction<T,U> toDoubleBiFunction(CheckedToDoubleBiFunction<T, U> function, Consumer<Throwable> handler) Wrap aCheckedToDoubleBiFunction
in aToDoubleBiFunction
with a custom handler for checked exceptions. -
biPredicate
Wrap aCheckedBiPredicate
in aBiPredicate
. -
biPredicate
public static <T,U> BiPredicate<T,U> biPredicate(CheckedBiPredicate<T, U> predicate, Consumer<Throwable> handler) Wrap aCheckedBiPredicate
in aBiPredicate
with a custom handler for checked exceptions. -
binaryOperator
Wrap aCheckedBinaryOperator
in aBinaryOperator
.Example:
Stream.of("a", "b", "c").reduce(Unchecked.binaryOperator((s1, s2) -> { if (s2.length() > 10) throw new Exception("Only short strings allowed"); return s1 + s2; }));
-
binaryOperator
public static <T> BinaryOperator<T> binaryOperator(CheckedBinaryOperator<T> operator, Consumer<Throwable> handler) Wrap aCheckedBinaryOperator
in aBinaryOperator
with a custom handler for checked exceptions.Example:
Stream.of("a", "b", "c").reduce(Unchecked.binaryOperator( (s1, s2) -> { if (s2.length() > 10) throw new Exception("Only short strings allowed"); return s1 + s2; }, e -> { throw new IllegalStateException(e); } ));
-
intBinaryOperator
Wrap aCheckedIntBinaryOperator
in aIntBinaryOperator
.Example:
IntStream.of(1, 2, 3).reduce(Unchecked.intBinaryOperator((i1, i2) -> { if (i2 < 0) throw new Exception("Only positive numbers allowed"); return i1 + i2; }));
-
intBinaryOperator
public static IntBinaryOperator intBinaryOperator(CheckedIntBinaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedIntBinaryOperator
in aIntBinaryOperator
with a custom handler for checked exceptions.Example:
IntStream.of(1, 2, 3).reduce(Unchecked.intBinaryOperator( (i1, i2) -> { if (i2 < 0) throw new Exception("Only positive numbers allowed"); return i1 + i2; }, e -> { throw new IllegalStateException(e); } ));
-
longBinaryOperator
Wrap aCheckedLongBinaryOperator
in aLongBinaryOperator
.Example:
LongStream.of(1L, 2L, 3L).reduce(Unchecked.longBinaryOperator((l1, l2) -> { if (l2 < 0L) throw new Exception("Only positive numbers allowed"); return l1 + l2; }));
-
longBinaryOperator
public static LongBinaryOperator longBinaryOperator(CheckedLongBinaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedLongBinaryOperator
in aLongBinaryOperator
with a custom handler for checked exceptions.Example:
LongStream.of(1L, 2L, 3L).reduce(Unchecked.longBinaryOperator( (l1, l2) -> { if (l2 < 0L) throw new Exception("Only positive numbers allowed"); return l1 + l2; }, e -> { throw new IllegalStateException(e); } ));
-
doubleBinaryOperator
Wrap aCheckedDoubleBinaryOperator
in aDoubleBinaryOperator
.Example:
DoubleStream.of(1.0, 2.0, 3.0).reduce(Unchecked.doubleBinaryOperator((d1, d2) -> { if (d2 < 0.0) throw new Exception("Only positive numbers allowed"); return d1 + d2; }));
-
doubleBinaryOperator
public static DoubleBinaryOperator doubleBinaryOperator(CheckedDoubleBinaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedDoubleBinaryOperator
in aDoubleBinaryOperator
with a custom handler for checked exceptions.Example:
DoubleStream.of(1.0, 2.0, 3.0).reduce(Unchecked.doubleBinaryOperator( (d1, d2) -> { if (d2 < 0.0) throw new Exception("Only positive numbers allowed"); return d1 + d2; }, e -> { throw new IllegalStateException(e); } ));
-
consumer
Wrap aCheckedConsumer
in aConsumer
.Example:
Arrays.asList("a", "b").stream().forEach(Unchecked.consumer(s -> { if (s.length() > 10) throw new Exception("Only short strings allowed"); }));
-
consumer
Wrap aCheckedConsumer
in aConsumer
with a custom handler for checked exceptions.Example:
Arrays.asList("a", "b").stream().forEach(Unchecked.consumer( s -> { if (s.length() > 10) throw new Exception("Only short strings allowed"); }, e -> { throw new IllegalStateException(e); } ));
-
intConsumer
Wrap aCheckedIntConsumer
in aIntConsumer
.Example:
Arrays.stream(new int[] { 1, 2 }).forEach(Unchecked.intConsumer(i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); }));
-
intConsumer
Wrap aCheckedIntConsumer
in aIntConsumer
with a custom handler for checked exceptions.Example:
Arrays.stream(new int[] { 1, 2 }).forEach(Unchecked.intConsumer( i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); }, e -> { throw new IllegalStateException(e); } ));
-
longConsumer
Wrap aCheckedLongConsumer
in aLongConsumer
.Example:
Arrays.stream(new long[] { 1L, 2L }).forEach(Unchecked.longConsumer(l -> { if (l < 0) throw new Exception("Only positive numbers allowed"); }));
-
longConsumer
Wrap aCheckedLongConsumer
in aLongConsumer
with a custom handler for checked exceptions.Example:
Arrays.stream(new long[] { 1L, 2L }).forEach(Unchecked.longConsumer( l -> { if (l < 0) throw new Exception("Only positive numbers allowed"); }, e -> { throw new IllegalStateException(e); } ));
-
doubleConsumer
Wrap aCheckedDoubleConsumer
in aDoubleConsumer
.Example:
Arrays.stream(new double[] { 1.0, 2.0 }).forEach(Unchecked.doubleConsumer(d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); }));
-
doubleConsumer
public static DoubleConsumer doubleConsumer(CheckedDoubleConsumer consumer, Consumer<Throwable> handler) Wrap aCheckedDoubleConsumer
in aDoubleConsumer
with a custom handler for checked exceptions.Example:
Arrays.stream(new double[] { 1.0, 2.0 }).forEach(Unchecked.doubleConsumer( d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); }, e -> { throw new IllegalStateException(e); } ));
-
function
Wrap aCheckedFunction
in aFunction
.Example:
map.computeIfAbsent("key", Unchecked.function(k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42; }));
-
function
public static <T,R> Function<T,R> function(CheckedFunction<T, R> function, Consumer<Throwable> handler) Wrap aCheckedFunction
in aFunction
with a custom handler for checked exceptions.Example:
map.forEach(Unchecked.function( k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42; }, e -> { throw new IllegalStateException(e); } ));
-
toIntFunction
Wrap aCheckedToIntFunction
in aToIntFunction
.Example:
map.computeIfAbsent("key", Unchecked.toIntFunction(k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42; }));
-
toIntFunction
public static <T> ToIntFunction<T> toIntFunction(CheckedToIntFunction<T> function, Consumer<Throwable> handler) Wrap aCheckedToIntFunction
in aToIntFunction
with a custom handler for checked exceptions.Example:
map.forEach(Unchecked.toIntFunction( k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42; }, e -> { throw new IllegalStateException(e); } ));
-
toLongFunction
Wrap aCheckedToLongFunction
in aToLongFunction
.Example:
map.computeIfAbsent("key", Unchecked.toLongFunction(k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42L; }));
-
toLongFunction
public static <T> ToLongFunction<T> toLongFunction(CheckedToLongFunction<T> function, Consumer<Throwable> handler) Wrap aCheckedToLongFunction
in aToLongFunction
with a custom handler for checked exceptions.Example:
map.forEach(Unchecked.toLongFunction( k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42L; }, e -> { throw new IllegalStateException(e); } ));
-
toDoubleFunction
Wrap aCheckedToDoubleFunction
in aToDoubleFunction
.Example:
map.computeIfAbsent("key", Unchecked.toDoubleFunction(k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42.0; }));
-
toDoubleFunction
public static <T> ToDoubleFunction<T> toDoubleFunction(CheckedToDoubleFunction<T> function, Consumer<Throwable> handler) Wrap aCheckedToDoubleFunction
in aToDoubleFunction
with a custom handler for checked exceptions.Example:
map.forEach(Unchecked.toDoubleFunction( k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42.0; }, e -> { throw new IllegalStateException(e); } ));
-
intFunction
Wrap aCheckedIntFunction
in aIntFunction
.Example:
IntStream.of(1, 2, 3).mapToObj(Unchecked.intFunction(i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return "" + i; });
-
intFunction
public static <R> IntFunction<R> intFunction(CheckedIntFunction<R> function, Consumer<Throwable> handler) Wrap aCheckedIntFunction
in aIntFunction
with a custom handler for checked exceptions.Example:
IntStream.of(1, 2, 3).mapToObj(Unchecked.intFunction( i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return "" + i; }, e -> { throw new IllegalStateException(e); } ));
-
intToLongFunction
Wrap aCheckedIntToLongFunction
in aIntToLongFunction
.Example:
IntStream.of(1, 2, 3).mapToLong(Unchecked.intToLongFunction(i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return (long) i; });
-
intToLongFunction
public static IntToLongFunction intToLongFunction(CheckedIntToLongFunction function, Consumer<Throwable> handler) Wrap aCheckedIntToLongFunction
in aIntToLongFunction
with a custom handler for checked exceptions.Example:
IntStream.of(1, 2, 3).mapToLong(Unchecked.intToLongFunction( i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return (long) i; }, e -> { throw new IllegalStateException(e); } ));
-
intToDoubleFunction
Wrap aCheckedIntToDoubleFunction
in aIntToDoubleFunction
.Example:
IntStream.of(1, 2, 3).mapToDouble(Unchecked.intToDoubleFunction(i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return (double) i; });
-
intToDoubleFunction
public static IntToDoubleFunction intToDoubleFunction(CheckedIntToDoubleFunction function, Consumer<Throwable> handler) Wrap aCheckedIntToDoubleFunction
in aIntToDoubleFunction
with a custom handler for checked exceptions.Example:
IntStream.of(1, 2, 3).mapToDouble(Unchecked.intToDoubleFunction( i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return (double) i; }, e -> { throw new IllegalStateException(e); } ));
-
longFunction
Wrap aCheckedLongFunction
in aLongFunction
.Example:
LongStream.of(1L, 2L, 3L).mapToObj(Unchecked.longFunction(l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return "" + l; });
-
longFunction
public static <R> LongFunction<R> longFunction(CheckedLongFunction<R> function, Consumer<Throwable> handler) Wrap aCheckedLongFunction
in aLongFunction
with a custom handler for checked exceptions.Example:
LongStream.of(1L, 2L, 3L).mapToObj(Unchecked.longFunction( l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return "" + l; }, e -> { throw new IllegalStateException(e); } ));
-
longToIntFunction
Wrap aCheckedLongToIntFunction
in aLongToIntFunction
.Example:
LongStream.of(1L, 2L, 3L).mapToInt(Unchecked.longToIntFunction(l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return (int) l; });
-
longToIntFunction
public static LongToIntFunction longToIntFunction(CheckedLongToIntFunction function, Consumer<Throwable> handler) Wrap aCheckedLongToIntFunction
in aLongToIntFunction
with a custom handler for checked exceptions.Example:
LongStream.of(1L, 2L, 3L).mapToInt(Unchecked.longToIntFunction( l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return (int) l; }, e -> { throw new IllegalStateException(e); } ));
-
longToDoubleFunction
Wrap aCheckedLongToDoubleFunction
in aLongToDoubleFunction
.Example:
LongStream.of(1L, 2L, 3L).mapToInt(Unchecked.longToDoubleFunction(l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return (double) l; });
-
longToDoubleFunction
public static LongToDoubleFunction longToDoubleFunction(CheckedLongToDoubleFunction function, Consumer<Throwable> handler) Wrap aCheckedLongToDoubleFunction
in aLongToDoubleFunction
with a custom handler for checked exceptions.Example:
LongStream.of(1L, 2L, 3L).mapToInt(Unchecked.longToDoubleFunction( l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return (double) l; }, e -> { throw new IllegalStateException(e); } ));
-
doubleFunction
Wrap aCheckedDoubleFunction
in aDoubleFunction
.Example:
DoubleStream.of(1.0, 2.0, 3.0).mapToObj(Unchecked.doubleFunction(d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return "" + d; });
-
doubleFunction
public static <R> DoubleFunction<R> doubleFunction(CheckedDoubleFunction<R> function, Consumer<Throwable> handler) Wrap aCheckedDoubleFunction
in aDoubleFunction
with a custom handler for checked exceptions.Example:
DoubleStream.of(1.0, 2.0, 3.0).mapToObj(Unchecked.doubleFunction( d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return "" + d; }, e -> { throw new IllegalStateException(e); } ));
-
doubleToIntFunction
Wrap aCheckedDoubleToIntFunction
in aDoubleToIntFunction
.Example:
DoubleStream.of(1.0, 2.0, 3.0).mapToInt(Unchecked.doubleToIntFunction(d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return (int) d; });
-
doubleToIntFunction
public static DoubleToIntFunction doubleToIntFunction(CheckedDoubleToIntFunction function, Consumer<Throwable> handler) Wrap aCheckedDoubleToIntFunction
in aDoubleToIntFunction
with a custom handler for checked exceptions.Example:
DoubleStream.of(1.0, 2.0, 3.0).mapToInt(Unchecked.doubleToIntFunction( d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return (int) d; }, e -> { throw new IllegalStateException(e); } ));
-
doubleToLongFunction
Wrap aCheckedDoubleToLongFunction
in aDoubleToLongFunction
.Example:
DoubleStream.of(1.0, 2.0, 3.0).mapToLong(Unchecked.doubleToLongFunction(d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return (long) d; });
-
doubleToLongFunction
public static DoubleToLongFunction doubleToLongFunction(CheckedDoubleToLongFunction function, Consumer<Throwable> handler) Wrap aCheckedDoubleToLongFunction
in aDoubleToLongFunction
with a custom handler for checked exceptions.Example:
DoubleStream.of(1.0, 2.0, 3.0).mapToLong(Unchecked.doubleToLongFunction( d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return (long) d; }, e -> { throw new IllegalStateException(e); } ));
-
predicate
Wrap aCheckedPredicate
in aPredicate
.Example:
Stream.of("a", "b", "c").filter(Unchecked.predicate(s -> { if (s.length() > 10) throw new Exception("Only short strings allowed"); return true; }));
-
predicate
Wrap aCheckedPredicate
in aPredicate
with a custom handler for checked exceptions.Example:
Stream.of("a", "b", "c").filter(Unchecked.predicate( s -> { if (s.length() > 10) throw new Exception("Only short strings allowed"); return true; }, e -> { throw new IllegalStateException(e); } ));
-
intPredicate
Wrap aCheckedPredicate
in aIntPredicate
.Example:
IntStream.of(1, 2, 3).filter(Unchecked.intPredicate(i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return true; }));
-
intPredicate
Wrap aCheckedPredicate
in aIntPredicate
with a custom handler for checked exceptions.Example:
IntStream.of(1, 2, 3).filter(Unchecked.intPredicate( i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return true; }, e -> { throw new IllegalStateException(e); } ));
-
longPredicate
Wrap aCheckedLongPredicate
in aLongPredicate
.Example:
LongStream.of(1L, 2L, 3L).filter(Unchecked.longPredicate(l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return true; }));
-
longPredicate
public static LongPredicate longPredicate(CheckedLongPredicate function, Consumer<Throwable> handler) Wrap aCheckedLongPredicate
in aLongPredicate
with a custom handler for checked exceptions.Example:
LongStream.of(1L, 2L, 3L).filter(Unchecked.longPredicate( l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return true; }, e -> { throw new IllegalStateException(e); } ));
-
doublePredicate
Wrap aCheckedDoublePredicate
in aDoublePredicate
.Example:
DoubleStream.of(1.0, 2.0, 3.0).filter(Unchecked.doublePredicate(d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return true; }));
-
doublePredicate
public static DoublePredicate doublePredicate(CheckedDoublePredicate function, Consumer<Throwable> handler) Wrap aCheckedDoublePredicate
in aDoublePredicate
with a custom handler for checked exceptions.Example:
DoubleStream.of(1.0, 2.0, 3.0).filter(Unchecked.doublePredicate( d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return true; }, e -> { throw new IllegalStateException(e); } ));
-
supplier
Wrap aCheckedSupplier
in aSupplier
.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.supplier(() -> rs.getObject(1)));
-
supplier
Wrap aCheckedSupplier
in aSupplier
with a custom handler for checked exceptions.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.supplier( () -> rs.getObject(1), e -> { throw new IllegalStateException(e); } ));
-
intSupplier
Wrap aCheckedIntSupplier
in aIntSupplier
.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.intSupplier(() -> rs.getInt(1)));
-
intSupplier
Wrap aCheckedIntSupplier
in aIntSupplier
with a custom handler for checked exceptions.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.intSupplier( () -> rs.getInt(1), e -> { throw new IllegalStateException(e); } ));
-
longSupplier
Wrap aCheckedLongSupplier
in aLongSupplier
.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.longSupplier(() -> rs.getLong(1)));
-
longSupplier
Wrap aCheckedLongSupplier
in aLongSupplier
with a custom handler for checked exceptions.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.longSupplier( () -> rs.getLong(1), e -> { throw new IllegalStateException(e); } ));
-
doubleSupplier
Wrap aCheckedDoubleSupplier
in aDoubleSupplier
.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.doubleSupplier(() -> rs.getDouble(1)));
-
doubleSupplier
public static DoubleSupplier doubleSupplier(CheckedDoubleSupplier supplier, Consumer<Throwable> handler) Wrap aCheckedDoubleSupplier
in aDoubleSupplier
with a custom handler for checked exceptions.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.doubleSupplier( () -> rs.getDouble(1), e -> { throw new IllegalStateException(e); } ));
-
booleanSupplier
Wrap aCheckedBooleanSupplier
in aBooleanSupplier
.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.booleanSupplier(() -> rs.getBoolean(1)));
-
booleanSupplier
public static BooleanSupplier booleanSupplier(CheckedBooleanSupplier supplier, Consumer<Throwable> handler) Wrap aCheckedBooleanSupplier
in aBooleanSupplier
with a custom handler for checked exceptions.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.booleanSupplier( () -> rs.getBoolean(1), e -> { throw new IllegalStateException(e); } ));
-
unaryOperator
Wrap aCheckedUnaryOperator
in aUnaryOperator
.Example:
Stream.of("a", "b", "c").map(Unchecked.unaryOperator(s -> { if (s.length() > 10) throw new Exception("Only short strings allowed"); return s; }));
-
unaryOperator
public static <T> UnaryOperator<T> unaryOperator(CheckedUnaryOperator<T> operator, Consumer<Throwable> handler) Wrap aCheckedUnaryOperator
in aUnaryOperator
with a custom handler for checked exceptions.Example:
Stream.of("a", "b", "c").map(Unchecked.unaryOperator( s -> { if (s.length() > 10) throw new Exception("Only short strings allowed"); return s; }, e -> { throw new IllegalStateException(e); } ));
-
intUnaryOperator
Wrap aCheckedIntUnaryOperator
in aIntUnaryOperator
.Example:
IntStream.of(1, 2, 3).map(Unchecked.intUnaryOperator(i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return i; }));
-
intUnaryOperator
public static IntUnaryOperator intUnaryOperator(CheckedIntUnaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedIntUnaryOperator
in aIntUnaryOperator
with a custom handler for checked exceptions.Example:
IntStream.of(1, 2, 3).map(Unchecked.intUnaryOperator( i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return i; }, e -> { throw new IllegalStateException(e); } ));
-
longUnaryOperator
Wrap aCheckedLongUnaryOperator
in aLongUnaryOperator
.Example:
LongStream.of(1L, 2L, 3L).map(Unchecked.longUnaryOperator(l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return l; }));
-
longUnaryOperator
public static LongUnaryOperator longUnaryOperator(CheckedLongUnaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedLongUnaryOperator
in aLongUnaryOperator
with a custom handler for checked exceptions.Example:
LongStream.of(1L, 2L, 3L).map(Unchecked.longUnaryOperator( l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return l; }, e -> { throw new IllegalStateException(e); } ));
-
doubleUnaryOperator
Wrap aCheckedDoubleUnaryOperator
in aDoubleUnaryOperator
.Example:
LongStream.of(1.0, 2.0, 3.0).map(Unchecked.doubleUnaryOperator(d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return d; }));
-
doubleUnaryOperator
public static DoubleUnaryOperator doubleUnaryOperator(CheckedDoubleUnaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedDoubleUnaryOperator
in aDoubleUnaryOperator
with a custom handler for checked exceptions.Example:
LongStream.of(1.0, 2.0, 3.0).map(Unchecked.doubleUnaryOperator( d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return d; }, e -> { throw new IllegalStateException(e); } ));
-