|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | 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 Iterator |
EMPTY_ITERATOR
The empty iterator (immutable). |
Constructor Summary | |
CollectionUtils()
|
Method Summary | |
static void |
addAll(Collection collection,
Enumeration enumeration)
Adds all elements in the enumeration to the given collection |
static void |
addAll(Collection collection,
Iterator iterator)
Adds all elements in the iteration 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,
Collection col)
Returns the number of occurrences of obj in col. |
static Collection |
collect(Collection inputCollection,
Transformer transformer)
Transforms all elements from inputCollection with the given transformer and adds them to the outputCollection |
static Collection |
collect(Collection inputCollection,
Transformer transformer,
Collection outputCollection)
Transforms all elements from inputCollection with the given transformer and adds them to the outputCollection |
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(Iterator inputIterator,
Transformer transformer,
Collection outputCollection)
Transforms all elements from the inputIterator with the given transformer and adds them to the outputCollection |
static Collection |
disjunction(Collection a,
Collection b)
Returns a Collection containing the exclusive disjunction
(symmetric difference) of the given Collection s. |
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 colleciton |
static Map |
getCardinalityMap(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 Iterator |
getIterator(Object obj)
Returns an Iterator for the given object. |
static Object |
index(Object obj,
int idx)
Given an Object, and an index, it will get the nth value in the object. |
static Object |
index(Object obj,
Object index)
Given an Object, and an index, it will get the nth value in the object. |
static Collection |
intersection(Collection a,
Collection b)
Returns a Collection containing the intersection
of the given Collection s. |
static boolean |
isEqualCollection(Collection a,
Collection b)
Returns true iff the given Collection s contain
exactly the same elements with exactly the same cardinality. |
static boolean |
isProperSubCollection(Collection a,
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(Collection a,
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 void |
reverseArray(Object[] array)
Reverses the order of the given array |
static Collection |
select(Collection inputCollection,
Predicate predicate)
Selects all elements from inputCollection which match the given predicate into an output collection |
static void |
select(Collection inputCollection,
Predicate predicate,
Collection outputCollection)
Selects all elements from inputCollection which match the given predicate and adds them to outputCollection |
static Collection |
subtract(Collection a,
Collection b)
Returns a Collection containing a - b. |
static Collection |
union(Collection a,
Collection b)
Returns a Collection containing the union
of the given Collection s. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final Iterator EMPTY_ITERATOR
Constructor Detail |
public CollectionUtils()
Method Detail |
public static void addAll(Collection collection, Enumeration enumeration)
public static void addAll(Collection collection, Iterator iterator)
public static void addAll(Collection collection, Object[] elements)
public static int cardinality(Object obj, Collection col)
public static Collection collect(Collection inputCollection, Transformer transformer)
public static Collection collect(Collection inputCollection, Transformer transformer, Collection outputCollection)
public static Collection collect(Iterator inputIterator, Transformer transformer)
public static Collection collect(Iterator inputIterator, Transformer transformer, Collection outputCollection)
public static Collection disjunction(Collection a, 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 Object find(Collection collection, Predicate predicate)
public static void forAllDo(Collection collection, Closure closure)
public static Map getCardinalityMap(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 Iterator getIterator(Object obj)
public static Object index(Object obj, int idx)
public static Object index(Object obj, Object index)
public static Collection intersection(Collection a, 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)
public static boolean isEqualCollection(Collection a, 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 boolean isProperSubCollection(Collection a, Collection b)
isSubCollection(java.util.Collection, java.util.Collection)
,
Collection.containsAll(java.util.Collection)
public static boolean isSubCollection(Collection a, Collection b)
isProperSubCollection(java.util.Collection, java.util.Collection)
,
Collection.containsAll(java.util.Collection)
public static void reverseArray(Object[] array)
public static Collection select(Collection inputCollection, Predicate predicate)
public static void select(Collection inputCollection, Predicate predicate, Collection outputCollection)
public static Collection subtract(Collection a, 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 Collection union(Collection a, 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)
|
||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |