Class CollectionUtils
-
- All Implemented Interfaces:
public class CollectionUtils
Utility 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> boolean
some(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)
Check whether any element of the collection passes the filter static <E> boolean
every(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)
Check whether all elements of the collection pass the filter static <E> E
find(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)
Find the first element which passes the filter static <E> E
findLast(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)
Find the last element which passes the filter static <E> int
findIndex(@NonNull() List<E> list, @NonNull() Function1<E, Boolean> filter)
Find the index of the first element which passes the filter static <E> int
findLastIndex(@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> boolean
removeIf(@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
-
every
static <E> boolean every(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)
Check whether all elements of the collection pass the filter
-
find
@Nullable() static <E> E find(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)
Find the first element which passes the filter
-
findLast
@Nullable() static <E> E findLast(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)
Find the last element which passes the filter
-
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
-
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
-
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
-
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
-
removeIf
static <E> boolean removeIf(@NonNull() Collection<E> collection, @NonNull() Function1<E, Boolean> filter)
Removes all elements from the collection which pass the filter
-
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
-
splice
static <E> List<E> splice(List<E> list, int start)
Removes all elements after the specified start index
-
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
-
-
-
-