public final class CollectionUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
anyHaveEntries(Object... containers)
See if any of the containers have entries and if so return true.
|
static Set |
asCaseInsensitiveHashSet(Object... values)
Collects the passed in objects into a case insensitive hash set.
|
static <T> List<T> |
asList(T... values)
Collects the passed in objects into a List.
|
static <T> LinkedHashSet<T> |
asOrderedSet(T... values)
Collects the passed in objects to a LinkedHashSet.
|
static <T> Set<T> |
asSet(T... values)
Collects the passed in objects into an unordered Set.
|
static boolean |
compareCaseInsensitiveMapOfSetOfStrings(Map<String,Set<String>> valA,
Map<String,Set<String>> valB)
Compares two map collections containing sets of strings in a case insensitive manner.
|
static int |
createHashForCaseInsensitiveMapOfSetOfStrings(Map<String,Set<String>> map)
Creates a hash code for a map of set of strings in a case insensitive manner.
|
static <T> boolean |
genericCompare(T valA,
T valB)
Compares any two arbitrary objects - including collections, for equality.
|
static <T> T |
getFirstItem(Collection<T> collection)
Retrieves the first item from a collection.
|
static <T> T |
getFirstItem(Collection<T> collection,
T defaultValue)
Retrieves the first item from a collections.
|
static <K,V> Map<V,K> |
invertMap(Map<K,V> map)
Creates a new Map which contains the entries of the provided map but with keys and values exchanged.
|
static boolean |
isEmpty(Collection<?> collection)
Determines whether the collections is null or empty.
|
static boolean |
isEmpty(Map<?,?> map)
Given a map determines whether it contains some values.
|
static boolean |
isNotEmpty(Collection<?> collection)
Given a collection determines whether it contains some values.
|
static boolean |
isNotEmpty(Map<?,?> map)
Given a map determines whether it contains some values.
|
static <T> List<T> |
newList(Collection<T> collection)
Returns an
ArrayList of the items in the provided collection, or null if the set is null. |
static Set<String> |
removeBlankEntries(Set<String> originalSet)
From the original Set of Strings, remove any entries that are blank.
|
static <K,V extends Comparable<? super V>> |
sortMapByValue(Map<K,V> map)
Sort the given Map by comparing it's values.
|
static Map<String,Set<String>> |
toAvPairMap(Set<String> names,
String value)
Creates a Hash Map, of names mapped to the provided value.
|
static <I,M,E extends Exception> |
transformList(Collection<I> values,
org.forgerock.util.Function<I,M,E> mapper)
Maps the non-null values from one type to another type using a non-null mapper function.
|
static <K,I,M,E extends Exception> |
transformMap(Map<K,I> map,
org.forgerock.util.Function<I,M,E> mapper)
Maps the values of a non-null map from one type to another type using a non-null mapper function.
|
static <I,M,E extends Exception> |
transformSet(Collection<I> values,
org.forgerock.util.Function<I,M,E> mapper)
Maps the non-null values from one type to another type using a non-null mapper function.
|
public static Set<String> removeBlankEntries(Set<String> originalSet)
originalSet - The Set of Strings to checkpublic static <T> List<T> asList(T... values)
T - The type of the passed in objects.values - An unbounded amount of objects that needs to be collected to a List.public static Set asCaseInsensitiveHashSet(Object... values)
values - An unbounded amount of objects that needs to be converted to a case insensitive hash set.public static <T> Set<T> asSet(T... values)
T - The type of the passed in objects.values - An unbounded amount of objects that needs to be converted to a Set.public static <T> LinkedHashSet<T> asOrderedSet(T... values)
T - The type of the passed in objects.values - An unbounded amount of objects that needs to be converted to a Set.public static <K,V> Map<V,K> invertMap(Map<K,V> map)
K - the type of keys in the provided map; the type of the values in the returned map.V - the type of values in the provided map; the type of the keys in the returned map.map - the non-null original map.public static <K,I,M,E extends Exception> Map<K,M> transformMap(Map<K,I> map, org.forgerock.util.Function<I,M,E> mapper) throws E extends Exception
K - the type of keyI - the type of the initial valueM - the type of the mapped valueE - the type of exception that the function may throwmap - the non-null original mapmapper - the non-null mapping functionE - should an exception occur during the mapping processE extends Exceptionpublic static <I,M,E extends Exception> List<M> transformList(Collection<I> values, org.forgerock.util.Function<I,M,E> mapper) throws E extends Exception
I - the type of the initial valueM - the type of the mapped valueE - the type of exception that the function may throwvalues - the non-null original valuesmapper - the non-null mapping functionE - should an exception occur during the mapping processE extends Exceptionpublic static <I,M,E extends Exception> Set<M> transformSet(Collection<I> values, org.forgerock.util.Function<I,M,E> mapper) throws E extends Exception
I - the type of the initial valueM - the type of the mapped valueE - the type of exception that the function may throwvalues - the non-null original valuesmapper - the non-null mapping functionE - should an exception occur during the mapping processE extends Exceptionpublic static <T> T getFirstItem(Collection<T> collection)
T - The type of the collection.collection - The collection.public static <T> T getFirstItem(Collection<T> collection, T defaultValue)
T - the type of the collectioncollection - the collectiondefaultValue - the default value should not initial value existpublic static <T> boolean genericCompare(T valA,
T valB)
T - The type of the objects being compared.valA - The first object to be compared.valB - The second object to tbe compared.public static boolean compareCaseInsensitiveMapOfSetOfStrings(Map<String,Set<String>> valA, Map<String,Set<String>> valB)
valA - - the first map of set of strings to be compared.valB - - the second map of set of strings to be compared.public static int createHashForCaseInsensitiveMapOfSetOfStrings(Map<String,Set<String>> map)
map - - the map of set of strings for which the hash code is to be generated.public static boolean isNotEmpty(Collection<?> collection)
collection - collection in questionpublic static boolean isEmpty(Collection<?> collection)
collection - the collectionpublic static Map<String,Set<String>> toAvPairMap(Set<String> names, String value)
names - The set of names to be associated with the provided value.value - The value to be mapped to each of the provided names.public static boolean isEmpty(Map<?,?> map)
map - map in questionpublic static boolean isNotEmpty(Map<?,?> map)
map - map in questionpublic static boolean anyHaveEntries(Object... containers)
Collection
or a Map is ignored.containers - a varied list of maps and collectionspublic static <K,V extends Comparable<? super V>> Map<K,V> sortMapByValue(Map<K,V> map)
K - The key type.V - The value type.map - The map to sort.LinkedHashMap to guarantee iteration order.public static <T> List<T> newList(Collection<T> collection)
ArrayList of the items in the provided collection, or null if the set is null.T - The type of value.collection - The collection.null if the collection was null.Copyright © 2010–2023 Open Identity Platform Community. All rights reserved.