Collection instances.
Various utility methods might put the input objects into a Set/Map/Bag. In case
the input objects override Object#equals(Object), it is mandatory that
the general contract of the Object#hashCode() method is maintained.
Note
From 4.0, method parameters will take Iterable objects when possible.
| Modifier and Type | Class and Description |
|---|---|
| private static class | CollectionUtils.CardinalityHelper<
the element type O>Helper class to easily access cardinality properties of two collections. |
| private static class | CollectionUtils.EquatorWrapper<
the element type O>Wraps another object and uses the provided Equator to implement
|
| private static class | CollectionUtils.SetOperationCardinalityHelper<
the element type O>Helper class for set-related operations, e.g. union, subtract, intersection. |
| Modifier and Type | Field and Description |
|---|---|
| public static final Collection | EMPTY_COLLECTION
An empty unmodifiable collection. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static < the type of object the C> booleanCollection contains | Returns: a boolean indicating whether the collection has changed or not.the collection to add to, must not be null collection, final Iterable<? extends C> the iterable of elements to add, must not be null iterable)Adds all elements in the |
| public static < the type of object the C> booleanCollection contains | Returns: a boolean indicating whether the collection has changed or not.the collection to add to, must not be null collection, final Iterator<? extends C> the iterator of elements to add, must not be null iterator)Adds all elements in the iteration to the given collection. |
| public static < the type of object the C> booleanCollection contains | Returns: true if the collections was changed, false otherwisethe collection to add to, must not be null collection, final Enumeration<? extends C> the enumeration of elements to add, must not be null enumeration)Adds all elements in the enumeration to the given collection. |
| public static < the type of object the C> booleanCollection contains | Returns: true if the collection was changed, false otherwisethe collection to add to, must not be null collection, final C... the array of elements to add, must not be null elements)Adds all elements in the array to the given collection. |
| public static < the type of object the T> booleanCollection contains | Returns: true if the collection changedthe collection to add to, must not be null collection, final T the object to add, if null it will not be added object)Adds an element to the collection unless the element is null. |
| public static < the type of object that the O> intIterable may contain. | Returns: the number of occurrences of obj in collthe object to find the cardinality of obj, final Iterable<? super O> the coll)Iterable to search
Deprecated
since 4.1, use
Returns the number of occurrences of obj in coll.
IterableUtils#frequency(Iterable, Object) instead.
|
| pack-priv static void | |
| public static < the element type O extends Comparable | Returns: a new sorted List, containing the elements of Collection a and bthe first collection, must not be null a, final Iterable<? extends O> the second collection, must not be null b)Merges two sorted Collections, a and b, into a single, sorted List such that the natural ordering of the elements is retained. |
| public static < the element type O extends Comparable | Returns: a new sorted List, containing the elements of Collection a and bthe first collection, must not be null a, final Iterable<? extends O> the second collection, must not be null b, final boolean if includeDuplicates)true duplicate elements will be retained, otherwise
they will be removed in the output collectionMerges two sorted Collections, a and b, into a single, sorted List such that the natural ordering of the elements is retained. |
| public static < the element type O> List | Returns: a new sorted List, containing the elements of Collection a and bthe first collection, must not be null a, final Iterable<? extends O> the second collection, must not be null b, final Comparator<? super O> the comparator to use for the merge. c)Merges two sorted Collections, a and b, into a single, sorted List such that the ordering of the elements according to Comparator c is retained. |
| public static < the element type O> List | Returns: a new sorted List, containing the elements of Collection a and bthe first collection, must not be null a, final Iterable<? extends O> the second collection, must not be null b, final Comparator<? super O> the comparator to use for the merge. c, final boolean if includeDuplicates)true duplicate elements will be retained, otherwise
they will be removed in the output collectionMerges two sorted Collections, a and b, into a single, sorted List such that the ordering of the elements according to Comparator c is retained. |
| public static < the type of object in the input collection I, the type of object in the output collection O> Collection | Returns: the transformed result (new list)the collection to get the input from, may not be null inputCollection, final Transformer<? super I, ? extends O> the transformer to use, may be null transformer)Returns a new Collection containing all elements of the input collection transformed by the given transformer. |
| public static < the type of object in the input collection I, the type of object in the output collection O> Collection | Returns: the transformed result (new list)the iterator to get the input from, may be null inputIterator, final Transformer<? super I, ? extends O> the transformer to use, may be null transformer)Transforms all elements from the input iterator with the given transformer and adds them to the output collection. |
| public static < the type of object in the input collection I, the type of object in the output collection O, the type of the output collection R extends Collection | Returns: the output collection with the transformed input addedthe collection to get the input from, may be null inputCollection, final Transformer<? super I, ? extends O> the transformer to use, may be null transformer, final R the collection to output into, may not be null if inputCollection
and transformer are not null outputCollection)Transforms all elements from input collection with the given transformer and adds them to the output collection. |
| public static < the type of object in the input collection I, the type of object in the output collection O, the type of the output collection R extends Collection | Returns: the outputCollection with the transformed input addedthe iterator to get the input from, may be null inputIterator, final Transformer<? super I, ? extends O> the transformer to use, may be null transformer, final R the collection to output into, may not be null if inputIterator
and transformer are not null outputCollection)Transforms all elements from the input iterator with the given transformer and adds them to the output collection. |
| public static boolean | Returns: true iff the intersection of the collections has the same cardinality
as the set of unique elements from the second collectionthe first collection, must not be null coll1, final Collection<?> the second collection, must not be null coll2)Returns |
| public static < the type of object to lookup in T> booleancoll1. | Returns: true iff the intersection of the collections is non-emptythe first collection, must not be null coll1, final T... the second collection, must not be null coll2)Returns |
| public static boolean | Returns: true iff the intersection of the collections is non-emptythe first collection, must not be null coll1, final Collection<?> the second collection, must not be null coll2)Returns |
| public static < the type of object the C> intIterable contains | Returns: the number of matches for the predicate in the collectionthe input, final Predicate<? super C> Iterable to get the input from, may be nullthe predicate to use, may be null predicate)
Deprecated
since 4.1, use
Counts the number of elements in the input collection that match the
predicate.
IterableUtils#countMatches(Iterable, Predicate) instead
|
| public static < the generic type that is able to represent the types contained
in both input collections. O> Collection | Returns: the symmetric difference of the two collectionsthe first collection, must not be null a, final Iterable<? extends O> the second collection, must not be null b)Returns a |
| public static < the element type T> Collection | Returns: immutable empty collectionReturns the immutable EMPTY_COLLECTION with generic type safety. |
| public static < the element type T> Collection | Returns: an empty collection if the argument isnullthe collection, possibly collection)nullReturns an immutable empty collection if the argument is |
| public static < the type of object the C> booleanIterable contains | Returns: true if at least one element of the collection matches the predicatethe input, final Predicate<? super C> Iterable to get the input from, may be nullthe predicate to use, may be null predicate)
Deprecated
since 4.1, use
Answers true if a predicate is true for at least one element of a
collection.
IterableUtils#matchesAny(Iterable, Predicate) instead
|
| public static < collection type E> E | Returns: sole member of collectionto read collection)Extract the lone element of the specified Collection. |
| public static < the type of object the T> booleanIterable contains | Returns: true if the collection is modified by this call, false otherwise.the collection to get the input from, may be null collection, final Predicate<? super T> the predicate to use as a filter, may be null predicate)Filter the collection by applying a Predicate to each element. |
| public static < the type of object the T> booleanIterable contains | Returns: true if the collection is modified by this call, false otherwise.the collection to get the input from, may be null collection, final Predicate<? super T> the predicate to use as a filter, may be null predicate)Filter the collection by applying a Predicate to each element. |
| public static < the type of object the T> TIterable contains | Returns: the first element of the collection which matches the predicate or null if none could be foundthe collection to search, may be null collection, final Predicate<? super T> the predicate to use, may be null predicate)
Deprecated
since 4.1, use
Finds the first element in the given collection which matches the given predicate.
IterableUtils#find(Iterable, Predicate) instead
|
| public static < the type of object the T, Iterable containsthe closure type C extends Closure | Returns: the last element in the collection, or null if either collection or closure is nullthe collection to get the input from, may be null collection, final C the closure to perform, may be null closure)
Deprecated
since 4.1, use
Executes the given closure on each but the last element in the collection.
IterableUtils#forEachButLast(Iterable, Closure) instead
|
| public static < the type of object the T, Collection containsthe closure type C extends Closure | Returns: the last element in the collection, or null if either iterator or closure is nullthe iterator to get the input from, may be null iterator, final C the closure to perform, may be null closure)
Deprecated
since 4.1, use
Executes the given closure on each but the last element in the collection.
IteratorUtils#forEachButLast(Iterator, Closure) instead
|
| public static < the type of object the T, Iterable containsthe closure type C extends Closure | Returns: closurethe collection to get the input from, may be null collection, final C the closure to perform, may be null closure)
Deprecated
since 4.1, use
Executes the given closure on each element in the collection.
IterableUtils#forEach(Iterable, Closure) instead
|
| public static < the type of object the T, Iterator containsthe closure type C extends Closure | Returns: closurethe iterator to get the input from, may be null iterator, final C the closure to perform, may be null closure)
Deprecated
since 4.1, use
Executes the given closure on each element in the collection.
IteratorUtils#forEach(Iterator, Closure) instead
|
| public static < the type of object in the T> TIterator | Returns: the object at the specified indexthe iterator to get a value from iterator, final int the index to get index)
Deprecated
since 4.1, use
Returns the IteratorUtils.get(Iterator, int) instead
index-th value in Iterator, throwing
IndexOutOfBoundsException if there is no such element.
|
| public static < the type of object in the T> TIterable. | Returns: the object at the specified indexthe iterable, final int Iterable to get a value fromthe index to get index)
Deprecated
since 4.1, use
Returns the IterableUtils.get(Iterable, int) instead
index-th value in the iterable's Iterator, throwing
IndexOutOfBoundsException if there is no such element.
|
| public static Object | Returns: the object at the specified indexthe object to get a value from object, final int the index to get index)Returns the |
| public static < the key type in the K, Mapthe key type in the V> Map.Map | |
| public static < the type of object in the returned O> MapMap. This is a super type of <I>. | Returns: the populated cardinality mapthe collection to get the cardinality map for, must not be null coll)Returns a |
| public static < the generic type that is able to represent the types contained
in both input collections. O> Collection | Returns: the intersection of the two collectionsthe first collection, must not be null a, final Iterable<? extends O> the second collection, must not be null b)Returns a |
| public static boolean | Returns: true if empty or nullthe collection to check, may be null coll)Null-safe check if the specified collection is empty. |
| public static boolean | Returns: true iff the collections contain the same elements with the same cardinalities.the first collection, must not be null a, final Collection<?> the second collection, must not be null b)Returns |
| public static < the element type E> boolean | Returns: true iff the collections contain the same elements with the same cardinalities.the first collection, must not be null a, final Collection<? extends E> the second collection, must not be null b, final Equator<? super E> the Equator used for testing equality equator)Returns |
| public static boolean | Returns: true if the BoundedCollection is fullthe collection to check coll)Returns true if no more elements can be added to the Collection. |
| public static boolean | Returns: true if non-null and non-emptythe collection to check, may be null coll)Null-safe check if the specified collection is not empty. |
| public static boolean | Returns: true iff a is a proper sub-collection of bthe first (sub?) collection, must not be null a, final Collection<?> the second (super?) collection, must not be null b)Returns |
| public static boolean | Returns: true iff a is a sub-collection of bthe first (sub?) collection, must not be null a, final Collection<?> the second (super?) collection, must not be null b)Returns |
| public static < the type of object the C> booleanIterable contains | Returns: true if every element of the collection matches the predicate or if the collection is empty, false otherwisethe input, final Predicate<? super C> Iterable to get the input from, may be nullthe predicate to use, may be null predicate)
Deprecated
since 4.1, use
Answers true if a predicate is true for every element of a
collection.
IterableUtils#matchesAll(Iterable, Predicate) instead
|
| public static int | Returns: the maximum size of the BoundedCollection, -1 if no maximum sizethe collection to check coll)Get the maximum number of elements that the Collection can contain. |
| public static < the element type E> Collection | Returns: an unordered collection of all permutations of the input collectionthe collection to create permutations for, may not be null collection)Returns a |
| public static < the type of objects in the Collection. C> Collection | Returns: a predicated collection backed by the given collectionthe collection to predicate, must not be null collection, final Predicate<? super C> the predicate for the collection, must not be null predicate)Returns a predicated (validating) collection backed by the given collection. |
| public static < the type of object the E> CollectionCollection contains | Returns: aCollection containing all the elements of collection except
any elements that also occur in remove.the collection from which items are removed (in the returned collection) collection, final Collection<?> the items to be removed from the returned remove)collectionRemoves the elements in |
| public static < the type of object the E> CollectionCollection contains | Returns: aCollection containing all the elements of collection
except any element that if equal according to the equatorthe collection from which items are removed (in the returned collection) collection, final Iterable<? extends E> the items to be removed from the returned collection remove, final Equator<? super E> the Equator used for testing equality equator)Removes all elements in |
| public static < the type of object the C> CollectionCollection contains | Returns: aCollection containing all the elements of collection
that occur at least once in retain.the collection whose contents are the target of the #retailAll operation collection, final Collection<?> the collection containing the elements to be retained in the returned collection retain)Returns a collection containing all the elements in |
| public static < the type of object the E> CollectionCollection contains | Returns: aCollection containing all the elements of collection
that occur at least once in retain according to the equatorthe collection whose contents are the target of the collection, final Iterable<? extends E> retainAll operationthe collection containing the elements to be retained in the returned collection retain, final Equator<? super E> the Equator used for testing equality equator)Returns a collection containing all the elements in
|
| public static void | |
| public static < the type of object the O> CollectionIterable contains | Returns: the elements matching the predicate (new list)the collection to get the input from, may not be null inputCollection, final Predicate<? super O> the predicate to use, may be null predicate)Selects all elements from input collection which match the given predicate into an output collection. |
| public static < the type of object the O, Iterable containsthe type of the output R extends CollectionCollection | Returns: the outputCollectionthe collection to get the input from, may be null inputCollection, final Predicate<? super O> the predicate to use, may be null predicate, final R the collection to output into, may not be null if the inputCollection
and predicate or not null outputCollection)Selects all elements from input collection which match the given predicate and adds them to outputCollection. |
| public static < the type of object the O, Iterable containsthe type of the output R extends CollectionCollection | Returns: the outputCollectionthe collection to get the input from, may be null inputCollection, final Predicate<? super O> the predicate to use, may be null predicate, final R the collection to output selected elements into, may not be null if the
inputCollection and predicate are not null outputCollection, final R the collection to output rejected elements into, may not be null if the
inputCollection or predicate are not null rejectedCollection)Selects all elements from inputCollection into an output and rejected collection, based on the evaluation of the given predicate. |
| public static < the type of object the O> CollectionIterable contains | Returns: the elements not matching the predicate (new list)the collection to get the input from, may not be null inputCollection, final Predicate<? super O> the predicate to use, may be null predicate)Selects all elements from inputCollection which don't match the given predicate into an output collection. |
| public static < the type of object the O, Iterable containsthe type of the output R extends CollectionCollection | Returns: outputCollectionthe collection to get the input from, may be null inputCollection, final Predicate<? super O> the predicate to use, may be null predicate, final R the collection to output into, may not be null if the inputCollection
and predicate or not null outputCollection)Selects all elements from inputCollection which don't match the given predicate and adds them to outputCollection. |
| public static int | |
| public static boolean | Returns: true if empty or nullthe object to get the size of, may be null object)Checks if the specified collection/array/iterator is empty. |
| public static < the generic type that is able to represent the types contained
in both input collections. O> Collection | Returns: a new collection with the resultsthe collection to subtract from, must not be null a, final Iterable<? extends O> the collection to subtract, must not be null b)Returns a new |
| public static < the generic type that is able to represent the types contained
in both input collections. O> Collection | Returns: a new collection with the resultsthe collection to subtract from, must not be null a, final Iterable<? extends O> the collection to subtract, must not be null b, final Predicate<O> the condition used to determine which elements of b are
subtracted. p)Returns a new |
| public static < the type of object the C> CollectionCollection contains | Returns: a synchronized collection backed by the given collectionthe collection to synchronize, must not be null collection)
Deprecated
since 4.1, use
Returns a synchronized collection backed by the given collection.
java. instead
|
| public static < the type of object the C> voidCollection contains | transform(final Collection<C>
the collection, final Transformer<? super C, ? extends C> Collection to get the input from, may be nullthe transformer to perform, may be null transformer)Transform the collection by applying a Transformer to each element. |
| public static < the type of object the E> CollectionCollection contains | Returns: a transformed collection backed by the given collectionthe collection to predicate, must not be null collection, final Transformer<? super E, ? extends E> the transformer for the collection, must not be null transformer)Returns a transformed bag backed by the given collection. |
| public static < the generic type that is able to represent the types contained
in both input collections. O> Collection | Returns: the union of the two collectionsthe first collection, must not be null a, final Iterable<? extends O> the second collection, must not be null b)Returns a |
| public static < the type of object the C> CollectionCollection contains | Returns: an unmodifiable collection backed by the given collectionthe collection to make unmodifiable, must not be null collection)
Deprecated
since 4.1, use
Returns an unmodifiable collection backed by the given collection.
java. instead
|