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 void |
assertTypes(List<Object> l,
Class<?>... c)
Asserts that all entries in the list are either instances or subclasses of at least one of the specified classes.
|
static List<Object> |
collapse(List<Object> l,
Object... o)
Same as
collapse(Object...) but allows you to supply your own list to append to. |
static List<Object> |
collapse(Object... o)
Collapses a collection of individual objects, arrays, and collections into a single list of objects.
|
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> List<T> |
reverse(List<T> l)
Same as
Collections.reverse(List) , but returns the list. |
static <K,V> LinkedHashMap<K,V> |
reverse(Map<K,V> in)
Reverses the order of a
LinkedHashMap . |
static <T> List<T> |
reverseCopy(List<T> l)
Creates a new copy of a list in reverse order.
|
static <T> Iterable<T> |
reverseIterable(Collection<T> c)
Returns a reverse iterable of the specified collection.
|
static <T> List<T> |
unmodifiableList(List<T> l)
Creates an unmodifiable list from the specified collection.
|
static <K,V> Map<K,V> |
unmodifiableMap(Map<K,V> m)
Creates an unmodifiable map from the specified map.
|
public CollectionUtils()
public static <K,V> LinkedHashMap<K,V> reverse(Map<K,V> in)
LinkedHashMap
.in
- The map to reverse the order on.LinkedHashMap
with keys in reverse order.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> reverseIterable(Collection<T> c)
c
- The collection to iterate over.public static <T> List<T> reverse(List<T> l)
Collections.reverse(List)
, but returns the list.l
- The list being reversedpublic static <T> List<T> reverseCopy(List<T> l)
l
- The old list.public static List<Object> collapse(Object... o)
o
- The collection of objects to collapse.public static List<Object> collapse(List<Object> l, Object... o)
collapse(Object...)
but allows you to supply your own list to append to.l
- The list to append to.o
- The collection of objects to collapse.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> unmodifiableList(List<T> l)
l
- The collection to copy from.Collections.emptyList()
if the list 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 void assertTypes(List<Object> l, Class<?>... c)
l
- The list to check.c
- The valid classes.Copyright © 2018 Apache. All rights reserved.