Package org.openl.util
Class CollectionUtils
java.lang.Object
org.openl.util.CollectionUtils
An util class for collections and arrays.
- Author:
- Yury Molchan
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDefines a functor interface implemented by classes that map one object into another.static interfaceDefines a functor interface implemented by classes that perform a predicate test on an object. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T> findAll(Iterable<T> col, CollectionUtils.Predicate<? super T> predicate) Selects all elements from input collection which match the given predicate into an output collection.static <T> TfindFirst(Iterable<T> col, CollectionUtils.Predicate<? super T> predicate) Finds the first element in the given collection which matches the given predicate.static <T> booleanhasNull(T[] array) Checks an array onnullvalue.static booleanisEmpty(Collection<?> col) Returntrueif a collection is null or is empty.static booleanReturntrueif a map is null or is empty.static <T> booleanisEmpty(T array) Returntrueif an array is null or is empty.static <T> booleanisEmpty(T[] array) Returntrueif an array is null or is empty.static booleanisNotEmpty(Collection<?> col) Returntrueif a collection contains at least one element.static booleanisNotEmpty(Map<?, ?> map) Returntrueif a map contains at least one element.static <T> booleanisNotEmpty(T array) Returntrueif an array contains at least one element.static <T> booleanisNotEmpty(T[] array) Returntrueif an array contains at least one element.static <I,O> List <O> map(Iterable<I> col, CollectionUtils.Mapper<? super I, ? extends O> mapper) Returns a new Collection consisting of the elements of the input collection transformed by the given transformer.static ObjecttoArray(Collection<?> list, Class<?> instanceClass)
-
Constructor Details
-
CollectionUtils
public CollectionUtils()
-
-
Method Details
-
isEmpty
Returntrueif a collection is null or is empty.- Parameters:
col- the checked collection.- Returns:
- return
trueif the collection does not contain any elements. - See Also:
-
isNotEmpty
Returntrueif a collection contains at least one element. This method is inverse toisEmpty(Collection).- Parameters:
col- the checked collection.- Returns:
trueif the collection contains at least one element.
-
isEmpty
Returntrueif a map is null or is empty.- Parameters:
map- the checked map.- Returns:
- return
trueif the map does not contain any elements. - See Also:
-
isNotEmpty
Returntrueif a map contains at least one element. This method is inverse toisEmpty(Map).- Parameters:
map- the checked map.- Returns:
trueif the map contains at least one element.
-
isEmpty
public static <T> boolean isEmpty(T[] array) Returntrueif an array is null or is empty.- Parameters:
array- the checked array.- Returns:
- return
trueif the array does not contain any elements.
-
isNotEmpty
public static <T> boolean isNotEmpty(T[] array) Returntrueif an array contains at least one element. This method is inverse to.invalid reference
#isEmpty(T[])- Parameters:
array- the checked array.- Returns:
trueif the array contains at least one element.
-
isEmpty
public static <T> boolean isEmpty(T array) Returntrueif an array is null or is empty.- Parameters:
array- the checked array.- Returns:
- return
trueif the array does not contain any elements. - Throws:
IllegalArgumentException- if the argument is not an array.- See Also:
-
isNotEmpty
public static <T> boolean isNotEmpty(T array) Returntrueif an array contains at least one element. This method is inverse to.invalid reference
#isEmpty(T[])- Parameters:
array- the checked array.- Returns:
trueif the array contains at least one element.- Throws:
IllegalArgumentException- if the argument is not an array.
-
map
public static <I,O> List<O> map(Iterable<I> col, CollectionUtils.Mapper<? super I, ? extends O> mapper) Returns a new Collection consisting of the elements of the input collection transformed by the given transformer.- Type Parameters:
I- the type of object in the input collection.O- the type of object in the output collection.- Parameters:
col- the collection to get the input from, may be null.mapper- the mapper to use.- Returns:
- the transformed result (new list).
- Throws:
NullPointerException- if the mapper is null.
-
findFirst
Finds the first element in the given collection which matches the given predicate.- Type Parameters:
T- the type of object theIterablecontains.- Parameters:
col- the collection to search, may be null.predicate- the predicate to use.- Returns:
- the first element of the collection which matches the predicate or null if none could be found.
- Throws:
NullPointerException- if the predicate is null.
-
findAll
Selects all elements from input collection which match the given predicate into an output collection.- Type Parameters:
T- the type of object theIterablecontains.- Parameters:
col- the collection to search, may be null.predicate- the predicate to use.- Returns:
- the all the elements of the collection which matches the predicate or [] if none could be found or null if the input collection is null.
- Throws:
NullPointerException- if the predicate is null.
-
hasNull
public static <T> boolean hasNull(T[] array) Checks an array onnullvalue.- Type Parameters:
T- the element type of checked array.- Parameters:
array- the checked array.- Returns:
trueif the array containsnull.
-
toArray
-