java.lang.Object | +--org.apache.commons.collections.CollectionUtils
static Collection | An empty unmodifiable collection. |
CollectionUtils should not normally be instantiated. |
static void | addAll(Collection collection, Iterator iterator) Adds all elements in the iteration to the given collection. |
static void | addAll(Collection collection, Enumeration enumeration) Adds all elements in the enumeration to the given collection. |
static void | addAll(Collection collection, Object[] elements) Adds all elements in the array to the given collection. |
static int | cardinality(Object obj, final Collection col) Returns the number of occurrences of obj in col. |
static Collection | collect(Collection inputCollection, Transformer transformer) Returns a new Collection consisting of the elements of inputCollection transformed by the given transformer. |
static Collection | collect(Iterator inputIterator, Transformer transformer) Transforms all elements from the inputIterator with the given transformer and adds them to the outputCollection. |
static Collection | collect(Collection inputCollection, final Transformer transformer, final Collection outputCollection) Transforms all elements from inputCollection with the given transformer and adds them to the outputCollection. |
static Collection | collect(Iterator inputIterator, final Transformer transformer, final Collection outputCollection) Transforms all elements from the inputIterator with the given transformer and adds them to the outputCollection. |
static boolean | containsAny(final Collection coll1, final Collection coll2) Returns true iff at least one element is in both collections. |
static int | countMatches(Collection inputCollection, Predicate predicate) Counts the number of elements in the input collection that match the predicate. |
static Collection | disjunction(final Collection a, final Collection b) Returns a Collection containing the exclusive disjunction (symmetric difference) of the given Collections. |
static boolean | exists(Collection collection, Predicate predicate) Answers true if a predicate is true for at least one element of a collection. |
static void | filter(Collection collection, Predicate predicate) Filter the collection by applying a Predicate to each element. |
static Object | find(Collection collection, Predicate predicate) Finds the first element in the given collection which matches the given predicate. |
static void | forAllDo(Collection collection, Closure closure) Executes the given closure on each element in the collection. |
static Object | get(Object object, int index) Returns the index-th value in object, throwing IndexOutOfBoundsException if there is no such element or IllegalArgumentException if object is not an instance of one of the supported types. |
static Map | getCardinalityMap(final Collection coll) Returns a Map mapping each unique element in the given Collection to an Integer representing the number of occurrences of that element in the Collection. |
static Object | index(Object obj, int idx) Given an Object, and an index, returns the nth value in the object. |
static Object | index(Object obj, Object index) Given an Object, and a key (index), returns the value associated with that key in the Object. |
static Collection | intersection(final Collection a, final Collection b) Returns a Collection containing the intersection of the given Collections. |
static boolean | isEqualCollection(final Collection a, final Collection b) Returns true iff the given Collections contain exactly the same elements with exactly the same cardinalities. |
static boolean | isFull(Collection coll) Returns true if no more elements can be added to the Collection. |
static boolean | isProperSubCollection(final Collection a, final Collection b) Returns true iff a is a proper sub-collection of b, that is, iff the cardinality of e in a is less than or equal to the cardinality of e in b, for each element e in a, and there is at least one element f such that the cardinality of f in b is strictly greater than the cardinality of f in a. |
static boolean | isSubCollection(final Collection a, final Collection b) Returns true iff a is a sub-collection of b, that is, iff the cardinality of e in a is less than or equal to the cardinality of e in b, for each element e in a. |
static int | maxSize(Collection coll) Get the maximum number of elements that the Collection can contain. |
static Collection | predicatedCollection(Collection collection, Predicate predicate) Returns a predicated collection backed by the given collection. |
static void | reverseArray(Object[] array) Reverses the order of the given array. |
static Collection | select(Collection inputCollection, Predicate predicate) Selects all elements from input collection which match the given predicate into an output collection. |
static void | select(Collection inputCollection, Predicate predicate, Collection outputCollection) Selects all elements from input collection which match the given predicate and adds them to outputCollection. |
static Collection | selectRejected(Collection inputCollection, Predicate predicate) Selects all elements from inputCollection which don't match the given predicate into an output collection. |
static void | selectRejected(Collection inputCollection, Predicate predicate, Collection outputCollection) Selects all elements from inputCollection which don't match the given predicate and adds them to outputCollection. |
static Collection | subtract(final Collection a, final Collection b) Returns a new Collection containing a - b. |
static Collection | synchronizedCollection(Collection collection) Returns a synchronized collection backed by the given collection. |
static void | transform(Collection collection, Transformer transformer) Transform the collection by applying a Transformer to each element. |
static Collection | transformedCollection(Collection collection, Transformer transformer) Returns a transformed bag backed by the given collection. |
static Collection | typedCollection(Collection collection, Class type) Returns a typed collection backed by the given collection. |
static Collection | union(final Collection a, final Collection b) Returns a Collection containing the union of the given Collections. |
static Collection | unmodifiableCollection(Collection collection) Returns an unmodifiable collection backed by the given collection. |
public static final Collection EMPTY_COLLECTION
public CollectionUtils()
CollectionUtils
should not normally be instantiated.
public static void addAll(Collection collection, Enumeration enumeration)
- if the collection or enumeration is nullpublic static void addAll(Collection collection, Iterator iterator)
- if the collection or iterator is nullpublic static void addAll(Collection collection, Object[] elements)
- if the collection or array is nullpublic static int cardinality(Object obj, final Collection col)
public static Collection collect(Collection inputCollection, final Transformer transformer, final Collection outputCollection)
- if the output collection is nullpublic static Collection collect(Collection inputCollection, Transformer transformer)
- if the input collection is nullpublic static Collection collect(Iterator inputIterator, final Transformer transformer, final Collection outputCollection)
- if the output collection is nullpublic static Collection collect(Iterator inputIterator, Transformer transformer)
public static boolean containsAny(final Collection coll1, final Collection coll2)
true
iff at least one element is in both collections.
In other words, this method returns true
iff the
intersection of coll1 and coll2 is not empty.
intersection
public static int countMatches(Collection inputCollection, Predicate predicate)
null
collection or predicate matches no elements.
public static Collection disjunction(final Collection a, final Collection b)
public static boolean exists(Collection collection, Predicate predicate)
null
collection or predicate returns false.
public static void filter(Collection collection, Predicate predicate)
public static Object find(Collection collection, Predicate predicate)
public static void forAllDo(Collection collection, Closure closure)
public static Object get(Object object, int index)
index
-th value in object
, throwing
IndexOutOfBoundsException
if there is no such element or
IllegalArgumentException
if object
is not an
instance of one of the supported types.
The supported types, and associated semantics are:
Map.Entry
in position
index
in the map's entrySet
iterator,
if there is such an entry.index
-th array entry is returned,
if there is such an entry; otherwise an ArrayIndexOutOfBoundsException
is thrown.index
-th object
returned by the collection's default iterator, if there is such an element.index
-th object in the Iterator/Enumeration, if there
is such an element. The Iterator/Enumeration is advanced to
index
(or to the end, if index
exceeds the
number of entries) as a side effect of this method.
-
- public static Map getCardinalityMap(final Collection coll)
public static Object index(Object obj, int idx)
-
- public static Object index(Object obj, Object index)
-
- public static Collection intersection(final Collection a, final Collection b)
Collection.retainAll
containsAny
public static boolean isEqualCollection(final Collection a, final Collection b)
public static boolean isFull(Collection coll)
- if the collection is nullpublic static boolean isProperSubCollection(final Collection a, final Collection b)
a.size()
and b.size()
represent the
total cardinality of a and b, resp. a.size() <32Integer.MAXVALUE
isSubCollection
Collection.containsAll
public static boolean isSubCollection(final Collection a, final Collection b)
isProperSubCollection
Collection.containsAll
public static int maxSize(Collection coll)
- if the collection is nullpublic static Collection predicatedCollection(Collection collection, Predicate predicate)
- if the Collection is nullpublic static void reverseArray(Object[] array)
public static void select(Collection inputCollection, Predicate predicate, Collection outputCollection)
public static Collection select(Collection inputCollection, Predicate predicate)
null
predicate matches no elements.
- if the input collection is nullpublic static void selectRejected(Collection inputCollection, Predicate predicate, Collection outputCollection)
null
, no elements are added to outputCollection
.
public static Collection selectRejected(Collection inputCollection, Predicate predicate)
null
, the result is an empty list.
- if the input collection is nullpublic static Collection subtract(final Collection a, final Collection b)
Collection.removeAll
public static Collection synchronizedCollection(Collection collection)
Collection c = CollectionUtils.synchronizedCollection(myCollection); synchronized (c) { Iterator i = c.iterator(); while (i.hasNext()) { process (i.next()); } }This method uses the implementation in the decorators subpackage.
- if the collection is nullpublic static void transform(Collection collection, Transformer transformer)
public static Collection transformedCollection(Collection collection, Transformer transformer)
- if the Collection or Transformer is nullpublic static Collection typedCollection(Collection collection, Class type)
public static Collection union(final Collection a, final Collection b)
Collection.addAll
public static Collection unmodifiableCollection(Collection collection)
- if the collection is null