Package software.amazon.awssdk.utils
Class CollectionUtils
- java.lang.Object
-
- software.amazon.awssdk.utils.CollectionUtils
-
public final class CollectionUtils extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,U>
Map<T,List<U>>deepCopyMap(Map<T,? extends List<U>> map)
Perform a deep copy of the provided map of lists.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.static <T,U>
Map<T,List<U>>deepUnmodifiableMap(Map<T,? extends List<U>> map)
Perform a deep copy of the provided map of lists, and make the result unmodifiable.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.static <K,V>
Map<K,V>filterMap(Map<K,V> map, Predicate<Map.Entry<K,V>> condition)
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>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.static <T> List<T>
mergeLists(List<T> list1, List<T> list2)
Returns a new list containing the second list appended to the first list.static <K,V>
Collector<Map.Entry<K,V>,?,Map<K,V>>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
.static <T,U>
Map<T,List<U>>unmodifiableMapOfLists(Map<T,List<U>> map)
-
-
-
Method Detail
-
isNullOrEmpty
public static boolean isNullOrEmpty(Collection<?> collection)
-
isNullOrEmpty
public static boolean isNullOrEmpty(Map<?,?> map)
-
isNotEmpty
public static boolean isNotEmpty(Map<?,?> map)
-
mergeLists
public static <T> List<T> mergeLists(List<T> list1, List<T> list2)
Returns a new list containing the second list appended to the first list.
-
firstIfPresent
public static <T> T firstIfPresent(List<T> list)
- 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
public static <T,U> Map<T,List<U>> deepCopyMap(Map<T,? extends List<U>> map)
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
public static <T,U> Map<T,List<U>> unmodifiableMapOfLists(Map<T,List<U>> map)
-
deepUnmodifiableMap
public static <T,U> Map<T,List<U>> deepUnmodifiableMap(Map<T,? extends List<U>> map)
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
public static <K,V> Collector<Map.Entry<K,V>,?,Map<K,V>> toMap()
- Type Parameters:
K
- the key typeV
- the value type- Returns:
- a map
-
mapValues
public static <K,VInT,VOutT> Map<K,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
public static <K,V> Map<K,V> filterMap(Map<K,V> map, Predicate<Map.Entry<K,V>> condition)
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
public 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. 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
public 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
. 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
-
-