public final class CollectionUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static <K,V> List<V> |
addToValueList(Map<K,List<V>> map,
K key,
V value)
Adds a value to a list of values in the map.
|
static <T> T |
getItemAtPositionOrNull(Collection<T> collection,
int position)
Returns the n-th item or
null if collection is smaller. |
static boolean |
isEmpty(Collection collection)
Returns
true if the given collection is null or empty, otherwise returns false. |
static boolean |
isNotEmpty(Collection collection)
Returns
true if the given collection is not null and not empty, otherwise returns false. |
static <C> Collection<Data> |
objectToDataCollection(Collection<C> collection,
SerializationService serializationService)
Converts a collection of any type to a collection of
Data. |
static int[] |
toIntArray(Collection<Integer> collection)
Converts a
Collection to a primitive int[] array. |
static List<Integer> |
toIntegerList(int[] array)
Converts an int array to an Integer
List. |
static long[] |
toLongArray(Collection<Long> collection)
Converts a
Collection to a primitive long[] array. |
public static boolean isEmpty(Collection collection)
true if the given collection is null or empty, otherwise returns false.collection - the given collectiontrue if collection is emptypublic static boolean isNotEmpty(Collection collection)
true if the given collection is not null and not empty, otherwise returns false.collection - the given collectiontrue if collection is not emptypublic static <K,V> List<V> addToValueList(Map<K,List<V>> map, K key, V value)
map - the given map of listskey - the key of the target listvalue - the value to add to the target listpublic static <T> T getItemAtPositionOrNull(Collection<T> collection, int position)
null if collection is smaller.collection - the given collectionposition - position of the wanted itemnull if the given collection is too smallNullPointerException - if collection is nullpublic static <C> Collection<Data> objectToDataCollection(Collection<C> collection, SerializationService serializationService)
Data.collection - the given collectionserializationService - will be used for converting object to DataNullPointerException - if collection is null or contains a null itempublic static int[] toIntArray(Collection<Integer> collection)
Collection to a primitive int[] array.collection - the given collectionNullPointerException - if collection is nullpublic static long[] toLongArray(Collection<Long> collection)
Collection to a primitive long[] array.collection - the given collectionNullPointerException - if collection is nullpublic static List<Integer> toIntegerList(int[] array)
List.
The returned collection can be modified after it is created; it isn't protected by an immutable wrapper.array - the arrayNullPointerException if array is null.Copyright © 2017 Hazelcast, Inc.. All Rights Reserved.