public abstract class CollectionUtils extends Object
Modifier and Type | Method and Description |
---|---|
static <R> Collection<R> |
asCollection(Object potentialCollection)
Returns a Collection instance that contains the elements of the given
potentialCollection . |
static <T,C extends Collection<T>> |
intersect(Collection<? extends T> collection1,
Collection<? extends T> collection2,
Supplier<C> collectionBuilder)
Returns a collection containing the elements that are in both given collections
collection1 and
collection2 , using the given collectionBuilder to create an instance for the new collection. |
static <S,T extends Collection<S>> |
merge(T collection1,
T collection2,
Supplier<T> factoryMethod)
Merge two collections into a new collection instance.
|
public static <S,T extends Collection<S>> T merge(T collection1, T collection2, Supplier<T> factoryMethod)
factoryMethod
.
If any of the two inputs collections is null
or empty the other input collection is returned (even if
that one is null
as well).
S
- the type of elements in the collectionsT
- the type of collectioncollection1
- the first collectioncollection2
- the second collectionfactoryMethod
- function to initialize the new collectionpublic static <R> Collection<R> asCollection(Object potentialCollection)
potentialCollection
. If not a
Collection-like structure, it will return a Collection with the given potentialCollection
as the sole
element.
The following structures are recognized and will have their elements placed inside a Collection:
Stream
Collection
Spliterator
Iterable
R
- The type of instance contained in the resulting CollectionpotentialCollection
- The instance to collect all elements frompotentialCollection
public static <T,C extends Collection<T>> C intersect(Collection<? extends T> collection1, Collection<? extends T> collection2, Supplier<C> collectionBuilder)
collection1
and
collection2
, using the given collectionBuilder
to create an instance for the new collection. The
items are added to the resulting collection in the order as found in collection2.T
- The type of element contained in the resuling collectionC
- The type of collection to returncollection1
- The first collectioncollection2
- The second collectioncollectionBuilder
- The factory for the returned collection instanceCopyright © 2010–2018. All rights reserved.