java.lang.Object
net.luis.utils.function.FunctionUtils
Utility class for the functional interfaces in the
java.util.function
and net.luis.utils.function.throwable
packages.-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Private constructor to prevent instantiation.
This is a static helper class. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T,
U, R> @NotNull BiFunction <T, U, R> memorize
(@NotNull BiFunction<T, U, R> function) Memorizes the givenBiFunction
and returns a newBiFunction
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.static <T,
R> @NotNull Function <T, R> static <T> @NotNull Supplier
<T> static <T,
U, V, W, R>
@NotNull QuadFunction<T, U, V, W, R> memorize
(@NotNull QuadFunction<T, U, V, W, R> function) Memorizes the givenQuadFunction
and returns a newQuadFunction
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.static <T,
U, V, R>
@NotNull TriFunction<T, U, V, R> memorize
(@NotNull TriFunction<T, U, V, R> function) Memorizes the givenTriFunction
and returns a newTriFunction
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.static <T,
U, R, X extends Throwable>
@NotNull ThrowableBiFunction<T, U, R, X> memorizeThrowable
(@NotNull ThrowableBiFunction<T, U, R, X> function) Memorizes the givenThrowableBiFunction
and returns a newThrowableBiFunction
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.static <T,
R, X extends Throwable>
@NotNull ThrowableFunction<T, R, X> memorizeThrowable
(@NotNull ThrowableFunction<T, R, X> delegate) Memorizes the givenThrowableFunction
and returns a newThrowableFunction
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.static <T,
U, V, W, R, X extends Throwable>
@NotNull ThrowableQuadFunction<T, U, V, W, R, X> memorizeThrowable
(@NotNull ThrowableQuadFunction<T, U, V, W, R, X> function) Memorizes the givenThrowableQuadFunction
and returns a newThrowableQuadFunction
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.static <T,
X extends Throwable>
@NotNull ThrowableSupplier<T, X> memorizeThrowable
(@NotNull ThrowableSupplier<T, X> delegate) Memorizes the givenThrowableSupplier
and returns a newThrowableSupplier
that caches the result of the first call.static <T,
U, V, R, X extends Throwable>
@NotNull ThrowableTriFunction<T, U, V, R, X> memorizeThrowable
(@NotNull ThrowableTriFunction<T, U, V, R, X> function) Memorizes the givenThrowableTriFunction
and returns a newThrowableTriFunction
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.
-
Constructor Details
-
FunctionUtils
private FunctionUtils()Private constructor to prevent instantiation.
This is a static helper class.
-
-
Method Details
-
memorize
- 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 givenThrowableSupplier
and returns a newThrowableSupplier
that caches the result of the first call.- Type Parameters:
T
- The type of the resultX
- 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 givenFunction
and returns a newFunction
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 valueR
- 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, @NotNull ThrowableFunction<T,X extends Throwable> R, memorizeThrowableX> (@NotNull @NotNull ThrowableFunction<T, R, X> delegate) Memorizes the givenThrowableFunction
and returns a newThrowableFunction
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 valueR
- The type of the resultX
- 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, @NotNull BiFunction<T,R> U, memorizeR> (@NotNull @NotNull BiFunction<T, U, R> function) Memorizes the givenBiFunction
and returns a newBiFunction
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 valueU
- The type of the second input valueR
- 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, @NotNull ThrowableBiFunction<T,R, X extends Throwable> U, memorizeThrowableR, X> (@NotNull @NotNull ThrowableBiFunction<T, U, R, X> function) Memorizes the givenThrowableBiFunction
and returns a newThrowableBiFunction
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 valueU
- The type of the second input valueR
- The type of the resultX
- 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, @NotNull TriFunction<T,V, R> U, memorizeV, R> (@NotNull @NotNull TriFunction<T, U, V, R> function) Memorizes the givenTriFunction
and returns a newTriFunction
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 valueU
- The type of the second input valueV
- The type of the third input valueR
- 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, @NotNull ThrowableTriFunction<T,V, R, X extends Throwable> U, memorizeThrowableV, R, X> (@NotNull @NotNull ThrowableTriFunction<T, U, V, R, X> function) Memorizes the givenThrowableTriFunction
and returns a newThrowableTriFunction
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 valueU
- The type of the second input valueV
- The type of the third input valueR
- The type of the resultX
- 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, @NotNull QuadFunction<T,V, W, R> U, memorizeV, W, R> (@NotNull @NotNull QuadFunction<T, U, V, W, R> function) Memorizes the givenQuadFunction
and returns a newQuadFunction
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 valueU
- The type of the second input valueV
- The type of the third input valueW
- The type of the fourth input valueR
- 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, @NotNull ThrowableQuadFunction<T,V, W, R, X extends Throwable> U, memorizeThrowableV, W, R, X> (@NotNull @NotNull ThrowableQuadFunction<T, U, V, W, R, X> function) Memorizes the givenThrowableQuadFunction
and returns a newThrowableQuadFunction
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 valueU
- The type of the second input valueV
- The type of the third input valueW
- The type of the fourth input valueR
- The type of the resultX
- The type of the exception- Parameters:
function
- The delegate function to memorize- Returns:
- A new function that caches the result for each input
-