Package software.amazon.awssdk.utils
Class CollectionUtils
java.lang.Object
software.amazon.awssdk.utils.CollectionUtils
-
Method Summary
Modifier and TypeMethodDescriptiondeepCopyMap
(Map<T, ? extends List<U>> map) Perform a deep copy of the provided map of lists.Perform a deep copy of the provided map of lists.deepUnmodifiableMap
(Map<T, ? extends List<U>> map) Perform a deep copy of the provided map of lists, and make the result unmodifiable.Perform a deep copy of the provided map of lists, and make the result unmodifiable.static <K,
V> Map <K, V> Filters a map based on a conditionstatic <T> T
firstIfPresent
(List<T> list) static <K,
V> Map <K, V> inverseMap
(Map<V, K> inputMap) Return a new map that is the inverse of the supplied map, with the values becoming the keys and vice versa.static boolean
isNotEmpty
(Map<?, ?> map) static boolean
isNullOrEmpty
(Collection<?> collection) static boolean
isNullOrEmpty
(Map<?, ?> map) static <K,
VInT, VOutT>
Map<K, VOutT> Transforms the values of a map to another map with the same keys, using the supplied function.static <T> List
<T> mergeLists
(List<T> list1, List<T> list2) Returns a new list containing the second list appended to the first list.toMap()
static <K,
V> Map <K, V> uniqueIndex
(Iterable<V> values, Function<? super V, K> indexFunction) For a collection of values of typeV
that can all be converted to typeK
, create a map that indexes all of the values byK
.unmodifiableMapOfLists
(Map<T, List<U>> map)
-
Method Details
-
isNullOrEmpty
-
isNullOrEmpty
-
isNotEmpty
-
mergeLists
Returns a new list containing the second list appended to the first list. -
firstIfPresent
- Type Parameters:
T
- Type of elements in the list.- Parameters:
list
- List to get first element from.- Returns:
- The first element in the list if it exists. If the list is null or empty this will return null.
-
deepCopyMap
Perform a deep copy of the provided map of lists. This only performs a deep copy of the map and lists. Entries are not copied, so care should be taken to ensure that entries are immutable if preventing unwanted mutations of the elements is desired. -
deepCopyMap
public static <T,U> Map<T,List<U>> deepCopyMap(Map<T, ? extends List<U>> map, Supplier<Map<T, List<U>>> mapConstructor) Perform a deep copy of the provided map of lists. This only performs a deep copy of the map and lists. Entries are not copied, so care should be taken to ensure that entries are immutable if preventing unwanted mutations of the elements is desired. -
unmodifiableMapOfLists
-
deepUnmodifiableMap
Perform a deep copy of the provided map of lists, and make the result unmodifiable. This is equivalent to callingdeepCopyMap(java.util.Map<T, ? extends java.util.List<U>>)
followed byunmodifiableMapOfLists(java.util.Map<T, java.util.List<U>>)
. -
deepUnmodifiableMap
public static <T,U> Map<T,List<U>> deepUnmodifiableMap(Map<T, ? extends List<U>> map, Supplier<Map<T, List<U>>> mapConstructor) Perform a deep copy of the provided map of lists, and make the result unmodifiable. This is equivalent to callingdeepCopyMap(java.util.Map<T, ? extends java.util.List<U>>)
followed byunmodifiableMapOfLists(java.util.Map<T, java.util.List<U>>)
. -
toMap
- Type Parameters:
K
- the key typeV
- the value type- Returns:
- a map
-
mapValues
public static <K,VInT, Map<K,VOutT> VOutT> mapValues(Map<K, VInT> inputMap, Function<VInT, VOutT> mapper) Transforms the values of a map to another map with the same keys, using the supplied function.- Type Parameters:
K
- the key typeVInT
- the value type for the input mapVOutT
- the value type for the output map- Parameters:
inputMap
- the input mapmapper
- the function used to transform the map values- Returns:
- a map
-
filterMap
Filters a map based on a condition- Type Parameters:
K
- the key typeV
- the value type- Parameters:
map
- the input mapcondition
- the predicate to filter on- Returns:
- the filtered map
-
inverseMap
Return a new map that is the inverse of the supplied map, with the values becoming the keys and vice versa. Requires the values to be unique.- Type Parameters:
K
- the key typeV
- the value type- Parameters:
inputMap
- a map where both the keys and values are unique- Returns:
- a map
-
uniqueIndex
For a collection of values of typeV
that can all be converted to typeK
, create a map that indexes all of the values byK
. This requires that no two values map to the same index.- Type Parameters:
K
- the index (or key) typeV
- the value type- Parameters:
values
- the collection of values to indexindexFunction
- the function used to convert a value to its index- Returns:
- a (modifiable) map that indexes K to its unique value V
- Throws:
IllegalArgumentException
- if any of the values map to the same index
-