- java.lang.Object
-
- org.jooq.lambda.Sneaky
-
public final class Sneaky extends java.lang.ObjectImproved interoperability between checked exceptions and Java 8.Similar to
Unchecked, except thatUnchecked.RETHROW_ALLis used as the default way to re-throw checked exceptions.
-
-
Constructor Summary
Constructors Modifier Constructor Description privateSneaky()No instances
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,U>
java.util.function.BiConsumer<T,U>biConsumer(CheckedBiConsumer<T,U> consumer)Wrap aCheckedBiConsumerin aBiConsumer.static <T,U,R>
java.util.function.BiFunction<T,U,R>biFunction(CheckedBiFunction<T,U,R> function)Wrap aCheckedBiFunctionin aBiFunction.static <T> java.util.function.BinaryOperator<T>binaryOperator(CheckedBinaryOperator<T> operator)Wrap aCheckedBinaryOperatorin aBinaryOperator.static <T,U>
java.util.function.BiPredicate<T,U>biPredicate(CheckedBiPredicate<T,U> predicate)Wrap aCheckedBiPredicatein aBiPredicate.static java.util.function.BooleanSupplierbooleanSupplier(CheckedBooleanSupplier supplier)Wrap aCheckedBooleanSupplierin aBooleanSupplier.static <T> java.util.concurrent.Callable<T>callable(CheckedCallable<T> callable)Wrap aCheckedCallablein aCallable.static <T> java.util.Comparator<T>comparator(CheckedComparator<T> comparator)Wrap aCheckedComparatorin aComparator.static <T> java.util.function.Consumer<T>consumer(CheckedConsumer<T> consumer)Wrap aCheckedConsumerin aConsumer.static java.util.function.DoubleBinaryOperatordoubleBinaryOperator(CheckedDoubleBinaryOperator operator)Wrap aCheckedDoubleBinaryOperatorin aDoubleBinaryOperator.static java.util.function.DoubleConsumerdoubleConsumer(CheckedDoubleConsumer consumer)Wrap aCheckedDoubleConsumerin aDoubleConsumer.static <R> java.util.function.DoubleFunction<R>doubleFunction(CheckedDoubleFunction<R> function)Wrap aCheckedDoubleFunctionin aDoubleFunction.static java.util.function.DoublePredicatedoublePredicate(CheckedDoublePredicate predicate)Wrap aCheckedDoublePredicatein aDoublePredicate.static java.util.function.DoubleSupplierdoubleSupplier(CheckedDoubleSupplier supplier)Wrap aCheckedDoubleSupplierin aDoubleSupplier.static java.util.function.DoubleToIntFunctiondoubleToIntFunction(CheckedDoubleToIntFunction function)Wrap aCheckedDoubleToIntFunctionin aDoubleToIntFunction.static java.util.function.DoubleToLongFunctiondoubleToLongFunction(CheckedDoubleToLongFunction function)Wrap aCheckedDoubleToLongFunctionin aDoubleToLongFunction.static java.util.function.DoubleUnaryOperatordoubleUnaryOperator(CheckedDoubleUnaryOperator operator)Wrap aCheckedDoubleUnaryOperatorin aDoubleUnaryOperator.static <T,R>
java.util.function.Function<T,R>function(CheckedFunction<T,R> function)Wrap aCheckedFunctionin aFunction.static java.util.function.IntBinaryOperatorintBinaryOperator(CheckedIntBinaryOperator operator)Wrap aCheckedIntBinaryOperatorin aIntBinaryOperator.static java.util.function.IntConsumerintConsumer(CheckedIntConsumer consumer)Wrap aCheckedIntConsumerin aIntConsumer.static <R> java.util.function.IntFunction<R>intFunction(CheckedIntFunction<R> function)Wrap aCheckedIntFunctionin aIntFunction.static java.util.function.IntPredicateintPredicate(CheckedIntPredicate predicate)Wrap aCheckedPredicatein aIntPredicate.static java.util.function.IntSupplierintSupplier(CheckedIntSupplier supplier)Wrap aCheckedIntSupplierin aIntSupplier.static java.util.function.IntToDoubleFunctionintToDoubleFunction(CheckedIntToDoubleFunction function)Wrap aCheckedIntToDoubleFunctionin aIntToDoubleFunction.static java.util.function.IntToLongFunctionintToLongFunction(CheckedIntToLongFunction function)Wrap aCheckedIntToLongFunctionin aIntToLongFunction.static java.util.function.IntUnaryOperatorintUnaryOperator(CheckedIntUnaryOperator operator)Wrap aCheckedIntUnaryOperatorin aIntUnaryOperator.static java.util.function.LongBinaryOperatorlongBinaryOperator(CheckedLongBinaryOperator operator)Wrap aCheckedLongBinaryOperatorin aLongBinaryOperator.static java.util.function.LongConsumerlongConsumer(CheckedLongConsumer consumer)Wrap aCheckedLongConsumerin aLongConsumer.static <R> java.util.function.LongFunction<R>longFunction(CheckedLongFunction<R> function)Wrap aCheckedLongFunctionin aLongFunction.static java.util.function.LongPredicatelongPredicate(CheckedLongPredicate predicate)Wrap aCheckedLongPredicatein aLongPredicate.static java.util.function.LongSupplierlongSupplier(CheckedLongSupplier supplier)Wrap aCheckedLongSupplierin aLongSupplier.static java.util.function.LongToDoubleFunctionlongToDoubleFunction(CheckedLongToDoubleFunction function)Wrap aCheckedLongToDoubleFunctionin aLongToDoubleFunction.static java.util.function.LongToIntFunctionlongToIntFunction(CheckedLongToIntFunction function)Wrap aCheckedLongToIntFunctionin aLongToIntFunction.static java.util.function.LongUnaryOperatorlongUnaryOperator(CheckedLongUnaryOperator operator)Wrap aCheckedLongUnaryOperatorin aLongUnaryOperator.static <T> java.util.function.ObjDoubleConsumer<T>objDoubleConsumer(CheckedObjDoubleConsumer<T> consumer)Wrap aCheckedObjDoubleConsumerin aObjDoubleConsumer.static <T> java.util.function.ObjIntConsumer<T>objIntConsumer(CheckedObjIntConsumer<T> consumer)Wrap aCheckedObjIntConsumerin aObjIntConsumer.static <T> java.util.function.ObjLongConsumer<T>objLongConsumer(CheckedObjLongConsumer<T> consumer)Wrap aCheckedObjLongConsumerin aObjLongConsumer.static <T> java.util.function.Predicate<T>predicate(CheckedPredicate<T> predicate)Wrap aCheckedPredicatein aPredicate.static java.lang.Runnablerunnable(CheckedRunnable runnable)Wrap aCheckedRunnablein aRunnable.static <T> java.util.function.Supplier<T>supplier(CheckedSupplier<T> supplier)Wrap aCheckedSupplierin aSupplier.static voidthrowChecked(java.lang.Throwable t)"sneaky-throw" a checked exception or throwable.static <T,U>
java.util.function.ToDoubleBiFunction<T,U>toDoubleBiFunction(CheckedToDoubleBiFunction<T,U> function)Wrap aCheckedToDoubleBiFunctionin aToDoubleBiFunction.static <T> java.util.function.ToDoubleFunction<T>toDoubleFunction(CheckedToDoubleFunction<T> function)Wrap aCheckedToDoubleFunctionin aToDoubleFunction.static <T,U>
java.util.function.ToIntBiFunction<T,U>toIntBiFunction(CheckedToIntBiFunction<T,U> function)Wrap aCheckedToIntBiFunctionin aToIntBiFunction.static <T> java.util.function.ToIntFunction<T>toIntFunction(CheckedToIntFunction<T> function)Wrap aCheckedToIntFunctionin aToIntFunction.static <T,U>
java.util.function.ToLongBiFunction<T,U>toLongBiFunction(CheckedToLongBiFunction<T,U> function)Wrap aCheckedToLongBiFunctionin aToLongBiFunction.static <T> java.util.function.ToLongFunction<T>toLongFunction(CheckedToLongFunction<T> function)Wrap aCheckedToLongFunctionin aToLongFunction.static <T> java.util.function.UnaryOperator<T>unaryOperator(CheckedUnaryOperator<T> operator)Wrap aCheckedUnaryOperatorin aUnaryOperator.
-
-
-
Method Detail
-
throwChecked
public static void throwChecked(java.lang.Throwable t)
"sneaky-throw" a checked exception or throwable.
-
runnable
public static java.lang.Runnable runnable(CheckedRunnable runnable)
Wrap aCheckedRunnablein aRunnable.Example:
new Thread(Unchecked.runnable(() -> { throw new Exception("Cannot run this thread"); })).start();
-
callable
public static <T> java.util.concurrent.Callable<T> callable(CheckedCallable<T> callable)
Wrap aCheckedCallablein aCallable.Example:
Executors.newFixedThreadPool(1).submit(Unchecked.callable(() -> { throw new Exception("Cannot execute this task"); })).get();
-
comparator
public static <T> java.util.Comparator<T> comparator(CheckedComparator<T> comparator)
Wrap aCheckedComparatorin aComparator.
-
biConsumer
public static <T,U> java.util.function.BiConsumer<T,U> biConsumer(CheckedBiConsumer<T,U> consumer)
Wrap aCheckedBiConsumerin aBiConsumer.Example:
map.forEach(Unchecked.biConsumer((k, v) -> { if (k == null || v == null) throw new Exception("No nulls allowed in map"); }));
-
objIntConsumer
public static <T> java.util.function.ObjIntConsumer<T> objIntConsumer(CheckedObjIntConsumer<T> consumer)
Wrap aCheckedObjIntConsumerin aObjIntConsumer.
-
objLongConsumer
public static <T> java.util.function.ObjLongConsumer<T> objLongConsumer(CheckedObjLongConsumer<T> consumer)
Wrap aCheckedObjLongConsumerin aObjLongConsumer.
-
objDoubleConsumer
public static <T> java.util.function.ObjDoubleConsumer<T> objDoubleConsumer(CheckedObjDoubleConsumer<T> consumer)
Wrap aCheckedObjDoubleConsumerin aObjDoubleConsumer.
-
biFunction
public static <T,U,R> java.util.function.BiFunction<T,U,R> biFunction(CheckedBiFunction<T,U,R> function)
Wrap aCheckedBiFunctionin 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
public static <T,U> java.util.function.ToIntBiFunction<T,U> toIntBiFunction(CheckedToIntBiFunction<T,U> function)
Wrap aCheckedToIntBiFunctionin aToIntBiFunction.
-
toLongBiFunction
public static <T,U> java.util.function.ToLongBiFunction<T,U> toLongBiFunction(CheckedToLongBiFunction<T,U> function)
Wrap aCheckedToLongBiFunctionin aToLongBiFunction.
-
toDoubleBiFunction
public static <T,U> java.util.function.ToDoubleBiFunction<T,U> toDoubleBiFunction(CheckedToDoubleBiFunction<T,U> function)
Wrap aCheckedToDoubleBiFunctionin aToDoubleBiFunction.
-
biPredicate
public static <T,U> java.util.function.BiPredicate<T,U> biPredicate(CheckedBiPredicate<T,U> predicate)
Wrap aCheckedBiPredicatein aBiPredicate.
-
binaryOperator
public static <T> java.util.function.BinaryOperator<T> binaryOperator(CheckedBinaryOperator<T> operator)
Wrap aCheckedBinaryOperatorin 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
public static java.util.function.IntBinaryOperator intBinaryOperator(CheckedIntBinaryOperator operator)
Wrap aCheckedIntBinaryOperatorin 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
public static java.util.function.LongBinaryOperator longBinaryOperator(CheckedLongBinaryOperator operator)
Wrap aCheckedLongBinaryOperatorin 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
public static java.util.function.DoubleBinaryOperator doubleBinaryOperator(CheckedDoubleBinaryOperator operator)
Wrap aCheckedDoubleBinaryOperatorin 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
public static <T> java.util.function.Consumer<T> consumer(CheckedConsumer<T> consumer)
Wrap aCheckedConsumerin aConsumer.Example:
Arrays.asList("a", "b").stream().forEach(Unchecked.consumer(s -> { if (s.length() > 10) throw new Exception("Only short strings allowed"); }));
-
intConsumer
public static java.util.function.IntConsumer intConsumer(CheckedIntConsumer consumer)
Wrap aCheckedIntConsumerin aIntConsumer.Example:
Arrays.stream(new int[] { 1, 2 }).forEach(Unchecked.intConsumer(i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); }));
-
longConsumer
public static java.util.function.LongConsumer longConsumer(CheckedLongConsumer consumer)
Wrap aCheckedLongConsumerin aLongConsumer.Example:
Arrays.stream(new long[] { 1L, 2L }).forEach(Unchecked.longConsumer(l -> { if (l < 0) throw new Exception("Only positive numbers allowed"); }));
-
doubleConsumer
public static java.util.function.DoubleConsumer doubleConsumer(CheckedDoubleConsumer consumer)
Wrap aCheckedDoubleConsumerin 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
public static <T,R> java.util.function.Function<T,R> function(CheckedFunction<T,R> function)
Wrap aCheckedFunctionin aFunction.Example:
map.computeIfAbsent("key", Unchecked.function(k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42; }));
-
toIntFunction
public static <T> java.util.function.ToIntFunction<T> toIntFunction(CheckedToIntFunction<T> function)
Wrap aCheckedToIntFunctionin aToIntFunction.Example:
map.computeIfAbsent("key", Unchecked.toIntFunction(k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42; }));
-
toLongFunction
public static <T> java.util.function.ToLongFunction<T> toLongFunction(CheckedToLongFunction<T> function)
Wrap aCheckedToLongFunctionin aToLongFunction.Example:
map.computeIfAbsent("key", Unchecked.toLongFunction(k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42L; }));
-
toDoubleFunction
public static <T> java.util.function.ToDoubleFunction<T> toDoubleFunction(CheckedToDoubleFunction<T> function)
Wrap aCheckedToDoubleFunctionin aToDoubleFunction.Example:
map.computeIfAbsent("key", Unchecked.toDoubleFunction(k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42.0; }));
-
intFunction
public static <R> java.util.function.IntFunction<R> intFunction(CheckedIntFunction<R> function)
Wrap aCheckedIntFunctionin aIntFunction.Example:
IntStream.of(1, 2, 3).mapToObj(Unchecked.intFunction(i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return "" + i; });
-
intToLongFunction
public static java.util.function.IntToLongFunction intToLongFunction(CheckedIntToLongFunction function)
Wrap aCheckedIntToLongFunctionin 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
public static java.util.function.IntToDoubleFunction intToDoubleFunction(CheckedIntToDoubleFunction function)
Wrap aCheckedIntToDoubleFunctionin 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
public static <R> java.util.function.LongFunction<R> longFunction(CheckedLongFunction<R> function)
Wrap aCheckedLongFunctionin aLongFunction.Example:
LongStream.of(1L, 2L, 3L).mapToObj(Unchecked.longFunction(l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return "" + l; });
-
longToIntFunction
public static java.util.function.LongToIntFunction longToIntFunction(CheckedLongToIntFunction function)
Wrap aCheckedLongToIntFunctionin 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
public static java.util.function.LongToDoubleFunction longToDoubleFunction(CheckedLongToDoubleFunction function)
Wrap aCheckedLongToDoubleFunctionin 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
public static <R> java.util.function.DoubleFunction<R> doubleFunction(CheckedDoubleFunction<R> function)
Wrap aCheckedDoubleFunctionin 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
public static java.util.function.DoubleToIntFunction doubleToIntFunction(CheckedDoubleToIntFunction function)
Wrap aCheckedDoubleToIntFunctionin 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
public static java.util.function.DoubleToLongFunction doubleToLongFunction(CheckedDoubleToLongFunction function)
Wrap aCheckedDoubleToLongFunctionin 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
public static <T> java.util.function.Predicate<T> predicate(CheckedPredicate<T> predicate)
Wrap aCheckedPredicatein 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
public static java.util.function.IntPredicate intPredicate(CheckedIntPredicate predicate)
Wrap aCheckedPredicatein aIntPredicate.Example:
IntStream.of(1, 2, 3).filter(Unchecked.intPredicate(i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return true; }));
-
longPredicate
public static java.util.function.LongPredicate longPredicate(CheckedLongPredicate predicate)
Wrap aCheckedLongPredicatein aLongPredicate.Example:
LongStream.of(1L, 2L, 3L).filter(Unchecked.longPredicate(l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return true; }));
-
doublePredicate
public static java.util.function.DoublePredicate doublePredicate(CheckedDoublePredicate predicate)
Wrap aCheckedDoublePredicatein 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
public static <T> java.util.function.Supplier<T> supplier(CheckedSupplier<T> supplier)
Wrap aCheckedSupplierin aSupplier.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.supplier(() -> rs.getObject(1)));
-
intSupplier
public static java.util.function.IntSupplier intSupplier(CheckedIntSupplier supplier)
Wrap aCheckedIntSupplierin aIntSupplier.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.intSupplier(() -> rs.getInt(1)));
-
longSupplier
public static java.util.function.LongSupplier longSupplier(CheckedLongSupplier supplier)
Wrap aCheckedLongSupplierin aLongSupplier.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.longSupplier(() -> rs.getLong(1)));
-
doubleSupplier
public static java.util.function.DoubleSupplier doubleSupplier(CheckedDoubleSupplier supplier)
Wrap aCheckedDoubleSupplierin aDoubleSupplier.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.doubleSupplier(() -> rs.getDouble(1)));
-
booleanSupplier
public static java.util.function.BooleanSupplier booleanSupplier(CheckedBooleanSupplier supplier)
Wrap aCheckedBooleanSupplierin aBooleanSupplier.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.booleanSupplier(() -> rs.getBoolean(1)));
-
unaryOperator
public static <T> java.util.function.UnaryOperator<T> unaryOperator(CheckedUnaryOperator<T> operator)
Wrap aCheckedUnaryOperatorin 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
public static java.util.function.IntUnaryOperator intUnaryOperator(CheckedIntUnaryOperator operator)
Wrap aCheckedIntUnaryOperatorin aIntUnaryOperator.Example:
IntStream.of(1, 2, 3).map(Unchecked.intUnaryOperator(i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return i; }));
-
longUnaryOperator
public static java.util.function.LongUnaryOperator longUnaryOperator(CheckedLongUnaryOperator operator)
Wrap aCheckedLongUnaryOperatorin aLongUnaryOperator.Example:
LongStream.of(1L, 2L, 3L).map(Unchecked.longUnaryOperator(l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return l; }));
-
doubleUnaryOperator
public static java.util.function.DoubleUnaryOperator doubleUnaryOperator(CheckedDoubleUnaryOperator operator)
Wrap aCheckedDoubleUnaryOperatorin 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; }));
-
-