public class FunctionalUtils extends Object
| Constructor and Description |
|---|
FunctionalUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <K,V> V |
computeIfAbsent(Map<K,V> map,
K key,
Function<K,V> mappingFunction)
Use this method instead if
Map.computeIfAbsent(Object, Function) when the mapping functions are recursive and/or
will end up accessing the same map again. |
static <T> void |
ifPresent(Optional<T> optional,
Consumer<? super T> ifPresent,
Runnable orElse)
If the
optional is present, it executes the ifPresent consumer. |
static <T> Optional<T> |
or(Optional<T> optional,
Supplier<Optional<T>> orElse)
If the given
optional is not present, then it returns the optional
provided by the orElse supplier |
public static <K,V> V computeIfAbsent(Map<K,V> map, K key, Function<K,V> mappingFunction)
Map.computeIfAbsent(Object, Function) when the mapping functions are recursive and/or
will end up accessing the same map again. This is necessary because starting with JDK9
Map.computeIfAbsent(Object, Function) throws ConcurrentModificationException if used in concurrent,
recursive, or nested fashion.public static <T> Optional<T> or(Optional<T> optional, Supplier<Optional<T>> orElse)
optional is not present, then it returns the optional
provided by the orElse supplierpublic static <T> void ifPresent(Optional<T> optional, Consumer<? super T> ifPresent, Runnable orElse)
optional is present, it executes the ifPresent consumer. Otherwise,
it executes the orElse runnableT - the generic type of the optional's value.optional - an Optional valueifPresent - the consumer to execute if the value is presentorElse - a fallback runnable in case the optional is empty.Copyright © 2021 MuleSoft, Inc.. All rights reserved.