Class CollectionUtils
-
- All Implemented Interfaces:
public class CollectionUtilsUtility class to work with collections, inspired by Javascript array methods
-
-
Constructor Summary
Constructors Constructor Description CollectionUtils()
-
Method Summary
Modifier and Type Method Description static <E> booleansome(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)Check whether any element of the collection passes the filter static <E> booleanevery(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)Check whether all elements of the collection pass the filter static <E> Efind(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)Find the first element which passes the filter static <E> EfindLast(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)Find the last element which passes the filter static <E> intfindIndex(@NonNull() List<E> list, @NonNull() Function1<E, Boolean> filter)Find the index of the first element which passes the filter static <E> intfindLastIndex(@NonNull() List<E> list, @NonNull() Function1<E, Boolean> filter)Find the index of the last element which passes the filter static <E> List<E>filter(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)Returns a new Array containing only the elements which passed the filter static <E, R> List<R>map(@NonNull() Collection<E> collection, @NonNull() Function1<E, R> transform)Returns a new Array containing the results of the transform function for all elements static <E> booleanremoveIf(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)Removes all elements from the collection which pass the filter static <E> Pair<List<E>, List<E>>partition(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)Partition the collection into two Arrays. static <E> List<E>splice(List<E> list, int start)Removes all elements after the specified start index static <E> List<E>splice(List<E> list, int start, int deleteCount, Array<E> items)Removes the specified amount of elements after the specified start index and inserts the specified items -
-
Method Detail
-
some
static <E> boolean some(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)
Check whether any element of the collection passes the filter
- Returns:
True if condition is true for any element in the collection
-
every
static <E> boolean every(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)
Check whether all elements of the collection pass the filter
- Returns:
True if condition is true for all elements in the collection
-
find
@Nullable() static <E> E find(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)
Find the first element which passes the filter
- Returns:
Element if found, otherwise null
-
findLast
@Nullable() static <E> E findLast(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)
Find the last element which passes the filter
- Returns:
Element if found, otherwise null
-
findIndex
static <E> int findIndex(@NonNull() List<E> list, @NonNull() Function1<E, Boolean> filter)
Find the index of the first element which passes the filter
- Returns:
Index if found, otherwise -1
-
findLastIndex
static <E> int findLastIndex(@NonNull() List<E> list, @NonNull() Function1<E, Boolean> filter)
Find the index of the last element which passes the filter
- Returns:
Index if found, otherwise -1
-
filter
@NonNull() static <E> List<E> filter(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)
Returns a new Array containing only the elements which passed the filter
- Returns:
Filtered Collection
-
map
@NonNull() static <E, R> List<R> map(@NonNull() Collection<E> collection, @NonNull() Function1<E, R> transform)
Returns a new Array containing the results of the transform function for all elements
- Returns:
Filtered Collection
-
removeIf
static <E> boolean removeIf(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)
Removes all elements from the collection which pass the filter
- Returns:
Whether an element was removed
-
partition
static <E> Pair<List<E>, List<E>> partition(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)
Partition the collection into two Arrays. The first array has all elements which passed the filter, the second one has the rest
- Returns:
A Pair containing the two arrays
-
splice
static <E> List<E> splice(List<E> list, int start)
Removes all elements after the specified start index
- Returns:
The removed elements
-
splice
@SafeVarargs() static <E> List<E> splice(List<E> list, int start, int deleteCount, Array<E> items)
Removes the specified amount of elements after the specified start index and inserts the specified items
- Parameters:
list- The list of splicestart- The start indexdeleteCount- The amount of items to removeitems- The items to insert- Returns:
The removed elements
-
-
-
-