public final class CollectionUtils extends Object
Collection implementations.| Modifier and Type | Method and Description |
|---|---|
static boolean |
addUnique(Collection<Boolean> collection,
boolean[] objects)
Adds all objects into the specified list.
|
static boolean |
addUnique(Collection<Byte> collection,
byte[] objects)
Adds all objects into the specified list.
|
static boolean |
addUnique(Collection<Character> collection,
char[] objects)
Adds all objects into the specified list.
|
static boolean |
addUnique(Collection<Double> collection,
double[] objects)
Adds all objects into the specified list.
|
static boolean |
addUnique(Collection<Float> collection,
float[] objects)
Adds all objects into the specified list.
|
static boolean |
addUnique(Collection<Integer> collection,
int[] objects)
Adds all objects into the specified list.
|
static boolean |
addUnique(Collection<Long> collection,
long[] objects)
Adds all objects into the specified list.
|
static boolean |
addUnique(Collection<Short> collection,
short[] objects)
Adds all objects into the specified list.
|
static <T> boolean |
addUnique(Collection<T> collection,
Collection<T> objects)
Adds all objects into the specified list.
|
static <T> boolean |
addUnique(Collection<T> collection,
T... objects)
Adds all objects into the specified list.
|
static <T> boolean |
addUniqueNonNull(Collection<T> collection,
Collection<T> objects)
Adds all non-null objects into the specified list.
|
static <T> boolean |
addUniqueNonNull(Collection<T> collection,
T... objects)
Adds all non-null objects into the specified list.
|
static <T> boolean |
areAllUnique(Collection<T> collection)
Returns whether or not all
Collection elements are unique. |
static <T> HashSet<T> |
asHashSet(Collection<T> data)
Returns data converted into
HashSet. |
static <T> HashSet<T> |
asHashSet(T... data)
Returns data converted into
HashSet. |
static ArrayList<Boolean> |
asList(boolean[] data)
Returns booleans converted into list.
|
static ArrayList<Byte> |
asList(byte[] data)
Returns bytes converted into list.
|
static ArrayList<Character> |
asList(char[] data)
Returns characters converted into list.
|
static ArrayList<Double> |
asList(double[] data)
Returns doubles converted into list.
|
static ArrayList<Float> |
asList(float[] data)
Returns floats converted into list.
|
static ArrayList<Integer> |
asList(int[] data)
Returns integers converted into list.
|
static <T> ArrayList<T> |
asList(Iterator<T> data)
Returns data converted into list.
|
static ArrayList<Long> |
asList(long[] data)
Returns longs converted into list.
|
static ArrayList<Short> |
asList(short[] data)
Returns shorts converted into list.
|
static <T> ArrayList<T> |
asList(T... data)
Returns data converted into list.
|
static <T> ArrayList<T> |
asNonNullList(T... data)
Returns non-null data converted into list.
|
static <T> Vector<T> |
asVector(T... data)
Returns a vector of objects converted from data.
|
static <T> ArrayList<T> |
copy(Collection<T> collection)
Returns
ArrayList that is a copy of the specified Collection. |
static <T> ArrayList<T> |
copySubList(List<T> list,
int fromIndex,
int toIndex)
Returns sub list with copied values.
|
static <T> List<T> |
distinct(List<T> list)
Removes non-distinct
List elements. |
static boolean |
equals(Collection collection1,
Collection collection2)
Returns whether
Collections are equal or not. |
static boolean |
equals(List list1,
List list2,
boolean strictIndices)
Returns whether
Lists are equal or not. |
static <T> List<T> |
fillList(int size,
Function<Integer,T> indexMapper)
|
static <T> ArrayList<T> |
filter(Collection<T> collection,
Filter<T>... filters)
Returns list of elements filtered from collection.
|
static <T> ArrayList<T> |
filter(Collection<T> collection,
Filter<T> filter)
Returns list of elements filtered from collection.
|
static List<Integer> |
intRange(int from,
int to)
|
static boolean |
isEmpty(Collection collection)
Returns whether specified
Collection is empty or not. |
static <T> ArrayList<T> |
join(Collection<T>... collections)
Returns collection that contains elements from all specified collections.
|
static <K,V> ArrayList<K> |
keysList(Map<K,V> map)
Returns map keys list.
|
static <T> List<T> |
limit(List<T> list,
int limit)
Returns list with limited amount of objects from the initial list.
|
static <T> T |
max(Collection<T> collection,
Comparator<T> comparator)
Returns maximum element of the
Collection according to Comparator. |
static <T> List<T> |
nonNull(List<T> list)
|
static <T> ArrayList<T> |
nonNullCopy(Collection<T> collection)
|
static boolean |
notEmpty(Collection collection)
Returns whether specified
Collection is empty or not. |
static <T> boolean |
removeAll(Collection<T> collection,
Collection<T> objects)
Removes all objects from the specified list.
|
static <T> boolean |
removeAll(Collection<T> collection,
T... objects)
Removes all objects from the specified list.
|
static <T> List<T> |
removeNulls(List<T> list)
Removes all null elements from list.
|
static <T extends Collection<?>> |
requireNotEmpty(T collection,
Supplier<RuntimeException> exceptionSupplier)
Checks that the specified
Collection is not empty and throws a customized RuntimeException if it is. |
static <T> T |
roundRobin(int index,
List<T> items)
Returns item from the
List at the specified index. |
static <T> List<T> |
sort(List<T> list,
Comparator<T>... comparators)
Sorts
List using the specified Comparators. |
static <T> List<T> |
sort(List<T> list,
Comparator<T> comparator)
Sorts
List using the specified Comparator. |
static int[] |
toIntArray(Collection<Integer> collection)
|
static <T> ArrayList<T> |
toList(Collection<T> collection)
Returns
List of objects converted from Collection. |
static <T> ArrayList<T> |
toList(T[] array)
|
static Object[] |
toObjectArray(Collection collection)
|
static <T> ArrayList<String> |
toStringList(List<T> list,
Function<T,String> textProvider)
|
static <T> Vector<T> |
toVector(Collection<T> collection)
Returns a vector of objects converted from collection.
|
static <K,V> ArrayList<V> |
valuesList(Map<K,V> map)
Returns map values list.
|
static <K,V> ArrayList<V> |
valuesSummaryList(Map<K,List<V>> map)
Returns map values summary list with unique elements only.
|
public static boolean isEmpty(@Nullable Collection collection)
Collection is empty or not.collection - Collection to processtrue if specified Collection is empty, false otherwisepublic static boolean notEmpty(@Nullable Collection collection)
Collection is empty or not.collection - Collection to processtrue if specified Collection is not empty, false otherwise@NotNull public static <T> List<T> limit(@NotNull List<T> list, int limit)
T - object typelist - initial listlimit - objects amount limitation@Nullable public static <T> T max(@Nullable Collection<T> collection, @NotNull Comparator<T> comparator)
Collection according to Comparator.
This methid is slightly more optimal and safe unlike Collections.max(Collection, Comparator).T - collection element typecollection - Collectioncomparator - ComparatorCollection according to Comparator@NotNull public static <T> ArrayList<T> copySubList(@NotNull List<T> list, int fromIndex, int toIndex)
T - data typelist - source listfromIndex - start indextoIndex - end index@NotNull public static ArrayList<Boolean> asList(@NotNull boolean[] data)
data - booleans array@NotNull public static ArrayList<Integer> asList(@NotNull int[] data)
data - integers array@NotNull public static ArrayList<Character> asList(@NotNull char[] data)
data - characters array@NotNull public static ArrayList<Byte> asList(@NotNull byte[] data)
data - bytes array@NotNull public static ArrayList<Short> asList(@NotNull short[] data)
data - shorts array@NotNull public static ArrayList<Long> asList(@NotNull long[] data)
data - longs array@NotNull public static ArrayList<Float> asList(@NotNull float[] data)
data - floats array@NotNull public static ArrayList<Double> asList(@NotNull double[] data)
data - doubles array@NotNull public static <T> ArrayList<T> asList(@NotNull T... data)
T - data typedata - data@NotNull public static <T> ArrayList<T> asList(@NotNull Iterator<T> data)
T - data typedata - data@NotNull public static <T> ArrayList<T> asNonNullList(@NotNull T... data)
T - data typedata - datapublic static <T> boolean areAllUnique(@NotNull Collection<T> collection)
Collection elements are unique.T - Collection element typecollection - Collectiontrue if all Collection elements are unique, false otherwisepublic static boolean addUnique(@NotNull Collection<Boolean> collection, @NotNull boolean[] objects)
collection - list to fillobjects - objectstrue if list changed as the result of this operation, false otherwisepublic static boolean addUnique(@NotNull Collection<Integer> collection, @NotNull int[] objects)
collection - list to fillobjects - objectstrue if list changed as the result of this operation, false otherwisepublic static boolean addUnique(@NotNull Collection<Character> collection, @NotNull char[] objects)
collection - list to fillobjects - objectstrue if list changed as the result of this operation, false otherwisepublic static boolean addUnique(@NotNull Collection<Byte> collection, @NotNull byte[] objects)
collection - list to fillobjects - objectstrue if list changed as the result of this operation, false otherwisepublic static boolean addUnique(@NotNull Collection<Short> collection, @NotNull short[] objects)
collection - list to fillobjects - objectstrue if list changed as the result of this operation, false otherwisepublic static boolean addUnique(@NotNull Collection<Long> collection, @NotNull long[] objects)
collection - list to fillobjects - objectstrue if list changed as the result of this operation, false otherwisepublic static boolean addUnique(@NotNull Collection<Float> collection, @NotNull float[] objects)
collection - list to fillobjects - objectstrue if list changed as the result of this operation, false otherwisepublic static boolean addUnique(@NotNull Collection<Double> collection, @NotNull double[] objects)
collection - list to fillobjects - objectstrue if list changed as the result of this operation, false otherwisepublic static <T> boolean addUnique(@NotNull Collection<T> collection, @NotNull T... objects)
T - objects typecollection - list to fillobjects - objectstrue if list changed as the result of this operation, false otherwisepublic static <T> boolean addUnique(@NotNull Collection<T> collection, @NotNull Collection<T> objects)
T - objects typecollection - list to fillobjects - objectstrue if list changed as the result of this operation, false otherwisepublic static <T> boolean addUniqueNonNull(@NotNull Collection<T> collection, @NotNull T... objects)
T - objects typecollection - list to fillobjects - objectstrue if list changed as the result of this operation, false otherwisepublic static <T> boolean addUniqueNonNull(@NotNull Collection<T> collection, @NotNull Collection<T> objects)
T - objects typecollection - list to fillobjects - objectstrue if list changed as the result of this operation, false otherwisepublic static <T> boolean removeAll(@NotNull Collection<T> collection, @NotNull T... objects)
T - objects typecollection - list to fillobjects - objectstrue if list changed as the result of this operation, false otherwisepublic static <T> boolean removeAll(@NotNull Collection<T> collection, @NotNull Collection<T> objects)
T - objects typecollection - list to fillobjects - objectstrue if list changed as the result of this operation, false otherwise@NotNull public static <T> ArrayList<T> join(@Nullable Collection<T>... collections)
T - collection typecollections - collections to join@Nullable public static <T> ArrayList<T> copy(@Nullable Collection<T> collection)
ArrayList that is a copy of the specified Collection.
Note that this method will copy same Collection values into the new ArrayList.T - Collection typecollection - Collection to copyArrayList that is a copy of the specified Collection@NotNull public static <T> ArrayList<T> nonNullCopy(@NotNull Collection<T> collection)
null ArrayList that is a copy of the specified Collection.
Note that this method will copy same Collection values into the new ArrayList.T - Collection typecollection - Collection to copynull ArrayList that is a copy of the specified Collection@Nullable public static <T> List<T> removeNulls(@Nullable List<T> list)
T - list typelist - list to refactorpublic static boolean equals(@NotNull Collection collection1, @NotNull Collection collection2)
Collections are equal or not.collection1 - first Collectioncollection2 - second Collectiontrue if Collections are equal, false otherwisepublic static boolean equals(@Nullable List list1, @Nullable List list2, boolean strictIndices)
Lists are equal or not.@NotNull public static int[] toIntArray(@NotNull Collection<Integer> collection)
collection - Collection of Integersint[] array created using Collection of Integers@NotNull public static Object[] toObjectArray(@NotNull Collection collection)
collection - Collection of ObjectsObject[] array created using Collection of Objects@NotNull public static <T> ArrayList<String> toStringList(@NotNull List<T> list, @NotNull Function<T,String> textProvider)
@NotNull public static <T> ArrayList<T> toList(@NotNull Collection<T> collection)
List of objects converted from Collection.T - Collection elements typecollection - CollectionList of objects converted from Collection@NotNull public static <T> Vector<T> toVector(@NotNull Collection<T> collection)
T - data typecollection - data collection@NotNull public static <T> Vector<T> asVector(@NotNull T... data)
T - data typedata - data@NotNull public static <T> ArrayList<T> filter(@NotNull Collection<T> collection, @Nullable Filter<T> filter)
T - elements typecollection - collection to filterfilter - filter to process@NotNull public static <T> ArrayList<T> filter(@NotNull Collection<T> collection, @NotNull Filter<T>... filters)
T - elements typecollection - collection to filterfilters - filters to process@NotNull public static <T> List<T> distinct(@NotNull List<T> list)
List elements.@NotNull public static <T> List<T> sort(@NotNull List<T> list, @Nullable Comparator<T> comparator)
List using the specified Comparator.T - elements typelist - List to sortcomparator - ComparatorList but sorted according to the specified Comparator@NotNull public static <T> List<T> sort(@NotNull List<T> list, @NotNull Comparator<T>... comparators)
List using the specified Comparators.T - elements typelist - List to sortcomparators - List of ComparatorsList but sorted according to the specified Comparator@NotNull public static <K,V> ArrayList<K> keysList(@NotNull Map<K,V> map)
K - key object typeV - value object typemap - map to process@NotNull public static <K,V> ArrayList<V> valuesList(@NotNull Map<K,V> map)
K - key object typeV - value object typemap - map to process@NotNull public static <K,V> ArrayList<V> valuesSummaryList(@NotNull Map<K,List<V>> map)
K - key object typeV - value object typemap - map to process@NotNull public static <T> List<T> fillList(int size, @NotNull Function<Integer,T> indexMapper)
@NotNull public static <T> HashSet<T> asHashSet(@NotNull Collection<T> data)
HashSet.T - data typedata - dataHashSet@NotNull public static <T> HashSet<T> asHashSet(@NotNull T... data)
HashSet.T - data typedata - dataHashSet@NotNull public static <T extends Collection<?>> T requireNotEmpty(@Nullable T collection, @NotNull Supplier<RuntimeException> exceptionSupplier)
Collection is not empty and throws a customized RuntimeException if it is.T - Collection typecollection - Collection to check for emptinessexceptionSupplier - Supplier for a customized exceptionCollection if not emptyRuntimeException - if Collection is emptyCopyright © 2020. All rights reserved.