public final class CollectionUtil extends Object
Modifier and Type | Method and Description |
---|---|
static <K,V> void |
addListMap(Map<K,List<V>> map,
K key,
V val)
Adds an element to a map of lists.
|
static <T> void |
clearListMap(Map<?,List<T>> map)
Clears all lists in a map of lists
|
static byte[] |
concat(byte[] array1,
byte[] array2)
Concatenates two byte arrays into a single array
|
static <T> List<T> |
concat(List<T> list1,
List<T> list2)
Concatenates two lists into a single list.
|
static <T> T[] |
concat(T[] array1,
T[] array2,
Class<T> componentType)
Concatenates two arrays into a single array.
|
static <T> List<T> |
concatAsList(Collection<T> collection1,
Collection<T> collection2)
Concatenates two collections and returns the result as a list.
|
static <T> List<T> |
copy(List<T> list)
Creates a copy containing the elements of the given list.
|
static <K,V> Map<K,V> |
firstValueMap(Map<K,List<V>> map)
Returns a map whose keys equal the keys of the given map and whose values equal
the first value of each entry in the map.
|
static <K,V> List<V> |
getListMap(Map<K,List<V>> map,
K key)
Returns a list from a map of lists or empty list if the element does not exist.
|
static boolean |
hasNulls(Collection<?> values)
Tests whether or not the provided collection contains null values
|
static boolean |
hasNullValues(Map<String,String> map)
Tests whether or not the provided map contains null values
|
static <T> List<T> |
newArrayList()
Syntactic sugar for ArrayList creation; avoids generic parameters on RHS.
|
static <T> List<T> |
newArrayList(int capacity)
Syntactic sugar for ArrayList creation; avoids generic parameters on RHS.
|
static <K,V> Map<K,V> |
newHashMap()
Syntactic sugar for HashMap creation; avoids generic parameters on RHS.
|
static <K,V> Map<K,V> |
newHashMap(int capacity)
Syntactic sugar for HashMap creation; avoids generic parameters on RHS.
|
static <T> Set<T> |
newHashSet()
Syntactic sugar for HashSet creation; avoids generic parameters on RHS.
|
static <T> Set<T> |
newHashSet(int capacity)
Syntactic sugar for HashSet creation; avoids generic parameters on RHS.
|
static <K,V> Map<K,V> |
newIdentityHashMap()
Syntactic sugar for IdentityHashMap creation; avoids generic parameters on RHS.
|
static <K,V> Map<K,V> |
newIdentityHashMap(int capacity)
Syntactic sugar for IdentityHashMap creation; avoids generic parameters on RHS.
|
static <K,V> Map<K,V> |
newLinkedHashMap()
Syntactic sugar for LinkedHashMap creation; avoids generic parameters on RHS.
|
static <K,V> Map<K,V> |
newLinkedHashMap(int capacity)
Syntactic sugar for LinkedHashMap creation; avoids generic parameters on RHS.
|
static <T> Set<T> |
newLinkedHashSet()
Syntactic sugar for LinkedHashSet creation; avoids generic parameters on RHS.
|
static <T> Set<T> |
newLinkedHashSet(int capacity)
Syntactic sugar for LinkedHashSet creation; avoids generic parameters on RHS.
|
static <K,V> SortedMap<K,V> |
newTreeMap()
Syntactic sugar for TreeMap creation; avoids generic parameters on RHS.
|
static <T> T[] |
prepend(T[] base,
T element,
Class<T> clazz)
Adds the given element to the start of the array, returning the new array
|
static <T> T[] |
removeFirst(T[] base,
Class<T> clazz)
Removes the first element of the array, returning the new array
|
static <T> List<T> |
substract(List<T> list1,
List<T> list2)
Computes a new list containing all of the elements of
the first list, that are not in the second list.
|
static <T> List<T> |
substractAsList(Collection<T> collection1,
Collection<T> collection2)
Computes a list containing all of the elements of
the first collection, that are not in the second collection.
|
static <T> T[] |
toArray(Collection<? extends T> collection,
Class<T> componentType)
Syntactic sugar for converting a collection to an array of
a given component type.
|
static int[] |
toArray(List<Integer> vals)
Converts the list of integers into an array of ints
|
static <K,V> Map<K,List<V>> |
toMultiValueMap(Map<K,V> map)
Returns a map whose keys equal the keys in the given map and whose values
equal singleton lists consisting of the values in the map.
|
static boolean |
unique(Collection<?> values)
Tests whether or not the provided collection contains only distinct values
|
static <T> List<T> |
unmodCopy(List<T> list)
Creates an unmodifiable copy of the provided list
|
static <K,V> Map<K,V> |
unmodCopy(Map<K,V> map)
Creates an unmodifiable copy of the provided map
|
public static <T> List<T> newArrayList()
T
- the element typepublic static <T> List<T> newArrayList(int capacity)
T
- the element typecapacity
- initial capacity for the listpublic static <K,V> Map<K,V> newHashMap()
K
- the key typeV
- the value typepublic static <K,V> Map<K,V> newHashMap(int capacity)
K
- the key typeV
- the value typecapacity
- initial capacity for the mappublic static <T> Set<T> newHashSet()
T
- the element typepublic static <T> Set<T> newHashSet(int capacity)
T
- the element typecapacity
- initial capacity for the mappublic static <K,V> SortedMap<K,V> newTreeMap()
K
- the key typeV
- the value typepublic static <K,V> Map<K,V> newIdentityHashMap()
K
- the key typeV
- the value typepublic static <K,V> Map<K,V> newIdentityHashMap(int capacity)
K
- the key typeV
- the value typecapacity
- initial capacity for the mappublic static <K,V> Map<K,V> newLinkedHashMap()
K
- the key typeV
- the value typepublic static <K,V> Map<K,V> newLinkedHashMap(int capacity)
K
- the key typeV
- the value typecapacity
- initial capacity for the mappublic static <T> Set<T> newLinkedHashSet()
T
- the element typepublic static <T> Set<T> newLinkedHashSet(int capacity)
T
- the element typecapacity
- initial capacity for the mappublic static <T> T[] toArray(Collection<? extends T> collection, Class<T> componentType)
T
- the element typecollection
- The collection.componentType
- The component type of the arraypublic static <T> List<T> concat(List<T> list1, List<T> list2)
T
- the element typelist1
- the first listlist2
- the second listpublic static <T> List<T> concatAsList(Collection<T> collection1, Collection<T> collection2)
collection1
- the first collectioncollection2
- the second collectionpublic static <T> T[] concat(T[] array1, T[] array2, Class<T> componentType)
T
- the element typearray1
- the first arrayarray2
- the second arraycomponentType
- the class of elements in the resulting arraypublic static byte[] concat(byte[] array1, byte[] array2)
array1
- the first byte arrayarray2
- the second byte arraypublic static <T> T[] prepend(T[] base, T element, Class<T> clazz)
T
- the element typebase
- the initial arrayelement
- the element to prependclazz
- the type of the resulting arraypublic static <T> List<T> substract(List<T> list1, List<T> list2)
list1
- the first listlist2
- the second listpublic static <T> List<T> substractAsList(Collection<T> collection1, Collection<T> collection2)
collection1
- the first collectioncollection2
- the second collectionpublic static <T> List<T> copy(List<T> list)
list
- the list to be copiedpublic static <T> T[] removeFirst(T[] base, Class<T> clazz)
T
- the element typebase
- the initial arrayclazz
- the type of the resulting arraypublic static <T> void clearListMap(Map<?,List<T>> map)
T
- the type of listmap
- a map of listspublic static <K,V> void addListMap(Map<K,List<V>> map, K key, V val)
K
- the key typeV
- the value typemap
- the map of listskey
- the keyval
- the valuepublic static <K,V> Map<K,V> firstValueMap(Map<K,List<V>> map)
map
- the mappublic static <K,V> Map<K,List<V>> toMultiValueMap(Map<K,V> map)
map
- the original mappublic static <K,V> List<V> getListMap(Map<K,List<V>> map, K key)
K
- the key typeV
- the value typemap
- the map of listskey
- the keypublic static int[] toArray(List<Integer> vals)
vals
- the integersNullPointerException
- if the given list contains any null valuespublic static boolean unique(Collection<?> values)
values
- the collection to be testedpublic static boolean hasNulls(Collection<?> values)
values
- the collection to be testedpublic static boolean hasNullValues(Map<String,String> map)
values
- the map to be testedpublic static <T> List<T> unmodCopy(List<T> list)
list
- the list to be copiedCopyright © 2016 Actian Corporation. All rights reserved.