org.apache.commons.collections.collection
Class CompositeCollection
java.lang.Object
org.apache.commons.collections.collection.CompositeCollection
- Collection
public class CompositeCollection
extends java.lang.Object
implements Collection
Decorates a collection of other collections to provide a single unified view.
Changes made to this collection will actually be made on the decorated collection.
Add and remove operations require the use of a pluggable strategy. If no
strategy is provided then add and remove are unsupported.
$Revision: 1.7 $ $Date: 2004/05/26 21:58:02 $- Brian McCallister
- Stephen Colebourne
- Phil Steitz
boolean | add(Object obj) - Adds an object to the collection, throwing UnsupportedOperationException
unless a CollectionMutator strategy is specified.
|
boolean | addAll(Collection coll) - Adds a collection of elements to this collection, throwing
UnsupportedOperationException unless a CollectionMutator strategy is specified.
|
void | addComposited(Collection c) - Add an additional collection to this composite.
|
void | addComposited(Collection c, Collection d) - Add two additional collections to this composite.
|
void | addComposited(Collection[] comps) - Add these Collections to the list of collections in this composite
|
void | clear() - Removes all of the elements from this collection .
|
boolean | contains(Object obj) - Checks whether this composite collection contains the object.
|
boolean | containsAll(Collection coll) - Checks whether this composite contains all the elements in the specified collection.
|
Collection | getCollections() - Gets the collections being decorated.
|
boolean | isEmpty() - Checks whether this composite collection is empty.
|
Iterator | iterator() - Gets an iterator over all the collections in this composite.
|
boolean | remove(Object obj) - Removes an object from the collection, throwing UnsupportedOperationException
unless a CollectionMutator strategy is specified.
|
boolean | removeAll(Collection coll) - Removes the elements in the specified collection from this composite collection.
|
void | removeComposited(Collection coll) - Removes a collection from the those being decorated in this composite.
|
boolean | retainAll(Collection coll) - Retains all the elements in the specified collection in this composite collection,
removing all others.
|
void | setMutator(CompositeCollection.CollectionMutator mutator) - Specify a CollectionMutator strategy instance to handle changes.
|
int | size() - Gets the size of this composite collection.
|
Object[] | toArray() - Returns an array containing all of the elements in this composite.
|
Object[] | toArray(Object[] array) - Returns an object array, populating the supplied array if possible.
|
Collection | toCollection() - Returns a new collection containing all of the elements
|
all
protected Collection[] all
Collections in the composite
CompositeCollection
public CompositeCollection()
Create an empty CompositeCollection.
CompositeCollection
public CompositeCollection(Collection coll)
Create a Composite Collection with only coll composited.
coll
- a collection to decorate
CompositeCollection
public CompositeCollection(Collection[] colls)
Create a CompositeCollection with colls as the initial list of
composited collections.
colls
- an array of collections to decorate
add
public boolean add(Object obj)
Adds an object to the collection, throwing UnsupportedOperationException
unless a CollectionMutator strategy is specified.
- true if the collection was modified
addAll
public boolean addAll(Collection coll)
Adds a collection of elements to this collection, throwing
UnsupportedOperationException unless a CollectionMutator strategy is specified.
coll
- the collection to add
- true if the collection was modified
addComposited
public void addComposited(Collection c)
Add an additional collection to this composite.
c
- the collection to add
addComposited
public void addComposited(Collection c,
Collection d)
Add two additional collections to this composite.
c
- the first collection to addd
- the second collection to add
addComposited
public void addComposited(Collection[] comps)
Add these Collections to the list of collections in this composite
comps
- Collections to be appended to the composite
clear
public void clear()
Removes all of the elements from this collection .
This implementation calls
clear()
on each collection.
contains
public boolean contains(Object obj)
Checks whether this composite collection contains the object.
This implementation calls
contains()
on each collection.
obj
- the object to search for
- true if obj is contained in any of the contained collections
containsAll
public boolean containsAll(Collection coll)
Checks whether this composite contains all the elements in the specified collection.
This implementation calls
contains()
for each element in the
specified collection.
coll
- the collection to check for
- true if all elements contained
getCollections
public Collection getCollections()
Gets the collections being decorated.
- Unmodifiable collection of all collections in this composite.
isEmpty
public boolean isEmpty()
Checks whether this composite collection is empty.
This implementation calls
isEmpty()
on each collection.
- true if all of the contained collections are empty
iterator
public Iterator iterator()
Gets an iterator over all the collections in this composite.
This implementation uses an
IteratorChain
.
- an
IteratorChain
instance which supports
remove()
. Iteration occurs over contained collections in
the order they were added, but this behavior should not be relied upon.
remove
public boolean remove(Object obj)
Removes an object from the collection, throwing UnsupportedOperationException
unless a CollectionMutator strategy is specified.
obj
- the object being removed
- true if the collection is changed
removeAll
public boolean removeAll(Collection coll)
Removes the elements in the specified collection from this composite collection.
This implementation calls
removeAll
on each collection.
coll
- the collection to remove
- true if the collection was modified
removeComposited
public void removeComposited(Collection coll)
Removes a collection from the those being decorated in this composite.
coll
- collection to be removed
retainAll
public boolean retainAll(Collection coll)
Retains all the elements in the specified collection in this composite collection,
removing all others.
This implementation calls
retainAll()
on each collection.
coll
- the collection to remove
- true if the collection was modified
size
public int size()
Gets the size of this composite collection.
This implementation calls
size()
on each collection.
- total number of elements in all contained containers
toArray
public Object[] toArray()
Returns an array containing all of the elements in this composite.
- an object array of all the elements in the collection
toArray
public Object[] toArray(Object[] array)
Returns an object array, populating the supplied array if possible.
See Collection
interface for full details.
array
- the array to use, populating if possible
- an array of all the elements in the collection
toCollection
public Collection toCollection()
Returns a new collection containing all of the elements
- A new ArrayList containing all of the elements in this composite.
The new collection is not backed by this composite.
Copyright © 2001-2006 Apache Software Foundation. All Rights Reserved.