public class CollectionUtils extends Object
| Constructor and Description |
|---|
CollectionUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T[] |
append(T[] array,
T elem)
Combines provided array and an element into a new array
|
static <E> List<List<E>> |
batches(List<E> list,
int batchSize) |
static <E> Stream<List<E>> |
batchesAsStream(List<E> list,
int batchSize) |
static <E> List<E> |
combine(List<E> one,
List<E> another)
|
static <K,V> HashMap<K,V> |
combine(Map<K,V> one,
Map<K,V> another)
|
static <K,V> HashMap<K,V> |
combine(Map<K,V> one,
Map<K,V> another,
BiFunction<V,V,V> merge)
|
static <T> T[] |
combine(T[] one,
T[] another)
Combines provided arrays into one
|
static Properties |
copy(Properties props)
Makes a copy of provided
Properties object |
static <T> List<T> |
createImmutableList(List<T> list) |
static <T> List<T> |
createImmutableList(T... elements) |
static <K,V> Map<K,V> |
createImmutableMap(Map<K,V> map) |
static <K,V> Map<K,V> |
createImmutableMap(Pair<K,V>... elements) |
static <T> Set<T> |
createImmutableSet(Set<T> set) |
static <T> Set<T> |
createImmutableSet(T... elements) |
static <T> Set<T> |
createSet(T... elements) |
static <E> List<E> |
diff(Collection<E> one,
Collection<E> another)
Returns difference b/w
one List of elements and another
NOTE: This is less optimal counterpart to diff(Collection, Collection), accepting List
as a holding collection to support duplicate elements use-cases |
static <E> Set<E> |
diffSet(Collection<E> one,
Set<E> another)
Returns difference b/w
one Collection of elements and another
The elements in collection one are also duplicated and returned as a Set. |
static boolean |
elementsEqual(Iterator<?> iterator1,
Iterator<?> iterator2)
Determines whether two iterators contain equal elements in the same order.
|
static Properties |
emptyProps()
Returns an empty
Properties instance. |
static boolean |
isNullOrEmpty(Collection<?> c) |
static boolean |
isNullOrEmpty(Map<?,?> m) |
static boolean |
nonEmpty(Collection<?> c) |
static <T,U> U |
reduce(Collection<T> c,
U identity,
BiFunction<U,T,U> reducer)
Reduces provided
Collection using provided reducer applied to
every element of the collection like following
reduce(reduce(reduce(identity, e1), e2), ...) |
static <T> T |
tail(T[] ts)
Returns last element of the array of
T |
static <T> Stream<T> |
toStream(Iterator<T> iterator)
|
static <K,V> Map<K,V> |
zipToMap(List<K> keys,
List<V> values)
Zip two lists into a Map.
|
public static Properties emptyProps()
Properties instance. The props instance is a singleton,
it should not be modified in any case.public static boolean isNullOrEmpty(Collection<?> c)
public static boolean isNullOrEmpty(Map<?,?> m)
public static boolean nonEmpty(Collection<?> c)
public static <T,U> U reduce(Collection<T> c, U identity, BiFunction<U,T,U> reducer)
Collection using provided reducer applied to
every element of the collection like following
reduce(reduce(reduce(identity, e1), e2), ...)c - target collection to be reducedidentity - element for reducing to start fromreducer - actual reducing operatorpublic static Properties copy(Properties props)
Properties objectpublic static <T> T tail(T[] ts)
Tpublic static <T> T[] combine(T[] one,
T[] another)
public static <T> T[] append(T[] array,
T elem)
public static <K,V> HashMap<K,V> combine(Map<K,V> one, Map<K,V> another, BiFunction<V,V,V> merge)
public static <K,V> Map<K,V> zipToMap(List<K> keys, List<V> values)
public static <E> Set<E> diffSet(Collection<E> one, Set<E> another)
one Collection of elements and another
The elements in collection one are also duplicated and returned as a Set.public static <E> List<E> diff(Collection<E> one, Collection<E> another)
one List of elements and another
NOTE: This is less optimal counterpart to diff(Collection, Collection), accepting List
as a holding collection to support duplicate elements use-casespublic static boolean elementsEqual(Iterator<?> iterator1, Iterator<?> iterator2)
true if iterator1 and iterator2 contain the same
number of elements and every element of iterator1 is equal to the corresponding element
of iterator2.
Note that this will modify the supplied iterators, since they will have been advanced some number of elements forward.
@SafeVarargs public static <T> List<T> createImmutableList(T... elements)
@SafeVarargs public static <K,V> Map<K,V> createImmutableMap(Pair<K,V>... elements)
@SafeVarargs public static <T> Set<T> createSet(T... elements)
@SafeVarargs public static <T> Set<T> createImmutableSet(T... elements)
Copyright © 2024 The Apache Software Foundation. All rights reserved.