java.lang.Object
org.jooq.lambda.Sneaky
Improved interoperability between checked exceptions and Java 8.
Similar to Unchecked
, except that Unchecked.RETHROW_ALL
is
used as the default way to re-throw checked exceptions.
- Author:
- Lukas Eder
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T,
U> BiConsumer<T, U> biConsumer
(CheckedBiConsumer<T, U> consumer) Wrap aCheckedBiConsumer
in aBiConsumer
.static <T,
U, R> BiFunction<T, U, R> biFunction
(CheckedBiFunction<T, U, R> function) Wrap aCheckedBiFunction
in aBiFunction
.static <T> BinaryOperator<T>
binaryOperator
(CheckedBinaryOperator<T> operator) Wrap aCheckedBinaryOperator
in aBinaryOperator
.static <T,
U> BiPredicate<T, U> biPredicate
(CheckedBiPredicate<T, U> predicate) Wrap aCheckedBiPredicate
in aBiPredicate
.static BooleanSupplier
booleanSupplier
(CheckedBooleanSupplier supplier) Wrap aCheckedBooleanSupplier
in aBooleanSupplier
.static <T> Callable<T>
callable
(CheckedCallable<T> callable) Wrap aCheckedCallable
in aCallable
.static <T> Comparator<T>
comparator
(CheckedComparator<T> comparator) Wrap aCheckedComparator
in aComparator
.static <T> Consumer<T>
consumer
(CheckedConsumer<T> consumer) Wrap aCheckedConsumer
in aConsumer
.static DoubleBinaryOperator
Wrap aCheckedDoubleBinaryOperator
in aDoubleBinaryOperator
.static DoubleConsumer
doubleConsumer
(CheckedDoubleConsumer consumer) Wrap aCheckedDoubleConsumer
in aDoubleConsumer
.static <R> DoubleFunction<R>
doubleFunction
(CheckedDoubleFunction<R> function) Wrap aCheckedDoubleFunction
in aDoubleFunction
.static DoublePredicate
doublePredicate
(CheckedDoublePredicate predicate) Wrap aCheckedDoublePredicate
in aDoublePredicate
.static DoubleSupplier
doubleSupplier
(CheckedDoubleSupplier supplier) Wrap aCheckedDoubleSupplier
in aDoubleSupplier
.static DoubleToIntFunction
Wrap aCheckedDoubleToIntFunction
in aDoubleToIntFunction
.static DoubleToLongFunction
Wrap aCheckedDoubleToLongFunction
in aDoubleToLongFunction
.static DoubleUnaryOperator
Wrap aCheckedDoubleUnaryOperator
in aDoubleUnaryOperator
.static <T,
R> Function<T, R> function
(CheckedFunction<T, R> function) Wrap aCheckedFunction
in aFunction
.static IntBinaryOperator
intBinaryOperator
(CheckedIntBinaryOperator operator) Wrap aCheckedIntBinaryOperator
in aIntBinaryOperator
.static IntConsumer
intConsumer
(CheckedIntConsumer consumer) Wrap aCheckedIntConsumer
in aIntConsumer
.static <R> IntFunction<R>
intFunction
(CheckedIntFunction<R> function) Wrap aCheckedIntFunction
in aIntFunction
.static IntPredicate
intPredicate
(CheckedIntPredicate predicate) Wrap aCheckedPredicate
in aIntPredicate
.static IntSupplier
intSupplier
(CheckedIntSupplier supplier) Wrap aCheckedIntSupplier
in aIntSupplier
.static IntToDoubleFunction
Wrap aCheckedIntToDoubleFunction
in aIntToDoubleFunction
.static IntToLongFunction
intToLongFunction
(CheckedIntToLongFunction function) Wrap aCheckedIntToLongFunction
in aIntToLongFunction
.static IntUnaryOperator
intUnaryOperator
(CheckedIntUnaryOperator operator) Wrap aCheckedIntUnaryOperator
in aIntUnaryOperator
.static LongBinaryOperator
longBinaryOperator
(CheckedLongBinaryOperator operator) Wrap aCheckedLongBinaryOperator
in aLongBinaryOperator
.static LongConsumer
longConsumer
(CheckedLongConsumer consumer) Wrap aCheckedLongConsumer
in aLongConsumer
.static <R> LongFunction<R>
longFunction
(CheckedLongFunction<R> function) Wrap aCheckedLongFunction
in aLongFunction
.static LongPredicate
longPredicate
(CheckedLongPredicate predicate) Wrap aCheckedLongPredicate
in aLongPredicate
.static LongSupplier
longSupplier
(CheckedLongSupplier supplier) Wrap aCheckedLongSupplier
in aLongSupplier
.static LongToDoubleFunction
Wrap aCheckedLongToDoubleFunction
in aLongToDoubleFunction
.static LongToIntFunction
longToIntFunction
(CheckedLongToIntFunction function) Wrap aCheckedLongToIntFunction
in aLongToIntFunction
.static LongUnaryOperator
longUnaryOperator
(CheckedLongUnaryOperator operator) Wrap aCheckedLongUnaryOperator
in aLongUnaryOperator
.static <T> ObjDoubleConsumer<T>
objDoubleConsumer
(CheckedObjDoubleConsumer<T> consumer) Wrap aCheckedObjDoubleConsumer
in aObjDoubleConsumer
.static <T> ObjIntConsumer<T>
objIntConsumer
(CheckedObjIntConsumer<T> consumer) Wrap aCheckedObjIntConsumer
in aObjIntConsumer
.static <T> ObjLongConsumer<T>
objLongConsumer
(CheckedObjLongConsumer<T> consumer) Wrap aCheckedObjLongConsumer
in aObjLongConsumer
.static <T> Predicate<T>
predicate
(CheckedPredicate<T> predicate) Wrap aCheckedPredicate
in aPredicate
.static Runnable
runnable
(CheckedRunnable runnable) Wrap aCheckedRunnable
in aRunnable
.static <T> Supplier<T>
supplier
(CheckedSupplier<T> supplier) Wrap aCheckedSupplier
in aSupplier
.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> ToDoubleFunction<T>
toDoubleFunction
(CheckedToDoubleFunction<T> function) Wrap aCheckedToDoubleFunction
in aToDoubleFunction
.static <T,
U> ToIntBiFunction<T, U> toIntBiFunction
(CheckedToIntBiFunction<T, U> function) Wrap aCheckedToIntBiFunction
in aToIntBiFunction
.static <T> ToIntFunction<T>
toIntFunction
(CheckedToIntFunction<T> function) Wrap aCheckedToIntFunction
in aToIntFunction
.static <T,
U> ToLongBiFunction<T, U> toLongBiFunction
(CheckedToLongBiFunction<T, U> function) Wrap aCheckedToLongBiFunction
in aToLongBiFunction
.static <T> ToLongFunction<T>
toLongFunction
(CheckedToLongFunction<T> function) Wrap aCheckedToLongFunction
in aToLongFunction
.static <T> UnaryOperator<T>
unaryOperator
(CheckedUnaryOperator<T> operator) Wrap aCheckedUnaryOperator
in aUnaryOperator
.
-
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();
-
callable
Wrap aCheckedCallable
in aCallable
.Example:
Executors.newFixedThreadPool(1).submit(Unchecked.callable(() -> { throw new Exception("Cannot execute this task"); })).get();
-
comparator
Wrap aCheckedComparator
in aComparator
. -
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"); }));
-
objIntConsumer
Wrap aCheckedObjIntConsumer
in aObjIntConsumer
. -
objLongConsumer
Wrap aCheckedObjLongConsumer
in aObjLongConsumer
. -
objDoubleConsumer
Wrap aCheckedObjDoubleConsumer
in aObjDoubleConsumer
. -
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; }));
-
toIntBiFunction
Wrap aCheckedToIntBiFunction
in aToIntBiFunction
. -
toLongBiFunction
Wrap aCheckedToLongBiFunction
in aToLongBiFunction
. -
toDoubleBiFunction
public static <T,U> ToDoubleBiFunction<T,U> toDoubleBiFunction(CheckedToDoubleBiFunction<T, U> function) Wrap aCheckedToDoubleBiFunction
in aToDoubleBiFunction
. -
biPredicate
Wrap aCheckedBiPredicate
in aBiPredicate
. -
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; }));
-
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; }));
-
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; }));
-
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; }));
-
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"); }));
-
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"); }));
-
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"); }));
-
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"); }));
-
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; }));
-
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; }));
-
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; }));
-
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; }));
-
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; });
-
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; });
-
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; });
-
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; });
-
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; });
-
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; });
-
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; });
-
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; });
-
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; });
-
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; }));
-
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; }));
-
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; }));
-
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; }));
-
supplier
Wrap aCheckedSupplier
in aSupplier
.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.supplier(() -> rs.getObject(1)));
-
intSupplier
Wrap aCheckedIntSupplier
in aIntSupplier
.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.intSupplier(() -> rs.getInt(1)));
-
longSupplier
Wrap aCheckedLongSupplier
in aLongSupplier
.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.longSupplier(() -> rs.getLong(1)));
-
doubleSupplier
Wrap aCheckedDoubleSupplier
in aDoubleSupplier
.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.doubleSupplier(() -> rs.getDouble(1)));
-
booleanSupplier
Wrap aCheckedBooleanSupplier
in aBooleanSupplier
.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.booleanSupplier(() -> rs.getBoolean(1)));
-
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; }));
-
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; }));
-
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; }));
-
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; }));
-