java.lang.Object
ru.progrm_jarvis.javacommons.util.function.Runnables

public final class Runnables extends Object
Utilities related to runnables.
  • Method Details

    • none

      @NotNull public static @NotNull Runnable none()
      Creates a runnable which does nothing.
      Returns:
      runnable which does nothing
    • stateful

      @NotNull public static <T> @NotNull Runnable stateful(T initialState, @NonNull @NonNull Function<? super T,? extends T> handler)
      Creates a stateful runnable which stores its state immutably.
      Type Parameters:
      T - type of stored state
      Parameters:
      initialState - initial state of the created runnable
      handler - handler invoked on each call to Runnable.run() with the state applied to it providing the new state
      Returns:
      created stateful runnable
      Throws:
      NullPointerException - if handler is null
    • intStateful

      @NotNull public static @NotNull Runnable intStateful(int initialState, @NonNull @NonNull IntUnaryOperator handler)
      Creates a stateful runnable which stores its state immutably.
      Parameters:
      initialState - initial state of the created runnable
      handler - handler invoked on each call to Runnable.run() with the state applied to it providing the new state
      Returns:
      created stateful runnable
      Throws:
      NullPointerException - if handler is null
    • longStateful

      @NotNull public static @NotNull Runnable longStateful(long initialState, @NonNull @NonNull LongUnaryOperator handler)
      Creates a stateful runnable which stores its state immutably.
      Parameters:
      initialState - initial state of the created runnable
      handler - handler invoked on each call to Runnable.run() with the state applied to it providing the new state
      Returns:
      created stateful runnable
      Throws:
      NullPointerException - if handler is null
    • doubleStateful

      @NotNull public static @NotNull Runnable doubleStateful(double initialState, @NonNull @NonNull DoubleUnaryOperator handler)
      Creates a stateful runnable which stores its state immutably.
      Parameters:
      initialState - initial state of the created runnable
      handler - handler invoked on each call to Runnable.run() with the state applied to it providing the new state
      Returns:
      created stateful runnable
      Throws:
      NullPointerException - if handler is null