Top Description Constructors Methods
org.jooq.lambda

public final Class Sneaky

extends Object
Class Inheritance
Imports
org.jooq.lambda.fi.util.function.*, org.jooq.lambda.fi.lang.CheckedRunnable, org.jooq.lambda.fi.util.CheckedComparator, org.jooq.lambda.fi.util.concurrent.CheckedCallable, java.util.Comparator, java.util.concurrent.Callable, java.util.function.*

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

Constructor Summary

AccessConstructor and Description
private
Sneaky()

No instances

Method Summary

Modifier and TypeMethod and Description
public static <T, U> BiConsumer<T, U>
public static <T, U, R> BiFunction<T, U, R>
public static <T> BinaryOperator<T>
public static <T, U> BiPredicate<T, U>
public static BooleanSupplier
public static <T> Callable<T>
public static <T> Comparator<T>
public static <T> Consumer<T>
public static DoubleBinaryOperator
public static DoubleConsumer
public static <R> DoubleFunction<R>
public static DoublePredicate
public static DoubleSupplier
public static DoubleToIntFunction
public static DoubleToLongFunction
public static DoubleUnaryOperator
public static <T, R> Function<T, R>
function(CheckedFunction<T, R> function)

Wrap a CheckedFunction in a Function.

public static IntBinaryOperator
public static IntConsumer
public static <R> IntFunction<R>
public static IntPredicate
public static IntSupplier
public static IntToDoubleFunction
public static IntToLongFunction
public static IntUnaryOperator
public static LongBinaryOperator
public static LongConsumer
public static <R> LongFunction<R>
public static LongPredicate
public static LongSupplier
public static LongToDoubleFunction
public static LongToIntFunction
public static LongUnaryOperator
public static <T> ObjDoubleConsumer<T>
public static <T> ObjIntConsumer<T>
public static <T> ObjLongConsumer<T>
public static <T> Predicate<T>
public static Runnable
public static <T> Supplier<T>
public static void
throwChecked(Throwable t)

"sneaky-throw" a checked exception or throwable.

public static <T, U> ToDoubleBiFunction<T, U>
public static <T> ToDoubleFunction<T>
public static <T, U> ToIntBiFunction<T, U>
public static <T> ToIntFunction<T>
public static <T, U> ToLongBiFunction<T, U>
public static <T> ToLongFunction<T>
public static <T> UnaryOperator<T>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Sneakyback to summary
private Sneaky()

No instances

Method Detail

biConsumerback to summary
public static <T, U> BiConsumer<T, U> biConsumer(CheckedBiConsumer<T, U> consumer)

Wrap a org.jooq.lambda.fi.util.function.CheckedBiConsumer in a BiConsumer.

Example:


map.forEach(Unchecked.biConsumer((k, v) -> {
    if (k == null || v == null)
        throw new Exception("No nulls allowed in map");
}));
biFunctionback to summary
public static <T, U, R> BiFunction<T, U, R> biFunction(CheckedBiFunction<T, U, R> function)

Wrap a org.jooq.lambda.fi.util.function.CheckedBiFunction in a BiFunction.

Example:


map.computeIfPresent("key", Unchecked.biFunction((k, v) -> {
    if (k == null || v == null)
        throw new Exception("No nulls allowed in map");

    return 42;
}));
binaryOperatorback to summary
public static <T> BinaryOperator<T> binaryOperator(CheckedBinaryOperator<T> operator)

Wrap a org.jooq.lambda.fi.util.function.CheckedBinaryOperator in a BinaryOperator.

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;
}));
biPredicateback to summary
public static <T, U> BiPredicate<T, U> biPredicate(CheckedBiPredicate<T, U> predicate)

Wrap a org.jooq.lambda.fi.util.function.CheckedBiPredicate in a BiPredicate.

booleanSupplierback to summary
public static BooleanSupplier booleanSupplier(CheckedBooleanSupplier supplier)

Wrap a org.jooq.lambda.fi.util.function.CheckedBooleanSupplier in a BooleanSupplier.

Example:


ResultSet rs = statement.executeQuery();
Stream.generate(Unchecked.booleanSupplier(() -> rs.getBoolean(1)));
callableback to summary
public static <T> Callable<T> callable(CheckedCallable<T> callable)

Wrap a CheckedCallable in a Callable.

Example:


Executors.newFixedThreadPool(1).submit(Unchecked.callable(() -> {
    throw new Exception("Cannot execute this task");
})).get();
comparatorback to summary
public static <T> Comparator<T> comparator(CheckedComparator<T> comparator)

Wrap a CheckedComparator in a Comparator.

consumerback to summary
public static <T> Consumer<T> consumer(CheckedConsumer<T> consumer)

Wrap a CheckedConsumer in a Consumer.

Example:


Arrays.asList("a", "b").stream().forEach(Unchecked.consumer(s -> {
    if (s.length() > 10)
        throw new Exception("Only short strings allowed");
}));
doubleBinaryOperatorback to summary
public static DoubleBinaryOperator doubleBinaryOperator(CheckedDoubleBinaryOperator operator)

Wrap a CheckedDoubleBinaryOperator in a DoubleBinaryOperator.

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;
}));
doubleConsumerback to summary
public static DoubleConsumer doubleConsumer(CheckedDoubleConsumer consumer)

Wrap a CheckedDoubleConsumer in a DoubleConsumer.

Example:


Arrays.stream(new double[] { 1.0, 2.0 }).forEach(Unchecked.doubleConsumer(d -> {
    if (d < 0.0)
        throw new Exception("Only positive numbers allowed");
}));
doubleFunctionback to summary
public static <R> DoubleFunction<R> doubleFunction(CheckedDoubleFunction<R> function)

Wrap a CheckedDoubleFunction in a DoubleFunction.

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;
});
doublePredicateback to summary
public static DoublePredicate doublePredicate(CheckedDoublePredicate predicate)

Wrap a CheckedDoublePredicate in a DoublePredicate.

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;
}));
doubleSupplierback to summary
public static DoubleSupplier doubleSupplier(CheckedDoubleSupplier supplier)

Wrap a CheckedDoubleSupplier in a DoubleSupplier.

Example:


ResultSet rs = statement.executeQuery();
Stream.generate(Unchecked.doubleSupplier(() -> rs.getDouble(1)));
doubleToIntFunctionback to summary
public static DoubleToIntFunction doubleToIntFunction(CheckedDoubleToIntFunction function)

Wrap a CheckedDoubleToIntFunction in a DoubleToIntFunction.

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;
});
doubleToLongFunctionback to summary
public static DoubleToLongFunction doubleToLongFunction(CheckedDoubleToLongFunction function)

Wrap a CheckedDoubleToLongFunction in a DoubleToLongFunction.

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;
});
doubleUnaryOperatorback to summary
public static DoubleUnaryOperator doubleUnaryOperator(CheckedDoubleUnaryOperator operator)

Wrap a CheckedDoubleUnaryOperator in a DoubleUnaryOperator.

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;
}));
functionback to summary
public static <T, R> Function<T, R> function(CheckedFunction<T, R> function)

Wrap a CheckedFunction in a Function.

Example:


map.computeIfAbsent("key", Unchecked.function(k -> {
    if (k.length() > 10)
        throw new Exception("Only short strings allowed");

    return 42;
}));
intBinaryOperatorback to summary
public static IntBinaryOperator intBinaryOperator(CheckedIntBinaryOperator operator)

Wrap a CheckedIntBinaryOperator in a IntBinaryOperator.

Example:


IntStream.of(1, 2, 3).reduce(Unchecked.intBinaryOperator((i1, i2) -> {
    if (i2 < 0)
        throw new Exception("Only positive numbers allowed");

    return i1 + i2;
}));
intConsumerback to summary
public static IntConsumer intConsumer(CheckedIntConsumer consumer)

Wrap a CheckedIntConsumer in a IntConsumer.

Example:


Arrays.stream(new int[] { 1, 2 }).forEach(Unchecked.intConsumer(i -> {
    if (i < 0)
        throw new Exception("Only positive numbers allowed");
}));
intFunctionback to summary
public static <R> IntFunction<R> intFunction(CheckedIntFunction<R> function)

Wrap a CheckedIntFunction in a IntFunction.

Example:


IntStream.of(1, 2, 3).mapToObj(Unchecked.intFunction(i -> {
    if (i < 0)
        throw new Exception("Only positive numbers allowed");

    return "" + i;
});
intPredicateback to summary
public static IntPredicate intPredicate(CheckedIntPredicate predicate)

Wrap a CheckedPredicate in a IntPredicate.

Example:


IntStream.of(1, 2, 3).filter(Unchecked.intPredicate(i -> {
    if (i < 0)
        throw new Exception("Only positive numbers allowed");

    return true;
}));
intSupplierback to summary
public static IntSupplier intSupplier(CheckedIntSupplier supplier)

Wrap a CheckedIntSupplier in a IntSupplier.

Example:


ResultSet rs = statement.executeQuery();
Stream.generate(Unchecked.intSupplier(() -> rs.getInt(1)));
intToDoubleFunctionback to summary
public static IntToDoubleFunction intToDoubleFunction(CheckedIntToDoubleFunction function)

Wrap a CheckedIntToDoubleFunction in a IntToDoubleFunction.

Example:


IntStream.of(1, 2, 3).mapToDouble(Unchecked.intToDoubleFunction(i -> {
    if (i < 0)
        throw new Exception("Only positive numbers allowed");

    return (double) i;
});
intToLongFunctionback to summary
public static IntToLongFunction intToLongFunction(CheckedIntToLongFunction function)

Wrap a CheckedIntToLongFunction in a IntToLongFunction.

Example:


IntStream.of(1, 2, 3).mapToLong(Unchecked.intToLongFunction(i -> {
    if (i < 0)
        throw new Exception("Only positive numbers allowed");

    return (long) i;
});
intUnaryOperatorback to summary
public static IntUnaryOperator intUnaryOperator(CheckedIntUnaryOperator operator)

Wrap a CheckedIntUnaryOperator in a IntUnaryOperator.

Example:


IntStream.of(1, 2, 3).map(Unchecked.intUnaryOperator(i -> {
    if (i < 0)
        throw new Exception("Only positive numbers allowed");

    return i;
}));
longBinaryOperatorback to summary
public static LongBinaryOperator longBinaryOperator(CheckedLongBinaryOperator operator)

Wrap a CheckedLongBinaryOperator in a LongBinaryOperator.

Example:


LongStream.of(1L, 2L, 3L).reduce(Unchecked.longBinaryOperator((l1, l2) -> {
    if (l2 < 0L)
        throw new Exception("Only positive numbers allowed");

    return l1 + l2;
}));
longConsumerback to summary
public static LongConsumer longConsumer(CheckedLongConsumer consumer)

Wrap a CheckedLongConsumer in a LongConsumer.

Example:


Arrays.stream(new long[] { 1L, 2L }).forEach(Unchecked.longConsumer(l -> {
    if (l < 0)
        throw new Exception("Only positive numbers allowed");
}));
longFunctionback to summary
public static <R> LongFunction<R> longFunction(CheckedLongFunction<R> function)

Wrap a CheckedLongFunction in a LongFunction.

Example:


LongStream.of(1L, 2L, 3L).mapToObj(Unchecked.longFunction(l -> {
    if (l < 0L)
        throw new Exception("Only positive numbers allowed");

    return "" + l;
});
longPredicateback to summary
public static LongPredicate longPredicate(CheckedLongPredicate predicate)

Wrap a CheckedLongPredicate in a LongPredicate.

Example:


LongStream.of(1L, 2L, 3L).filter(Unchecked.longPredicate(l -> {
    if (l < 0L)
        throw new Exception("Only positive numbers allowed");

    return true;
}));
longSupplierback to summary
public static LongSupplier longSupplier(CheckedLongSupplier supplier)

Wrap a CheckedLongSupplier in a LongSupplier.

Example:


ResultSet rs = statement.executeQuery();
Stream.generate(Unchecked.longSupplier(() -> rs.getLong(1)));
longToDoubleFunctionback to summary
public static LongToDoubleFunction longToDoubleFunction(CheckedLongToDoubleFunction function)

Wrap a CheckedLongToDoubleFunction in a LongToDoubleFunction.

Example:


LongStream.of(1L, 2L, 3L).mapToInt(Unchecked.longToDoubleFunction(l -> {
    if (l < 0L)
        throw new Exception("Only positive numbers allowed");

    return (double) l;
});
longToIntFunctionback to summary
public static LongToIntFunction longToIntFunction(CheckedLongToIntFunction function)

Wrap a CheckedLongToIntFunction in a LongToIntFunction.

Example:


LongStream.of(1L, 2L, 3L).mapToInt(Unchecked.longToIntFunction(l -> {
    if (l < 0L)
        throw new Exception("Only positive numbers allowed");

    return (int) l;
});
longUnaryOperatorback to summary
public static LongUnaryOperator longUnaryOperator(CheckedLongUnaryOperator operator)

Wrap a CheckedLongUnaryOperator in a LongUnaryOperator.

Example:


LongStream.of(1L, 2L, 3L).map(Unchecked.longUnaryOperator(l -> {
    if (l < 0L)
        throw new Exception("Only positive numbers allowed");

    return l;
}));
objDoubleConsumerback to summary
public static <T> ObjDoubleConsumer<T> objDoubleConsumer(CheckedObjDoubleConsumer<T> consumer)

Wrap a CheckedObjDoubleConsumer in a ObjDoubleConsumer.

objIntConsumerback to summary
public static <T> ObjIntConsumer<T> objIntConsumer(CheckedObjIntConsumer<T> consumer)

Wrap a CheckedObjIntConsumer in a ObjIntConsumer.

objLongConsumerback to summary
public static <T> ObjLongConsumer<T> objLongConsumer(CheckedObjLongConsumer<T> consumer)

Wrap a CheckedObjLongConsumer in a ObjLongConsumer.

predicateback to summary
public static <T> Predicate<T> predicate(CheckedPredicate<T> predicate)

Wrap a CheckedPredicate in a Predicate.

Example:


Stream.of("a", "b", "c").filter(Unchecked.predicate(s -> {
    if (s.length() > 10)
        throw new Exception("Only short strings allowed");

    return true;
}));
runnableback to summary
public static Runnable runnable(CheckedRunnable runnable)

Wrap a CheckedRunnable in a Runnable.

Example:


new Thread(Unchecked.runnable(() -> {
    throw new Exception("Cannot run this thread");
})).start();
supplierback to summary
public static <T> Supplier<T> supplier(CheckedSupplier<T> supplier)

Wrap a CheckedSupplier in a Supplier.

Example:


ResultSet rs = statement.executeQuery();
Stream.generate(Unchecked.supplier(() -> rs.getObject(1)));
throwCheckedback to summary
public static void throwChecked(Throwable t)

"sneaky-throw" a checked exception or throwable.

toDoubleBiFunctionback to summary
public static <T, U> ToDoubleBiFunction<T, U> toDoubleBiFunction(CheckedToDoubleBiFunction<T, U> function)

Wrap a CheckedToDoubleBiFunction in a ToDoubleBiFunction.

toDoubleFunctionback to summary
public static <T> ToDoubleFunction<T> toDoubleFunction(CheckedToDoubleFunction<T> function)

Wrap a CheckedToDoubleFunction in a ToDoubleFunction.

Example:


map.computeIfAbsent("key", Unchecked.toDoubleFunction(k -> {
    if (k.length() > 10)
        throw new Exception("Only short strings allowed");

    return 42.0;
}));
toIntBiFunctionback to summary
public static <T, U> ToIntBiFunction<T, U> toIntBiFunction(CheckedToIntBiFunction<T, U> function)

Wrap a CheckedToIntBiFunction in a ToIntBiFunction.

toIntFunctionback to summary
public static <T> ToIntFunction<T> toIntFunction(CheckedToIntFunction<T> function)

Wrap a CheckedToIntFunction in a ToIntFunction.

Example:


map.computeIfAbsent("key", Unchecked.toIntFunction(k -> {
    if (k.length() > 10)
        throw new Exception("Only short strings allowed");

    return 42;
}));
toLongBiFunctionback to summary
public static <T, U> ToLongBiFunction<T, U> toLongBiFunction(CheckedToLongBiFunction<T, U> function)

Wrap a CheckedToLongBiFunction in a ToLongBiFunction.

toLongFunctionback to summary
public static <T> ToLongFunction<T> toLongFunction(CheckedToLongFunction<T> function)

Wrap a CheckedToLongFunction in a ToLongFunction.

Example:


map.computeIfAbsent("key", Unchecked.toLongFunction(k -> {
    if (k.length() > 10)
        throw new Exception("Only short strings allowed");

    return 42L;
}));
unaryOperatorback to summary
public static <T> UnaryOperator<T> unaryOperator(CheckedUnaryOperator<T> operator)

Wrap a CheckedUnaryOperator in a UnaryOperator.

Example:


Stream.of("a", "b", "c").map(Unchecked.unaryOperator(s -> {
    if (s.length() > 10)
        throw new Exception("Only short strings allowed");

    return s;
}));