public final class CollectionUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> boolean |
addWhenNotExist(Collection<T> list,
T element)
It add to collection if is not present already.
|
static <T> List<T> |
filterToList(Collection<T> collection,
Predicate<T> filter)
This method get some collection and filter expected elements and put them to new List.
|
static <T,R> List<R> |
filterToList(Collection<T> collection,
Predicate<T> filter,
Function<T,R> mapFunc)
This method get some collection and filter expected elements and map them to new type and put results to new List.
|
static <T,R> List<R> |
filterToList(Predicate<T> predicate,
Function<T,R> mapFunc,
T... array)
This method get some array and filter expected elements and map them to new type and put results to new List.
|
static <T> List<T> |
filterToList(Predicate<T> predicate,
T... array)
This method get some collection and filter expected elements and put them to new List.
|
static <T> Set<T> |
filterToSet(Collection<T> collection,
Predicate<T> filter)
This method get some collection and filter expected elements and put them to new set.
|
static <T,R> Set<R> |
filterToSet(Collection<T> collection,
Predicate<T> filter,
Function<T,R> mapFunc)
This method get some collection and filter expected elements and map them to new type and put results to new Set.
|
static <T> T |
getFirst(List<T> list)
It returns first element from list if present.
|
static <T> T |
getLast(List<T> list)
It returns last element from list if present.
|
static int |
getLastIndex(Collection<?> list)
It returns last index from list.
|
static int |
getLastIndex(Object... array)
It returns last index from array.
|
static <T extends Comparable<? super T>> |
hasTheSameElements(Collection<T> first,
Collection<T> second)
It return true when provided collections have the same elements.
|
static <E> List<E> |
intersection(Collection<E> first,
Collection<E> second)
It return intersection for two given collections.
|
static <T> boolean |
isEmpty(Collection<T> list)
It returns true when collection is null or empty.
|
static boolean |
isLastIndex(List<?> list,
int index)
check that given index is last in certain list.
|
static boolean |
isLastIndex(Object[] array,
int index)
check that given index is last in certain array.
|
static <T> boolean |
isNotEmpty(Collection<T> list)
It returns true only when collection is not null, and if not empty.
|
static <T,R> List<R> |
mapToList(Collection<T> collection,
Function<T,R> mapFunc)
This method return new List with mapped values from source collection.
|
static <T,R> List<R> |
mapToList(Collection<T> collection,
Function<T,R> mapFunc,
Predicate<R> filter)
This method return new List with mapped values from source collection.
|
static <T,R> List<R> |
mapToList(Function<T,R> mapFunc,
Predicate<R> predicate,
T... array)
This method return new List with mapped values from source array.
|
static <T,R> List<R> |
mapToList(Function<T,R> mapFunc,
T... array)
This method return new List with mapped values from source array.
|
static <T,R> Set<R> |
mapToSet(Collection<T> collection,
Function<T,R> mapFunc)
This method return new Set with mapped values from source collection.
|
static <T,R> Set<R> |
mapToSet(Collection<T> collection,
Function<T,R> mapFunc,
Predicate<R> filter)
This method return new Set with mapped values from source collection.
|
static <T extends Comparable<? super T>> |
sortAsNewList(Collection<T> list)
It get list and sort elements but not change source list.
|
static <T> List<T> |
swapElementsAsNewList(List<T> sourceList,
int indexToSwap,
T newValue)
Swap element in copy of sourceList and returns it.
|
public static boolean isLastIndex(List<?> list, int index)
list - list to check.index - index to checkpublic static boolean isLastIndex(Object[] array, int index)
array - list to check.index - index to checkpublic static int getLastIndex(Collection<?> list)
list - for get last index.public static int getLastIndex(Object... array)
array - for get last index.public static <T> Set<T> filterToSet(Collection<T> collection, Predicate<T> filter)
T - generic type for collection and predicate.collection - source collection.filter - predicate for filter.public static <T,R> Set<R> filterToSet(Collection<T> collection, Predicate<T> filter, Function<T,R> mapFunc)
T - type for source collection.R - type for result Set.collection - source collection.filter - predicate for filter by source elements type.mapFunc - map to new type filtered result.public static <T,R> Set<R> mapToSet(Collection<T> collection, Function<T,R> mapFunc)
T - type for source collection.R - type for result Set.collection - source elements.mapFunc - function for map from collection to new Set with another types.public static <T,R> Set<R> mapToSet(Collection<T> collection, Function<T,R> mapFunc, Predicate<R> filter)
T - type for source collection.R - type for result Set.collection - source elements.mapFunc - function for map from collection to new Set with another types.filter - predicate for mapped elements.public static <T,R> List<R> mapToList(Collection<T> collection, Function<T,R> mapFunc)
T - type for source collection.R - type for result List.collection - source elements.mapFunc - function for map from collection to new List with another types.public static <T,R> List<R> mapToList(Collection<T> collection, Function<T,R> mapFunc, Predicate<R> filter)
T - type for source collection.R - type for result List.collection - source elements.mapFunc - function for map from collection to new List with another types.filter - predicate for mapped elements.public static <T,R> List<R> mapToList(Function<T,R> mapFunc, T... array)
T - type for source array.R - type for result List.mapFunc - function for map from collection to new List with another types.array - source elements.public static <T,R> List<R> mapToList(Function<T,R> mapFunc, Predicate<R> predicate, T... array)
T - type for source array.R - type for result List.mapFunc - function for map from collection to new List with another types.predicate - predicate for filter.array - source elements.public static <T> List<T> filterToList(Collection<T> collection, Predicate<T> filter)
T - generic type for collection and predicate.collection - source collection.filter - predicate for filter.public static <T,R> List<R> filterToList(Collection<T> collection, Predicate<T> filter, Function<T,R> mapFunc)
T - type for source collection.R - type for result List.collection - source collection.filter - predicate for filter by source elements type.mapFunc - map to new type filtered result.public static <T> List<T> filterToList(Predicate<T> predicate, T... array)
T - generic type for collection and predicate.predicate - predicate for filter.array - source collection.public static <T,R> List<R> filterToList(Predicate<T> predicate, Function<T,R> mapFunc, T... array)
T - type for source array.R - type for result List.predicate - predicate for filter by source elements type.mapFunc - map to new type filtered result.array - source array.public static <T extends Comparable<? super T>> List<T> sortAsNewList(Collection<T> list)
T - generic type in list.list - to sort.public static <T> List<T> swapElementsAsNewList(List<T> sourceList, int indexToSwap, T newValue)
T - generic type for list.sourceList - source for swap.indexToSwap - index element to swap in copy of source listnewValue - new value in certain index.public static <T> T getFirst(List<T> list)
T - generic typelist - as sourcepublic static <T> T getLast(List<T> list)
T - generic typelist - as sourcepublic static <T> boolean addWhenNotExist(Collection<T> list, T element)
T - generic type of collection and tried add element.list - where will be added element.element - to add.public static <T extends Comparable<? super T>> boolean hasTheSameElements(Collection<T> first, Collection<T> second)
T - generic type of collections.first - collectionsecond - collectionpublic static <T> boolean isEmpty(Collection<T> list)
T - generic type.list - to verify.public static <T> boolean isNotEmpty(Collection<T> list)
T - generic type.list - to verify.public static <E> List<E> intersection(Collection<E> first, Collection<E> second)
E - generic type.first - collection.second - collection.Copyright © 2019. All rights reserved.