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 <T> Collection<T> |
nullToEmpty(Collection<T> collection)
Returns an empty Collection if argument is null.
|
static <C> void |
objectToDataCollection(Collection<C> objectCollection,
Collection<Data> dataCollection,
SerializationService serializationService,
String errorMessage)
Converts a collection of any type to a collection of
Data . |
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)
Creates a new list if no list is found for the key.
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 null
public static <C> Collection<Data> objectToDataCollection(Collection<C> collection, SerializationService serializationService)
Data
.collection
- the given collectionserializationService
- will be used for converting object to Data
NullPointerException
- if collection is null
or contains a null
itempublic static <C> void objectToDataCollection(Collection<C> objectCollection, Collection<Data> dataCollection, SerializationService serializationService, String errorMessage)
Data
.objectCollection
- object itemsdataCollection
- data itemsserializationService
- will be used for converting object to Data
errorMessage
- the errorMessage when an item is nullNullPointerException
- 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 null
public static long[] toLongArray(Collection<Long> collection)
Collection
to a primitive long[]
array.collection
- the given collectionNullPointerException
- if collection is null
public 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.public static <T> Collection<T> nullToEmpty(Collection<T> collection)
Copyright © 2018 Hazelcast, Inc.. All rights reserved.