| java.lang.Object org.apache.commons.collections.CollectionUtils
CollectionUtils | public class CollectionUtils (Code) | | Provides utility methods and decorators for
Collection instances.
since: Commons Collections 1.0 version: $Revision: 348013 $ $Date: 2005-11-21 23:24:45 +0000 (Mon, 21 Nov 2005) $ author: Rodney Waldhoff author: Paul Jack author: Stephen Colebourne author: Steve Downey author: Herve Quiroz author: Peter KoBek author: Matthew Hawthorne author: Janek Bogucki author: Phil Steitz author: Steven Melzer author: Jon Schewe author: Neil O'Toole author: Stephen Smith |
Field Summary | |
final public static Collection | EMPTY_COLLECTION An empty unmodifiable collection.
The JDK provides empty Set and List implementations which could be used for
this purpose. |
Constructor Summary | |
public | CollectionUtils() CollectionUtils should not normally be instantiated. |
Method Summary | |
public static void | addAll(Collection collection, Iterator iterator) Adds all elements in the iteration to the given collection. | public static void | addAll(Collection collection, Enumeration enumeration) Adds all elements in the enumeration to the given collection. | public static void | addAll(Collection collection, Object[] elements) Adds all elements in the array to the given collection. | public static boolean | addIgnoreNull(Collection collection, Object object) Adds an element to the collection unless the element is null. | public static int | cardinality(Object obj, Collection coll) Returns the number of occurrences of obj in coll. | public static Collection | collect(Collection inputCollection, Transformer transformer) Returns a new Collection consisting of the elements of inputCollection transformed
by the given transformer. | public static Collection | collect(Iterator inputIterator, Transformer transformer) Transforms all elements from the inputIterator with the given transformer
and adds them to the outputCollection. | public static Collection | collect(Collection inputCollection, Transformer transformer, Collection outputCollection) Transforms all elements from inputCollection with the given transformer
and adds them to the outputCollection. | public 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. | public static boolean | containsAny(Collection coll1, Collection coll2) Returns true iff at least one element is in both collections. | public static int | countMatches(Collection inputCollection, Predicate predicate) Counts the number of elements in the input collection that match the predicate. | public static Collection | disjunction(Collection a, Collection b) Returns a
Collection containing the exclusive disjunction
(symmetric difference) of the given
Collection s. | public static boolean | exists(Collection collection, Predicate predicate) Answers true if a predicate is true for at least one element of a collection. | public static void | filter(Collection collection, Predicate predicate) Filter the collection by applying a Predicate to each element. | public static Object | find(Collection collection, Predicate predicate) Finds the first element in the given collection which matches the given predicate. | public static void | forAllDo(Collection collection, Closure closure) Executes the given closure on each element in the collection. | public 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.
The supported types, and associated semantics are:
- Map -- the value returned is the
Map.Entry in position
index in the map's entrySet iterator,
if there is such an entry.
- List -- this method is equivalent to the list's get method.
- Array -- the
index -th array entry is returned,
if there is such an entry; otherwise an IndexOutOfBoundsException
is thrown.
- Collection -- the value returned is the
index -th object
returned by the collection's default iterator, if there is such an element.
- Iterator or Enumeration -- the value returned is the
index -th object in the Iterator/Enumeration, if there
is such an element. | public static Map | getCardinalityMap(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 . | public static Object | index(Object obj, int idx) Given an Object, and an index, returns the nth value in the
object.
- If obj is a Map, returns the nth value from the keySet iterator, unless
the Map contains an Integer key with integer value = idx, in which case the
corresponding map entry value is returned.
| public static Object | index(Object obj, Object index) Given an Object, and a key (index), returns the value associated with
that key in the Object. | public static Collection | intersection(Collection a, Collection b) Returns a
Collection containing the intersection
of the given
Collection s. | public static boolean | isEmpty(Collection coll) Null-safe check if the specified collection is empty. | public static boolean | isEqualCollection(Collection a, Collection b) Returns true iff the given
Collection s contain
exactly the same elements with exactly the same cardinalities. | public static boolean | isFull(Collection coll) Returns true if no more elements can be added to the Collection.
This method uses the
BoundedCollection interface to determine the
full status. | public static boolean | isNotEmpty(Collection coll) Null-safe check if the specified collection is not empty. | public 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.
The implementation assumes
a.size() and b.size() represent the
total cardinality of a and b, resp. | public 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. | public static int | maxSize(Collection coll) Get the maximum number of elements that the Collection can contain.
This method uses the
BoundedCollection interface to determine the
maximum size. | public static Collection | predicatedCollection(Collection collection, Predicate predicate) Returns a predicated (validating) collection backed by the given collection. | public static Collection | removeAll(Collection collection, Collection remove) Removes the elements in remove from collection . | public static Collection | retainAll(Collection collection, Collection retain) Returns a collection containing all the elements in collection
that are also in retain . | public static void | reverseArray(Object[] array) Reverses the order of the given array. | public static Collection | select(Collection inputCollection, Predicate predicate) Selects all elements from input collection which match the given predicate
into an output collection. | public 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. | public static Collection | selectRejected(Collection inputCollection, Predicate predicate) Selects all elements from inputCollection which don't match the given predicate
into an output collection. | public 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. | public static int | size(Object object) Gets the size of the collection/iterator specified. | public static boolean | sizeIsEmpty(Object object) Checks if the specified collection/array/iterator is empty. | public static Collection | subtract(Collection a, Collection b) Returns a new
Collection containing a - b. | public static Collection | synchronizedCollection(Collection collection) Returns a synchronized collection backed by the given collection. | public static void | transform(Collection collection, Transformer transformer) Transform the collection by applying a Transformer to each element.
If the input collection or transformer is null, there is no change made.
This routine is best for Lists, for which set() is used to do the
transformations "in place." For other Collections, clear() and addAll()
are used to replace elements. | public static Collection | transformedCollection(Collection collection, Transformer transformer) Returns a transformed bag backed by the given collection.
Each object is passed through the transformer as it is added to the
Collection. | public static Collection | typedCollection(Collection collection, Class type) Returns a typed collection backed by the given collection. | public static Collection | union(Collection a, Collection b) Returns a
Collection containing the union
of the given
Collection s. | public static Collection | unmodifiableCollection(Collection collection) Returns an unmodifiable collection backed by the given collection. |
EMPTY_COLLECTION | final public static Collection EMPTY_COLLECTION(Code) | | An empty unmodifiable collection.
The JDK provides empty Set and List implementations which could be used for
this purpose. However they could be cast to Set or List which might be
undesirable. This implementation only implements Collection.
|
CollectionUtils | public CollectionUtils()(Code) | | CollectionUtils should not normally be instantiated.
|
addAll | public static void addAll(Collection collection, Iterator iterator)(Code) | | Adds all elements in the iteration to the given collection.
Parameters: collection - the collection to add to, must not be null Parameters: iterator - the iterator of elements to add, must not be null throws: NullPointerException - if the collection or iterator is null |
addAll | public static void addAll(Collection collection, Enumeration enumeration)(Code) | | Adds all elements in the enumeration to the given collection.
Parameters: collection - the collection to add to, must not be null Parameters: enumeration - the enumeration of elements to add, must not be null throws: NullPointerException - if the collection or enumeration is null |
addAll | public static void addAll(Collection collection, Object[] elements)(Code) | | Adds all elements in the array to the given collection.
Parameters: collection - the collection to add to, must not be null Parameters: elements - the array of elements to add, must not be null throws: NullPointerException - if the collection or array is null |
addIgnoreNull | public static boolean addIgnoreNull(Collection collection, Object object)(Code) | | Adds an element to the collection unless the element is null.
Parameters: collection - the collection to add to, must not be null Parameters: object - the object to add, if null it will not be added true if the collection changed throws: NullPointerException - if the collection is null since: Commons Collections 3.2 |
cardinality | public static int cardinality(Object obj, Collection coll)(Code) | | Returns the number of occurrences of obj in coll.
Parameters: obj - the object to find the cardinality of Parameters: coll - the collection to search the the number of occurrences of obj in coll |
collect | public static Collection collect(Collection inputCollection, Transformer transformer)(Code) | | Returns a new Collection consisting of the elements of inputCollection transformed
by the given transformer.
If the input transformer is null, the result is an empty list.
Parameters: inputCollection - the collection to get the input from, may not be null Parameters: transformer - the transformer to use, may be null the transformed result (new list) throws: NullPointerException - if the input collection is null |
collect | public static Collection collect(Iterator inputIterator, Transformer transformer)(Code) | | Transforms all elements from the inputIterator with the given transformer
and adds them to the outputCollection.
If the input iterator or transformer is null, the result is an empty list.
Parameters: inputIterator - the iterator to get the input from, may be null Parameters: transformer - the transformer to use, may be null the transformed result (new list) |
collect | public static Collection collect(Collection inputCollection, Transformer transformer, Collection outputCollection)(Code) | | Transforms all elements from inputCollection with the given transformer
and adds them to the outputCollection.
If the input collection or transformer is null, there is no change to the
output collection.
Parameters: inputCollection - the collection to get the input from, may be null Parameters: transformer - the transformer to use, may be null Parameters: outputCollection - the collection to output into, may not be null the outputCollection with the transformed input added throws: NullPointerException - if the output collection is null |
collect | public static Collection collect(Iterator inputIterator, Transformer transformer, Collection outputCollection)(Code) | | Transforms all elements from the inputIterator with the given transformer
and adds them to the outputCollection.
If the input iterator or transformer is null, there is no change to the
output collection.
Parameters: inputIterator - the iterator to get the input from, may be null Parameters: transformer - the transformer to use, may be null Parameters: outputCollection - the collection to output into, may not be null the outputCollection with the transformed input added throws: NullPointerException - if the output collection is null |
containsAny | public static boolean containsAny(Collection coll1, Collection coll2)(Code) | | Returns true iff at least one element is in both collections.
In other words, this method returns true iff the
CollectionUtils.intersection of coll1 and coll2 is not empty.
Parameters: coll1 - the first collection, must not be null Parameters: coll2 - the first collection, must not be null true iff the intersection of the collections is non-empty since: 2.1 See Also: CollectionUtils.intersection |
countMatches | public static int countMatches(Collection inputCollection, Predicate predicate)(Code) | | Counts the number of elements in the input collection that match the predicate.
A null collection or predicate matches no elements.
Parameters: inputCollection - the collection to get the input from, may be null Parameters: predicate - the predicate to use, may be null the number of matches for the predicate in the collection |
disjunction | public static Collection disjunction(Collection a, Collection b)(Code) | | Returns a
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
CollectionUtils.subtract subtract (
CollectionUtils.union union(a,b) ,
CollectionUtils.intersection intersection(a,b) )
or
CollectionUtils.union union (
CollectionUtils.subtract subtract(a,b) ,
CollectionUtils.subtract subtract(b,a) ).
Parameters: a - the first collection, must not be null Parameters: b - the second collection, must not be null the symmetric difference of the two collections |
exists | public static boolean exists(Collection collection, Predicate predicate)(Code) | | Answers true if a predicate is true for at least one element of a collection.
A null collection or predicate returns false.
Parameters: collection - the collection to get the input from, may be null Parameters: predicate - the predicate to use, may be null true if at least one element of the collection matches the predicate |
filter | public static void filter(Collection collection, Predicate predicate)(Code) | | Filter the collection by applying a Predicate to each element. If the
predicate returns false, remove the element.
If the input collection or predicate is null, there is no change made.
Parameters: collection - the collection to get the input from, may be null Parameters: predicate - the predicate to use as a filter, may be null |
find | public static Object find(Collection collection, Predicate predicate)(Code) | | Finds the first element in the given collection which matches the given predicate.
If the input collection or predicate is null, or no element of the collection
matches the predicate, null is returned.
Parameters: collection - the collection to search, may be null Parameters: predicate - the predicate to use, may be null the first element of the collection which matches the predicate or null if none could be found |
forAllDo | public static void forAllDo(Collection collection, Closure closure)(Code) | | Executes the given closure on each element in the collection.
If the input collection or closure is null, there is no change made.
Parameters: collection - the collection to get the input from, may be null Parameters: closure - the closure to perform, may be null |
get | public static Object get(Object object, int index)(Code) | | 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.
The supported types, and associated semantics are:
- Map -- the value returned is the
Map.Entry in position
index in the map's entrySet iterator,
if there is such an entry.
- List -- this method is equivalent to the list's get method.
- Array -- the
index -th array entry is returned,
if there is such an entry; otherwise an IndexOutOfBoundsException
is thrown.
- Collection -- the value returned is the
index -th object
returned by the collection's default iterator, if there is such an element.
- Iterator or Enumeration -- the value returned is the
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.
Parameters: object - the object to get a value from Parameters: index - the index to get the object at the specified index throws: IndexOutOfBoundsException - if the index is invalid throws: IllegalArgumentException - if the object type is invalid |
getCardinalityMap | public static Map getCardinalityMap(Collection coll)(Code) | | 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 .
Only those elements present in the collection will appear as
keys in the map.
Parameters: coll - the collection to get the cardinality map for, must not be null the populated cardinality map |
index | public static Object index(Object obj, int idx)(Code) | | Given an Object, and an index, returns the nth value in the
object.
- If obj is a Map, returns the nth value from the keySet iterator, unless
the Map contains an Integer key with integer value = idx, in which case the
corresponding map entry value is returned. If idx exceeds the number of entries in
the map, an empty Iterator is returned.
- If obj is a List or an array, returns the nth value, throwing IndexOutOfBoundsException,
ArrayIndexOutOfBoundsException, resp. if the nth value does not exist.
- If obj is an iterator, enumeration or Collection, returns the nth value from the iterator,
returning an empty Iterator (resp. Enumeration) if the nth value does not exist.
- Returns the original obj if it is null or not a Collection or Iterator.
Parameters: obj - the object to get an index of, may be null Parameters: idx - the index to get throws: IndexOutOfBoundsException - throws: ArrayIndexOutOfBoundsException - CollectionUtils.get(Object,int) |
index | public static Object index(Object obj, Object index)(Code) | | Given an Object, and a key (index), returns the value associated with
that key in the Object. The following checks are made:
- If obj is a Map, use the index as a key to get a value. If no match continue.
- Check key is an Integer. If not, return the object passed in.
- If obj is a Map, get the nth value from the keySet iterator.
If the Map has fewer than n entries, return an empty Iterator.
- If obj is a List or an array, get the nth value, throwing IndexOutOfBoundsException,
ArrayIndexOutOfBoundsException, resp. if the nth value does not exist.
- If obj is an iterator, enumeration or Collection, get the nth value from the iterator,
returning an empty Iterator (resp. Enumeration) if the nth value does not exist.
- Return the original obj.
Parameters: obj - the object to get an index of Parameters: index - the index to get the object at the specified index throws: IndexOutOfBoundsException - throws: ArrayIndexOutOfBoundsException - CollectionUtils.get(Object,int) |
isEmpty | public static boolean isEmpty(Collection coll)(Code) | | Null-safe check if the specified collection is empty.
Null returns true.
Parameters: coll - the collection to check, may be null true if empty or null since: Commons Collections 3.2 |
isEqualCollection | public static boolean isEqualCollection(Collection a, Collection b)(Code) | | Returns true iff the given
Collection s contain
exactly the same elements with exactly the same cardinalities.
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.
Parameters: a - the first collection, must not be null Parameters: b - the second collection, must not be null true iff the collections contain the same elements with the same cardinalities. |
isFull | public static boolean isFull(Collection coll)(Code) | | Returns true if no more elements can be added to the Collection.
This method uses the
BoundedCollection interface to determine the
full status. If the collection does not implement this interface then
false is returned.
The collection does not have to implement this interface directly.
If the collection has been decorated using the decorators subpackage
then these will be removed to access the BoundedCollection.
Parameters: coll - the collection to check true if the BoundedCollection is full throws: NullPointerException - if the collection is null |
isNotEmpty | public static boolean isNotEmpty(Collection coll)(Code) | | Null-safe check if the specified collection is not empty.
Null returns false.
Parameters: coll - the collection to check, may be null true if non-null and non-empty since: Commons Collections 3.2 |
isProperSubCollection | public static boolean isProperSubCollection(Collection a, Collection b)(Code) | | 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.
The implementation assumes
a.size() and b.size() represent the
total cardinality of a and b, resp.
a.size() < Integer.MAXVALUE
Parameters: a - the first (sub?) collection, must not be null Parameters: b - the second (super?) collection, must not be null true iff a is a proper sub-collection of b See Also: CollectionUtils.isSubCollection See Also: Collection.containsAll |
isSubCollection | public static boolean isSubCollection(Collection a, Collection b)(Code) | | 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.
Parameters: a - the first (sub?) collection, must not be null Parameters: b - the second (super?) collection, must not be null true iff a is a sub-collection of b See Also: CollectionUtils.isProperSubCollection See Also: Collection.containsAll |
maxSize | public static int maxSize(Collection coll)(Code) | | Get the maximum number of elements that the Collection can contain.
This method uses the
BoundedCollection interface to determine the
maximum size. If the collection does not implement this interface then
-1 is returned.
The collection does not have to implement this interface directly.
If the collection has been decorated using the decorators subpackage
then these will be removed to access the BoundedCollection.
Parameters: coll - the collection to check the maximum size of the BoundedCollection, -1 if no maximum size throws: NullPointerException - if the collection is null |
predicatedCollection | public static Collection predicatedCollection(Collection collection, Predicate predicate)(Code) | | Returns a predicated (validating) collection backed by the given collection.
Only objects that pass the test in the given predicate can be added to the collection.
Trying to add an invalid object results in an IllegalArgumentException.
It is important not to use the original collection after invoking this method,
as it is a backdoor for adding invalid objects.
Parameters: collection - the collection to predicate, must not be null Parameters: predicate - the predicate for the collection, must not be null a predicated collection backed by the given collection throws: IllegalArgumentException - if the Collection is null |
removeAll | public static Collection removeAll(Collection collection, Collection remove)(Code) | | Removes the elements in remove from collection . That is, this
method returns a collection containing all the elements in c
that are not in remove . The cardinality of an element e
in the returned collection is the same as the cardinality of e
in collection unless remove contains e , in which
case the cardinality is zero. This method is useful if you do not wish to modify
the collection c and thus cannot call collection.removeAll(remove); .
Parameters: collection - the collection from which items are removed (in the returned collection) Parameters: remove - the items to be removed from the returned collection a Collection containing all the elements of collection exceptany elements that also occur in remove . throws: NullPointerException - if either parameter is null since: Commons Collections 3.2 |
retainAll | public static Collection retainAll(Collection collection, Collection retain)(Code) | | Returns a collection containing all the elements in collection
that are also in retain . The cardinality of an element e
in the returned collection is the same as the cardinality of e
in collection unless retain does not contain e , in which
case the cardinality is zero. This method is useful if you do not wish to modify
the collection c and thus cannot call c.retainAll(retain); .
Parameters: collection - the collection whose contents are the target of the #retailAll operation Parameters: retain - the collection containing the elements to be retained in the returned collection a Collection containing all the elements of collection that occur at least once in retain . throws: NullPointerException - if either parameter is null since: Commons Collections 3.2 |
reverseArray | public static void reverseArray(Object[] array)(Code) | | Reverses the order of the given array.
Parameters: array - the array to reverse |
select | public static Collection select(Collection inputCollection, Predicate predicate)(Code) | | Selects all elements from input collection which match the given predicate
into an output collection.
A null predicate matches no elements.
Parameters: inputCollection - the collection to get the input from, may not be null Parameters: predicate - the predicate to use, may be null the elements matching the predicate (new list) throws: NullPointerException - if the input collection is null |
select | public static void select(Collection inputCollection, Predicate predicate, Collection outputCollection)(Code) | | Selects all elements from input collection which match the given predicate
and adds them to outputCollection.
If the input collection or predicate is null, there is no change to the
output collection.
Parameters: inputCollection - the collection to get the input from, may be null Parameters: predicate - the predicate to use, may be null Parameters: outputCollection - the collection to output into, may not be null |
selectRejected | public static Collection selectRejected(Collection inputCollection, Predicate predicate)(Code) | | Selects all elements from inputCollection which don't match the given predicate
into an output collection.
If the input predicate is null , the result is an empty list.
Parameters: inputCollection - the collection to get the input from, may not be null Parameters: predicate - the predicate to use, may be null the elements not matching the predicate (new list) throws: NullPointerException - if the input collection is null |
selectRejected | public static void selectRejected(Collection inputCollection, Predicate predicate, Collection outputCollection)(Code) | | Selects all elements from inputCollection which don't match the given predicate
and adds them to outputCollection.
If the input predicate is null , no elements are added to outputCollection .
Parameters: inputCollection - the collection to get the input from, may be null Parameters: predicate - the predicate to use, may be null Parameters: outputCollection - the collection to output into, may not be null |
size | public static int size(Object object)(Code) | | Gets the size of the collection/iterator specified.
This method can handles objects as follows
- Collection - the collection size
- Map - the map size
- Array - the array size
- Iterator - the number of elements remaining in the iterator
- Enumeration - the number of elements remaining in the enumeration
Parameters: object - the object to get the size of the size of the specified collection throws: IllegalArgumentException - thrown if object is not recognised or null since: Commons Collections 3.1 |
sizeIsEmpty | public static boolean sizeIsEmpty(Object object)(Code) | | Checks if the specified collection/array/iterator is empty.
This method can handles objects as follows
- Collection - via collection isEmpty
- Map - via map isEmpty
- Array - using array size
- Iterator - via hasNext
- Enumeration - via hasMoreElements
Note: This method is named to avoid clashing with
CollectionUtils.isEmpty(Collection) .
Parameters: object - the object to get the size of, not null true if empty throws: IllegalArgumentException - thrown if object is not recognised or null since: Commons Collections 3.2 |
subtract | public static Collection subtract(Collection a, Collection b)(Code) | | Returns a new
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.
Parameters: a - the collection to subtract from, must not be null Parameters: b - the collection to subtract, must not be null a new collection with the results See Also: Collection.removeAll |
synchronizedCollection | public static Collection synchronizedCollection(Collection collection)(Code) | | Returns a synchronized collection backed by the given collection.
You must manually synchronize on the returned buffer's iterator to
avoid non-deterministic behavior:
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.
Parameters: collection - the collection to synchronize, must not be null a synchronized collection backed by the given collection throws: IllegalArgumentException - if the collection is null |
transform | public static void transform(Collection collection, Transformer transformer)(Code) | | Transform the collection by applying a Transformer to each element.
If the input collection or transformer is null, there is no change made.
This routine is best for Lists, for which set() is used to do the
transformations "in place." For other Collections, clear() and addAll()
are used to replace elements.
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.
Parameters: collection - the collection to get the input from, may be null Parameters: transformer - the transformer to perform, may be null |
transformedCollection | public static Collection transformedCollection(Collection collection, Transformer transformer)(Code) | | Returns a transformed bag backed by the given collection.
Each object is passed through the transformer as it is added to the
Collection. It is important not to use the original collection after invoking this
method, as it is a backdoor for adding untransformed objects.
Parameters: collection - the collection to predicate, must not be null Parameters: transformer - the transformer for the collection, must not be null a transformed collection backed by the given collection throws: IllegalArgumentException - if the Collection or Transformer is null |
typedCollection | public static Collection typedCollection(Collection collection, Class type)(Code) | | Returns a typed collection backed by the given collection.
Only objects of the specified type can be added to the collection.
Parameters: collection - the collection to limit to a specific type, must not be null Parameters: type - the type of objects which may be added to the collection a typed collection backed by the specified collection |
unmodifiableCollection | public static Collection unmodifiableCollection(Collection collection)(Code) | | Returns an unmodifiable collection backed by the given collection.
This method uses the implementation in the decorators subpackage.
Parameters: collection - the collection to make unmodifiable, must not be null an unmodifiable collection backed by the given collection throws: IllegalArgumentException - if the collection is null |
|
|