Class FunctionalUtil

java.lang.Object
pl.matsuo.core.util.function.FunctionalUtil

public class FunctionalUtil extends Object
Functional programming utils.
  • Field Details

    • ignoringExConsumer

      public static final Consumer<Exception> ignoringExConsumer
      Consumer of exception that logs error.
    • runtimeExConsumer

      public static final Consumer<Exception> runtimeExConsumer
      Consumer that throws RuntimeException with passed exception as root cause.
  • Constructor Details

    • FunctionalUtil

      public FunctionalUtil()
  • Method Details

    • access

      public static <E> FunctionalUtil.AccessProvider<E> access(Supplier<E> getter, Consumer<E> setter)
      Create access provider from getter/setter pair.
    • access

      public static <E> FunctionalUtil.AccessProvider<E> access(Object object, Field field)
      Create access provider from field on object.
    • with

      public static <E> E with(E object, Consumer<E> invoke)
      Invoke consumer with object as parameter.
    • transform

      public static <E, F> F transform(E object, Function<E,F> invoke)
      Return function invocation result with object as parameter.
    • with

      public static <E, F> void with(E object, F object2, BiConsumer<E,F> invoke)
      Invoke consumer with two objects as parameters.
    • ignoreEx

      public static <E> E ignoreEx(ThrowingExceptionsSupplier<E> throwsExceptions)
      Invoke supplier and return null on exception.
    • ignoreEx

      public static void ignoreEx(ThrowingExceptionsRunnable throwsExceptions)
      Invoke runnable and ignore exceptions.
    • runtimeEx

      public static <E> E runtimeEx(ThrowingExceptionsSupplier<E> throwsExceptions)
      Invoke supplier and throw RuntimeException on exception.
    • runtimeEx

      public static void runtimeEx(ThrowingExceptionsRunnable throwsExceptions)
      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

      public static <E> Consumer<E> compose(Consumer<? super E>... parts)
      Create consumer that invokes list of inner consumers.
    • either

      public static <E> E either(boolean what, Supplier<E> ifTrue, Supplier<E> ifFalse)
      Invoke ifTrue or ifFalse depending on what parameter.
    • repeat

      public static void repeat(Supplier<Boolean> condition, Runnable exec)
      Repeat runnable invocations until condition is true.
    • collectList

      public static <E> List<E> collectList(Supplier<Boolean> condition, Supplier<E> getter)
      Collect elements returned by getter until condition is true;