Class CollectionHelper
java.lang.Object
io.github.torand.javacommons.collection.CollectionHelper
Helper functions for collections
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T> Creates a list of specified iterable items.static <T> List<T> asList(T... items) Creates a list of specified item array.static <T> List<T> asNonEmptyList(T first, T... others) Creates a list of at least one, possibly multiple items.static <T> List<T> Concatenates the specified iterables into a single list.static <T> List<T> Concatenates the elements of the specified iterable and array into a single list.static <T> booleancontainsAny(Iterable<T> iterable, Predicate<T> predicate) Tests whether the specified iterable contains an element satisfying a predicate.static <T> booleancontainsOneOf(Iterable<T> iterable, T... items) Tests whether the specified iterable contains one of the specified items.static <T> TReturns the first element of the specified iterable.static booleanisEmpty(Collection<?> collection) Returns whether the specified collection is null or contains no elements.static booleanReturns whether the specified map is null or contains no elements.static booleannonEmpty(Collection<?> collection) Returns whether the specified collection contains at least one element.static booleanReturns whether the specified map contains at least one element.static <T> List<T> reverse(Collection<T> collection) Returns a new list with elements of specified collection in reversed order.static <T> TReturns the last element of the specified iterable.
-
Method Details
-
asList
Creates a list of specified iterable items.- Type Parameters:
T- the item type.- Parameters:
items- the item iterable.- Returns:
- the list.
-
asList
Creates a list of specified item array.- Type Parameters:
T- the item type.- Parameters:
items- the item array.- Returns:
- the list.
-
asNonEmptyList
Creates a list of at least one, possibly multiple items.- Type Parameters:
T- the item type.- Parameters:
first- the first item, which cannot be null.others- the additional items, which can be null or empty.- Returns:
- the list.
-
isEmpty
Returns whether the specified collection is null or contains no elements.- Parameters:
collection- the collection.- Returns:
- true if the collection is null or contains no elements; else false.
-
isEmpty
Returns whether the specified map is null or contains no elements.- Parameters:
map- the map.- Returns:
- true if the map is null or contains no elements; else false.
-
nonEmpty
Returns whether the specified collection contains at least one element.- Parameters:
collection- the collection.- Returns:
- true if the collection contains at least one element; else false.
-
nonEmpty
Returns whether the specified map contains at least one element.- Parameters:
map- the map.- Returns:
- true if the map contains at least one element; else false.
-
concat
Concatenates the specified iterables into a single list.- Type Parameters:
T- the element type.- Parameters:
first- the first iterable.second- the second iterable.- Returns:
- the list.
-
concat
Concatenates the elements of the specified iterable and array into a single list.- Type Parameters:
T- the element type.- Parameters:
first- the iterable.second- the array.- Returns:
- the list.
-
headOf
Returns the first element of the specified iterable.- Type Parameters:
T- the element type.- Parameters:
iterable- the iterable.- Returns:
- the first element of the iterable.
-
tailOf
Returns the last element of the specified iterable.- Type Parameters:
T- the element type.- Parameters:
iterable- the iterable.- Returns:
- the lastelement of the iterable.
-
containsAny
Tests whether the specified iterable contains an element satisfying a predicate.- Type Parameters:
T- the element type.- Parameters:
iterable- the iterable.predicate- the predicate.- Returns:
- true if the iterable contains an element satisfying the predicate; else false.
-
containsOneOf
Tests whether the specified iterable contains one of the specified items.- Type Parameters:
T- the element type.- Parameters:
iterable- the iterable.items- the items to look for.- Returns:
- true if the iterable contains one of the specified items; else false.
-
reverse
Returns a new list with elements of specified collection in reversed order.- Type Parameters:
T- the element type.- Parameters:
collection- the collection- Returns:
- the reversed list.
-