|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.commons.collections.CollectionUtils
A set of Collection
related utility methods.
Field Summary | |
static java.util.Iterator |
EMPTY_ITERATOR
Deprecated. use IteratorUtils.EMPTY_ITERATOR |
Constructor Summary | |
CollectionUtils()
Please don't ever instantiate a CollectionUtils . |
Method Summary | |
static void |
addAll(java.util.Collection collection,
java.util.Enumeration enumeration)
Adds all elements in the enumeration to the given collection. |
static void |
addAll(java.util.Collection collection,
java.util.Iterator iterator)
Adds all elements in the iteration to the given collection. |
static void |
addAll(java.util.Collection collection,
java.lang.Object[] elements)
Adds all elements in the array to the given collection. |
static int |
cardinality(java.lang.Object obj,
java.util.Collection col)
Returns the number of occurrences of obj in col. |
static java.util.Collection |
collect(java.util.Collection inputCollection,
Transformer transformer)
Transforms all elements from inputCollection with the given transformer and adds them to the outputCollection. |
static java.util.Collection |
collect(java.util.Collection inputCollection,
Transformer transformer,
java.util.Collection outputCollection)
Transforms all elements from inputCollection with the given transformer and adds them to the outputCollection. |
static java.util.Collection |
collect(java.util.Iterator inputIterator,
Transformer transformer)
Transforms all elements from the inputIterator with the given transformer and adds them to the outputCollection. |
static java.util.Collection |
collect(java.util.Iterator inputIterator,
Transformer transformer,
java.util.Collection outputCollection)
Transforms all elements from the inputIterator with the given transformer and adds them to the outputCollection. |
static boolean |
containsAny(java.util.Collection a,
java.util.Collection b)
Returns true iff some element of a
is also an element of b (or, equivalently, if
some element of b is also an element of a). |
static java.util.Collection |
disjunction(java.util.Collection a,
java.util.Collection b)
Returns a Collection containing the exclusive disjunction
(symmetric difference) of the given Collection s. |
static void |
filter(java.util.Collection collection,
Predicate predicate)
Filter the collection by applying a Predicate to each element. |
static java.lang.Object |
find(java.util.Collection collection,
Predicate predicate)
Finds the first element in the given collection which matches the given predicate. |
static void |
forAllDo(java.util.Collection collection,
Closure closure)
Executes the given closure on each element in the collection. |
static java.util.Map |
getCardinalityMap(java.util.Collection col)
Returns a Map mapping each unique element in
the given Collection to an Integer
representing the number of occurances of that element
in the Collection . |
static java.util.Iterator |
getIterator(java.lang.Object obj)
Deprecated. use IteratorUtils version instead |
static java.lang.Object |
index(java.lang.Object obj,
int idx)
Given an Object, and an index, it will get the nth value in the object. |
static java.lang.Object |
index(java.lang.Object obj,
java.lang.Object index)
Given an Object, and a key (index), it will get value associated with that key in the Object. |
static java.util.Collection |
intersection(java.util.Collection a,
java.util.Collection b)
Returns a Collection containing the intersection
of the given Collection s. |
static boolean |
isEqualCollection(java.util.Collection a,
java.util.Collection b)
Returns true iff the given Collection s contain
exactly the same elements with exactly the same cardinality. |
static boolean |
isProperSubCollection(java.util.Collection a,
java.util.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(java.util.Collection a,
java.util.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 java.util.Collection |
predicatedCollection(java.util.Collection collection,
Predicate predicate)
Returns a predicated collection backed by the given collection. |
static void |
reverseArray(java.lang.Object[] array)
Reverses the order of the given array |
static java.util.Collection |
select(java.util.Collection inputCollection,
Predicate predicate)
Selects all elements from input collection which match the given predicate into an output collection. |
static void |
select(java.util.Collection inputCollection,
Predicate predicate,
java.util.Collection outputCollection)
Selects all elements from input collection which match the given predicate and adds them to outputCollection. |
static java.util.Collection |
subtract(java.util.Collection a,
java.util.Collection b)
Returns a Collection containing a - b. |
static void |
transform(java.util.Collection collection,
Transformer transformer)
Transform the collection by applying a Transformer to each element. |
static java.util.Collection |
union(java.util.Collection a,
java.util.Collection b)
Returns a Collection containing the union
of the given Collection s. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.util.Iterator EMPTY_ITERATOR
Constructor Detail |
public CollectionUtils()
CollectionUtils
.
Method Detail |
public static java.util.Collection union(java.util.Collection a, java.util.Collection b)
Collection
containing the union
of the given Collection
s.
The cardinality of each element in the returned Collection
will be equal to the maximum of the cardinality of that element
in the two given Collection
s.
Collection.addAll(java.util.Collection)
public static java.util.Collection intersection(java.util.Collection a, java.util.Collection b)
Collection
containing the intersection
of the given Collection
s.
The cardinality of each element in the returned Collection
will be equal to the minimum of the cardinality of that element
in the two given Collection
s.
Collection.retainAll(java.util.Collection)
,
containsAny(java.util.Collection, java.util.Collection)
public static java.util.Collection disjunction(java.util.Collection a, java.util.Collection b)
Collection
containing the exclusive disjunction
(symmetric difference) of the given Collection
s.
The cardinality of each element e in the returned Collection
will be equal to
max(cardinality(e,a),cardinality(e,b)) - min(cardinality(e,a),cardinality(e,b)).
This is equivalent to
subtract
(union(a,b)
,intersection(a,b)
)
or
union
(subtract(a,b)
,subtract(b,a)
).
public static java.util.Collection subtract(java.util.Collection a, java.util.Collection b)
Collection
containing a - b.
The cardinality of each element e in the returned Collection
will be the cardinality of e in a minus the cardinality
of e in b, or zero, whichever is greater.
Collection.removeAll(java.util.Collection)
public static boolean containsAny(java.util.Collection a, java.util.Collection b)
true
iff some element of a
is also an element of b (or, equivalently, if
some element of b is also an element of a).
In other words, this method returns true
iff the intersection(java.util.Collection, java.util.Collection)
of a and b
is not empty.
a
- a non-null
Collectionb
- a non-null
Collection
true
iff the intersection of a and b is non-emptyintersection(java.util.Collection, java.util.Collection)
public static java.util.Map getCardinalityMap(java.util.Collection col)
Map
mapping each unique element in
the given Collection
to an Integer
representing the number of occurances of that element
in the Collection
.
An entry that maps to null indicates that the
element does not appear in the given Collection
.
public static boolean isSubCollection(java.util.Collection a, java.util.Collection b)
isProperSubCollection(java.util.Collection, java.util.Collection)
,
Collection.containsAll(java.util.Collection)
public static boolean isProperSubCollection(java.util.Collection a, java.util.Collection b)
isSubCollection(java.util.Collection, java.util.Collection)
,
Collection.containsAll(java.util.Collection)
public static boolean isEqualCollection(java.util.Collection a, java.util.Collection b)
Collection
s contain
exactly the same elements with exactly the same cardinality.
That is, iff the cardinality of e in a is equal to the cardinality of e in b, for each element e in a or b.
public static int cardinality(java.lang.Object obj, java.util.Collection col)
public static java.lang.Object find(java.util.Collection collection, Predicate predicate)
If the input collection or predicate is null, null is returned.
collection
- the collection to search, may be nullpredicate
- the predicate to use, may be null
public static void forAllDo(java.util.Collection collection, Closure closure)
If the input collection is null, there is no change made.
collection
- the collection to get the input from, may be nullclosure
- the closure to perform, may not be null
java.lang.NullPointerException
- if the closure is nullpublic static void filter(java.util.Collection collection, Predicate predicate)
If the input collection or predicate is null, there is no change made.
collection
- the collection to get the input from, may be nullpredicate
- the predicate to use as a filter, may be nullpublic static void transform(java.util.Collection collection, Transformer transformer)
If the input collection or transformer is null, there is no change made.
This routine is best for Lists and uses set(), however it adapts for all Collections that support clear() and addAll().
If the input collection controls its input, such as a Set, and the Transformer creates duplicates (or are otherwise invalid), the collection may reduce in size due to calling this method.
collection
- the collection to get the input from, may be nulltransformer
- the transformer to perform, may be nullpublic static java.util.Collection select(java.util.Collection inputCollection, Predicate predicate)
inputCollection
- the collection to get the input from, may not be nullpredicate
- the predicate to use, may be null
java.lang.NullPointerException
- if the input collection is nullpublic static void select(java.util.Collection inputCollection, Predicate predicate, java.util.Collection outputCollection)
If the input collection or predicate is null, there is no change to the output collection.
inputCollection
- the collection to get the input from, may be nullpredicate
- the predicate to use, may be nulloutputCollection
- the collection to output into, may not be null
java.lang.NullPointerException
- if the input collection is nullpublic static java.util.Collection collect(java.util.Collection inputCollection, Transformer transformer)
If the input transfomer is null, the result is an empty list.
inputCollection
- the collection to get the input from, may not be nulltransformer
- the transformer to use, may be null
java.lang.NullPointerException
- if the input collection is nullpublic static java.util.Collection collect(java.util.Iterator inputIterator, Transformer transformer)
If the input iterator or transfomer is null, the result is an empty list.
inputIterator
- the iterator to get the input from, may be nulltransformer
- the transformer to use, may be null
public static java.util.Collection collect(java.util.Collection inputCollection, Transformer transformer, java.util.Collection outputCollection)
If the input collection or transfomer is null, there is no change to the output collection.
inputCollection
- the collection to get the input from, may be nulltransformer
- the transformer to use, may be nulloutputCollection
- the collection to output into, may not be null
java.lang.NullPointerException
- if the output collection is nullpublic static java.util.Collection collect(java.util.Iterator inputIterator, Transformer transformer, java.util.Collection outputCollection)
If the input iterator or transfomer is null, there is no change to the output collection.
inputIterator
- the iterator to get the input from, may be nulltransformer
- the transformer to use, may be nulloutputCollection
- the collection to output into, may not be null
java.lang.NullPointerException
- if the output collection is nullpublic static void addAll(java.util.Collection collection, java.util.Iterator iterator)
collection
- the collection to add toiterator
- the iterator of elements to add, may not be null
java.lang.NullPointerException
- if the collection or iterator is nullpublic static void addAll(java.util.Collection collection, java.util.Enumeration enumeration)
collection
- the collection to add toenumeration
- the enumeration of elements to add, may not be null
java.lang.NullPointerException
- if the collection or enumeration is nullpublic static void addAll(java.util.Collection collection, java.lang.Object[] elements)
collection
- the collection to add toelements
- the array of elements to add, may be null
java.lang.NullPointerException
- if the collection or array is nullpublic static java.lang.Object index(java.lang.Object obj, int idx)
obj
- the object to get an index of
java.lang.IndexOutOfBoundsException
java.util.NoSuchElementException
public static java.lang.Object index(java.lang.Object obj, java.lang.Object index)
obj
- the object to get an index ofindex
- the index to get
java.lang.IndexOutOfBoundsException
java.util.NoSuchElementException
public static java.util.Iterator getIterator(java.lang.Object obj)
public static void reverseArray(java.lang.Object[] array)
public static java.util.Collection predicatedCollection(java.util.Collection collection, Predicate predicate)
collection
- the collection to predicate, must not be nullpredicate
- the predicate for the collection, must not be null
java.lang.IllegalArgumentException
- if the Collection is null
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |