Class FunctionUtils

java.lang.Object
net.luis.utils.function.FunctionUtils

public final class FunctionUtils extends Object
Utility class for the functional interfaces in the java.util.function and net.luis.utils.function.throwable packages.
  • Constructor Details

    • FunctionUtils

      private FunctionUtils()
      Private constructor to prevent instantiation.
      This is a static helper class.
  • Method Details

    • memorize

      @NotNull public static <T> @NotNull Supplier<T> memorize(@NotNull @NotNull Supplier<T> delegate)
      Memorizes the given Supplier and returns a new Supplier that caches the result of the first call.
      Type Parameters:
      T - The type of the result
      Parameters:
      delegate - The delegate supplier to memorize
      Returns:
      A new supplier that caches the result of the first call
      Throws:
      NullPointerException - If the delegate supplier is null
    • memorizeThrowable

      @NotNull public static <T, X extends Throwable> @NotNull ThrowableSupplier<T,X> memorizeThrowable(@NotNull @NotNull ThrowableSupplier<T,X> delegate)
      Memorizes the given ThrowableSupplier and returns a new ThrowableSupplier that caches the result of the first call.
      Type Parameters:
      T - The type of the result
      X - The type of the exception
      Parameters:
      delegate - The delegate supplier to memorize
      Returns:
      A new supplier that caches the result of the first call
      Throws:
      NullPointerException - If the delegate supplier is null
    • memorize

      @NotNull public static <T, R> @NotNull Function<T,R> memorize(@NotNull @NotNull Function<T,R> delegate)
      Memorizes the given Function and returns a new Function that caches the result for each input.
      The cache is weakly referenced, so it will be cleared when the input is no longer reachable.
      Be aware that this may lead to memory leaks if the input is not properly managed.
      Type Parameters:
      T - The type of the input value
      R - The type of the result
      Parameters:
      delegate - The delegate function to memorize
      Returns:
      A new function that caches the result for each input
      Throws:
      NullPointerException - If the delegate function is null
    • memorizeThrowable

      @NotNull public static <T, R, X extends Throwable> @NotNull ThrowableFunction<T,R,X> memorizeThrowable(@NotNull @NotNull ThrowableFunction<T,R,X> delegate)
      Memorizes the given ThrowableFunction and returns a new ThrowableFunction that caches the result for each input.
      The cache is weakly referenced, so it will be cleared when the input is no longer reachable.
      Be aware that this may lead to memory leaks if the input is not properly managed.
      Type Parameters:
      T - The type of the input value
      R - The type of the result
      X - The type of the exception
      Parameters:
      delegate - The delegate function to memorize
      Returns:
      A new function that caches the result for each input
    • memorize

      @NotNull public static <T, U, R> @NotNull BiFunction<T,U,R> memorize(@NotNull @NotNull BiFunction<T,U,R> function)
      Memorizes the given BiFunction and returns a new BiFunction that caches the result for each input.
      The cache is weakly referenced, so it will be cleared when the input is no longer reachable.
      Be aware that this may lead to memory leaks if the input is not properly managed.
      Type Parameters:
      T - The type of the first input value
      U - The type of the second input value
      R - The type of the result
      Parameters:
      function - The delegate function to memorize
      Returns:
      A new function that caches the result for each input
    • memorizeThrowable

      @NotNull public static <T, U, R, X extends Throwable> @NotNull ThrowableBiFunction<T,U,R,X> memorizeThrowable(@NotNull @NotNull ThrowableBiFunction<T,U,R,X> function)
      Memorizes the given ThrowableBiFunction and returns a new ThrowableBiFunction that caches the result for each input.
      The cache is weakly referenced, so it will be cleared when the input is no longer reachable.
      Be aware that this may lead to memory leaks if the input is not properly managed.
      Type Parameters:
      T - The type of the first input value
      U - The type of the second input value
      R - The type of the result
      X - The type of the exception
      Parameters:
      function - The delegate function to memorize
      Returns:
      A new function that caches the result for each input
    • memorize

      @NotNull public static <T, U, V, R> @NotNull TriFunction<T,U,V,R> memorize(@NotNull @NotNull TriFunction<T,U,V,R> function)
      Memorizes the given TriFunction and returns a new TriFunction that caches the result for each input.
      The cache is weakly referenced, so it will be cleared when the input is no longer reachable.
      Be aware that this may lead to memory leaks if the input is not properly managed.
      Type Parameters:
      T - The type of the first input value
      U - The type of the second input value
      V - The type of the third input value
      R - The type of the result
      Parameters:
      function - The delegate function to memorize
      Returns:
      A new function that caches the result for each input
    • memorizeThrowable

      @NotNull public static <T, U, V, R, X extends Throwable> @NotNull ThrowableTriFunction<T,U,V,R,X> memorizeThrowable(@NotNull @NotNull ThrowableTriFunction<T,U,V,R,X> function)
      Memorizes the given ThrowableTriFunction and returns a new ThrowableTriFunction that caches the result for each input.
      The cache is weakly referenced, so it will be cleared when the input is no longer reachable.
      Be aware that this may lead to memory leaks if the input is not properly managed.
      Type Parameters:
      T - The type of the first input value
      U - The type of the second input value
      V - The type of the third input value
      R - The type of the result
      X - The type of the exception
      Parameters:
      function - The delegate function to memorize
      Returns:
      A new function that caches the result for each input
    • memorize

      @NotNull public static <T, U, V, W, R> @NotNull QuadFunction<T,U,V,W,R> memorize(@NotNull @NotNull QuadFunction<T,U,V,W,R> function)
      Memorizes the given QuadFunction and returns a new QuadFunction that caches the result for each input.
      The cache is weakly referenced, so it will be cleared when the input is no longer reachable.
      Be aware that this may lead to memory leaks if the input is not properly managed.
      Type Parameters:
      T - The type of the first input value
      U - The type of the second input value
      V - The type of the third input value
      W - The type of the fourth input value
      R - The type of the result
      Parameters:
      function - The delegate function to memorize
      Returns:
      A new function that caches the result for each input
    • memorizeThrowable

      @NotNull public static <T, U, V, W, R, X extends Throwable> @NotNull ThrowableQuadFunction<T,U,V,W,R,X> memorizeThrowable(@NotNull @NotNull ThrowableQuadFunction<T,U,V,W,R,X> function)
      Memorizes the given ThrowableQuadFunction and returns a new ThrowableQuadFunction that caches the result for each input.
      The cache is weakly referenced, so it will be cleared when the input is no longer reachable.
      Be aware that this may lead to memory leaks if the input is not properly managed.
      Type Parameters:
      T - The type of the first input value
      U - The type of the second input value
      V - The type of the third input value
      W - The type of the fourth input value
      R - The type of the result
      X - The type of the exception
      Parameters:
      function - The delegate function to memorize
      Returns:
      A new function that caches the result for each input