Package pl.matsuo.core.util.function
Class FunctionalUtil
java.lang.Object
pl.matsuo.core.util.function.FunctionalUtil
public class FunctionalUtil extends Object
Functional programming utils.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFunctionalUtil.AccessProvider<E>Objects provide access to some element. -
Field Summary
Fields Modifier and Type Field Description static Consumer<Exception>ignoringExConsumerConsumer of exception that logs error.static Consumer<Exception>runtimeExConsumerConsumer that throws RuntimeException with passed exception as root cause. -
Constructor Summary
Constructors Constructor Description FunctionalUtil() -
Method Summary
Modifier and Type Method Description static <E> FunctionalUtil.AccessProvider<E>access(Object object, Field field)Create access provider from field on object.static <E> FunctionalUtil.AccessProvider<E>access(Supplier<E> getter, Consumer<E> setter)Create access provider from getter/setter pair.static <E> List<E>collectList(Supplier<Boolean> condition, Supplier<E> getter)Collect elements returned by getter until condition is true;static <E> Consumer<E>compose(Consumer<? super E>... parts)Create consumer that invokes list of inner consumers.static <E> Eeither(boolean what, Supplier<E> ifTrue, Supplier<E> ifFalse)Invoke ifTrue or ifFalse depending on what parameter.static voidignoreEx(ThrowingExceptionsRunnable throwsExceptions)Invoke runnable and ignore exceptions.static <E> EignoreEx(ThrowingExceptionsSupplier<E> throwsExceptions)Invoke supplier and return null on exception.static voidprocessEx(ThrowingExceptionsRunnable throwsExceptions, Consumer<Exception> processEx)Invoke runnable with exception handler.static <E> EprocessEx(ThrowingExceptionsSupplier<E> throwsExceptions, Function<Exception,E> processEx)Invoke supplier with exception handler.static voidrepeat(Supplier<Boolean> condition, Runnable exec)Repeat runnable invocations until condition is true.static voidruntimeEx(ThrowingExceptionsRunnable throwsExceptions)Invoke runnable and throw RuntimeException on exception.static voidruntimeEx(ThrowingExceptionsRunnable throwsExceptions, Consumer<Exception> processEx)Invoke runnable with exception handler.static <E> EruntimeEx(ThrowingExceptionsSupplier<E> throwsExceptions)Invoke supplier and throw RuntimeException on exception.static <E, F> Ftransform(E object, Function<E,F> invoke)Return function invocation result with object as parameter.static <E, F> voidwith(E object, F object2, BiConsumer<E,F> invoke)Invoke consumer with two objects as parameters.static <E> Ewith(E object, Consumer<E> invoke)Invoke consumer with object as parameter.
-
Field Details
-
ignoringExConsumer
Consumer of exception that logs error. -
runtimeExConsumer
Consumer that throws RuntimeException with passed exception as root cause.
-
-
Constructor Details
-
FunctionalUtil
public FunctionalUtil()
-
-
Method Details
-
access
Create access provider from getter/setter pair. -
access
Create access provider from field on object. -
with
Invoke consumer with object as parameter. -
transform
Return function invocation result with object as parameter. -
with
Invoke consumer with two objects as parameters. -
ignoreEx
Invoke supplier and return null on exception. -
ignoreEx
Invoke runnable and ignore exceptions. -
runtimeEx
Invoke supplier and throw RuntimeException on exception. -
runtimeEx
Invoke runnable and throw RuntimeException on exception. -
runtimeEx
public static void runtimeEx(ThrowingExceptionsRunnable throwsExceptions, Consumer<Exception> processEx)Invoke runnable with exception handler. -
processEx
public static <E> E processEx(ThrowingExceptionsSupplier<E> throwsExceptions, Function<Exception,E> processEx)Invoke supplier with exception handler. -
processEx
public static void processEx(ThrowingExceptionsRunnable throwsExceptions, Consumer<Exception> processEx)Invoke runnable with exception handler. -
compose
Create consumer that invokes list of inner consumers. -
either
Invoke ifTrue or ifFalse depending on what parameter. -
repeat
Repeat runnable invocations until condition is true. -
collectList
Collect elements returned by getter until condition is true;
-