public final class CollectionUtils extends Object
Constructor and Description |
---|
CollectionUtils() |
Modifier and Type | Method and Description |
---|---|
static <T> List<T> |
addIfNotNull(List<T> l,
T o)
Add a value to a list if the value is not null.
|
static List<?> |
addReverse(List list,
List append)
Adds the contents of one list to the other in reverse order.
|
static List<?> |
addReverse(List list,
Object[] append)
Adds the contents of the array to the list in reverse order.
|
static <T> List<T> |
addToList(List<T> l,
Collection<T> val)
Copies the specified values into an existing list.
|
static <T> List<T> |
addToList(List<T> appendTo,
Object[] values,
Class<T> type,
Type... args)
Adds a set of values to an existing list.
|
static <K,V> Map<K,V> |
addToMap(Map<K,V> m,
K key,
V value)
Adds a single entry into an existing map.
|
static <K,V> Map<K,V> |
addToMap(Map<K,V> m,
Map<K,V> val)
Copies the specified values into an existing map.
|
static <K,V> Map<K,V> |
addToMap(Map<K,V> appendTo,
Object[] values,
Class<K> keyType,
Class<V> valueType,
Type... valueTypeArgs)
Adds a set of values to an existing map.
|
static <K,V> Map<K,V> |
addToSortedMap(Map<K,V> m,
K key,
V value,
Comparator<K> comparator)
Adds a single entry into an existing map.
|
static <K,V> Map<K,V> |
addToSortedMap(Map<K,V> m,
Map<K,V> val,
Comparator<K> comparator)
Copies the specified values into an existing map.
|
static <T> List<T> |
emptyList()
Simple passthrough to
Collections.emptyList() |
static <K,V> Map<K,V> |
emptyMap()
Simple passthrough to
Collections.emptyMap() |
static <T> Set<T> |
emptySet()
Simple passthrough to
Collections.emptySet() |
static <T> List<T> |
immutableList(Collection<T> l)
Creates an immutable list from the specified collection.
|
static <T> List<T> |
immutableList(T[] l)
Creates an immutable list from the specified array.
|
static <K,V> Map<K,V> |
immutableMap(Map<K,V> m)
Creates an immutable map from the specified map.
|
static <T> Iterable<T> |
iterable(Collection<T> c,
boolean reverse)
Returns an iterable over the specified collection.
|
static <E> Iterable<E> |
iterable(Enumeration<E> e)
Returns an iterable over the specified enumeration.
|
static <T> Iterable<T> |
iterable(List<T> c,
boolean reverse)
Returns an iterable over the specified list.
|
static <T> Iterable<T> |
iterable(T[] c,
boolean reverse)
Returns an iterable over the specified array.
|
static <T> Set<T> |
newHashSet(T... values)
Converts the specified arguments into a modifiable
HashSet . |
static <T> Set<T> |
newLinkedHashSet(T... values)
Converts the specified arguments into a modifiable
LinkedHashSet . |
static <T> List<T> |
newList(Collection<T> val)
Creates a new list from the specified collection.
|
static <K,V> Map<K,V> |
newMap(Map<K,V> val)
Creates a new map from the specified map.
|
static Set<String> |
newSortedCaseInsensitiveSet(String... values)
Creates a case-insensitive ordered set out of the specified string values.
|
static Set<String> |
newSortedCaseInsensitiveSet(String values)
Creates a case-insensitive ordered set out of the specified string values.
|
static <K,V> Map<K,V> |
newSortedMap(Map<K,V> val,
Comparator<K> comparator)
Creates a new map from the specified map.
|
static <T> Set<T> |
newUnmodifiableHashSet(T... values)
Converts the specified arguments into an unmodifiable
HashSet . |
static <T> Set<T> |
newUnmodifiableLinkedHashSet(T... values)
Converts the specified arguments into an unmodifiable
LinkedHashSet . |
static Set<String> |
newUnmodifiableSortedCaseInsensitiveSet(String values)
Same as
newSortedCaseInsensitiveSet(String) but makes the set unmodifiable. |
static <T> Iterable<T> |
reverseIterable(List<T> c)
Returns a reverse iterable over the specified list.
|
static <T> Iterable<T> |
reverseIterable(T[] c)
Returns a reverse iterable over the specified array.
|
static <T> List<T> |
unmodifiableList(List<T> l)
Creates an unmodifiable list from the specified list.
|
static <T> List<T> |
unmodifiableList(T[] l)
Creates an unmodifiable list from the specified array.
|
static <K,V> Map<K,V> |
unmodifiableMap(Map<K,V> m)
Creates an unmodifiable map from the specified map.
|
public CollectionUtils()
public static <T> List<T> addIfNotNull(List<T> l, T o)
l
- The list to add to.o
- The element to add.public static List<?> addReverse(List list, List append)
i.e. add values from 2nd list from end-to-start order to the end of the 1st list.
list
- The list to append to.append
- Contains the values to append to the list.public static List<?> addReverse(List list, Object[] append)
i.e. add values from the array from end-to-start order to the end of the list.
list
- The list to append to.append
- Contains the values to append to the list.public static <T> Iterable<T> iterable(Collection<T> c, boolean reverse)
c
- The collection to iterate over.reverse
- If public static <T> Iterable<T> iterable(List<T> c, boolean reverse)
c
- The collection to iterate over.reverse
- If public static <T> Iterable<T> reverseIterable(List<T> c)
c
- The collection to iterate over.public static <T> Iterable<T> iterable(T[] c, boolean reverse)
c
- The collection to iterate over.reverse
- If public static <T> Iterable<T> reverseIterable(T[] c)
c
- The collection to iterate over.public static <E> Iterable<E> iterable(Enumeration<E> e)
e
- The collection to iterate over.public static <T> List<T> unmodifiableList(List<T> l)
l
- The collection to copy from.Collections.emptyList()
if the list was empty or public static <T> List<T> unmodifiableList(T[] l)
l
- The collection to copy from.Collections.emptyList()
if the list was empty or public static <T> List<T> immutableList(Collection<T> l)
l
- The collection to copy from.ArrayList
copy of the collection, or a Collections.emptyList()
if the collection was empty or public static <T> List<T> immutableList(T[] l)
l
- The array to copy from.ArrayList
copy of the collection, or a Collections.emptyList()
if the collection was empty or public static <K,V> Map<K,V> immutableMap(Map<K,V> m)
m
- The map to copy from.LinkedHashMap
copy of the collection, or a Collections.emptyMap()
if the collection was empty or public static <K,V> Map<K,V> unmodifiableMap(Map<K,V> m)
m
- The map to copy from.Collections.emptyMap()
if the collection was empty or public static <T> List<T> addToList(List<T> appendTo, Object[] values, Class<T> type, Type... args)
appendTo
- The list to append to.
ArrayList
will be created.values
- The values to add.type
- The data type of the elements.args
- The generic type arguments of the data type.public static <K,V> Map<K,V> addToMap(Map<K,V> appendTo, Object[] values, Class<K> keyType, Class<V> valueType, Type... valueTypeArgs)
appendTo
- The map to append to.
LinkedHashMap
will be created.values
- The values to add.keyType
- The data type of the keys.valueType
- The data type of the values.valueTypeArgs
- The generic type arguments of the data type of the values.public static <T> List<T> newList(Collection<T> val)
val
- The value to copy from.ArrayList
, or public static <T> List<T> addToList(List<T> l, Collection<T> val)
l
- The list to add to.
ArrayList
will be created.val
- The values to add.public static <K,V> Map<K,V> newMap(Map<K,V> val)
val
- The value to copy from.LinkedHashMap
, or public static <K,V> Map<K,V> addToMap(Map<K,V> m, Map<K,V> val)
m
- The map to add to.
LinkedHashMap
will be created.val
- The values to add.public static <K,V> Map<K,V> addToMap(Map<K,V> m, K key, V value)
m
- The map to add to.
LinkedHashMap
will be created.key
- The entry key.value
- The entry value.public static <K,V> Map<K,V> newSortedMap(Map<K,V> val, Comparator<K> comparator)
val
- The value to copy from.comparator
- The key comparator to use, or LinkedHashMap
, or public static Set<String> newSortedCaseInsensitiveSet(String... values)
values
- The values to populate the set with.public static Set<String> newSortedCaseInsensitiveSet(String values)
values
- A comma-delimited list of the values to populate the set with.public static Set<String> newUnmodifiableSortedCaseInsensitiveSet(String values)
newSortedCaseInsensitiveSet(String)
but makes the set unmodifiable.values
- A comma-delimited list of the values to populate the set with.public static <K,V> Map<K,V> addToSortedMap(Map<K,V> m, Map<K,V> val, Comparator<K> comparator)
m
- The map to add to.
LinkedHashMap
will be created.val
- The values to add.comparator
- The key comparator to use, or public static <K,V> Map<K,V> addToSortedMap(Map<K,V> m, K key, V value, Comparator<K> comparator)
m
- The map to add to.
LinkedHashMap
will be created.key
- The entry key.value
- The entry value.comparator
- The key comparator to use, or @SafeVarargs public static <T> Set<T> newUnmodifiableHashSet(T... values)
HashSet
.values
- The entries to populate the hashset with.HashSet
populated with the specified arguments.@SafeVarargs public static <T> Set<T> newHashSet(T... values)
HashSet
.values
- The entries to populate the hashset with.HashSet
populated with the specified arguments.@SafeVarargs public static <T> Set<T> newUnmodifiableLinkedHashSet(T... values)
LinkedHashSet
.values
- The entries to populate the hashset with.LinkedHashSet
populated with the specified arguments.@SafeVarargs public static <T> Set<T> newLinkedHashSet(T... values)
LinkedHashSet
.values
- The entries to populate the hashset with.LinkedHashSet
populated with the specified arguments.public static <T> Set<T> emptySet()
Collections.emptySet()
public static <T> List<T> emptyList()
Collections.emptyList()
public static <K,V> Map<K,V> emptyMap()
Collections.emptyMap()
Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.