E
- the type of the elements in the collectionjava.io.Serializable
, java.lang.Iterable<E>
, java.util.Collection<E>
public class CompositeCollection<E>
extends java.lang.Object
implements java.util.Collection<E>, java.io.Serializable
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.
Modifier and Type | Class | Description |
---|---|---|
static interface |
CompositeCollection.CollectionMutator<E> |
Pluggable strategy to handle changes to the composite.
|
Constructor | Description |
---|---|
CompositeCollection() |
Create an empty CompositeCollection.
|
CompositeCollection(java.util.Collection<E> compositeCollection) |
Create a Composite Collection with one collection.
|
CompositeCollection(java.util.Collection<E>... compositeCollections) |
Create a Composite Collection with an array of collections.
|
CompositeCollection(java.util.Collection<E> compositeCollection1,
java.util.Collection<E> compositeCollection2) |
Create a Composite Collection with two collections.
|
Modifier and Type | Method | Description |
---|---|---|
boolean |
add(E obj) |
Adds an object to the collection, throwing UnsupportedOperationException
unless a CollectionMutator strategy is specified.
|
boolean |
addAll(java.util.Collection<? extends E> coll) |
Adds a collection of elements to this collection, throwing
UnsupportedOperationException unless a CollectionMutator strategy is specified.
|
void |
addComposited(java.util.Collection<E> compositeCollection) |
Add these Collections to the list of collections in this composite
|
void |
addComposited(java.util.Collection<E>... compositeCollections) |
Add these Collections to the list of collections in this composite
|
void |
addComposited(java.util.Collection<E> compositeCollection1,
java.util.Collection<E> compositeCollection2) |
Add these Collections to the list of collections in this composite
|
void |
clear() |
Removes all of the elements from this collection .
|
boolean |
contains(java.lang.Object obj) |
Checks whether this composite collection contains the object.
|
boolean |
containsAll(java.util.Collection<?> coll) |
Checks whether this composite contains all the elements in the specified collection.
|
java.util.List<java.util.Collection<E>> |
getCollections() |
Gets the collections being decorated.
|
protected CompositeCollection.CollectionMutator<E> |
getMutator() |
Get the collection mutator to be used for this CompositeCollection.
|
boolean |
isEmpty() |
Checks whether this composite collection is empty.
|
java.util.Iterator<E> |
iterator() |
Gets an iterator over all the collections in this composite.
|
boolean |
remove(java.lang.Object obj) |
Removes an object from the collection, throwing UnsupportedOperationException
unless a CollectionMutator strategy is specified.
|
boolean |
removeAll(java.util.Collection<?> coll) |
Removes the elements in the specified collection from this composite collection.
|
void |
removeComposited(java.util.Collection<E> coll) |
Removes a collection from the those being decorated in this composite.
|
boolean |
retainAll(java.util.Collection<?> coll) |
Retains all the elements in the specified collection in this composite collection,
removing all others.
|
void |
setMutator(CompositeCollection.CollectionMutator<E> mutator) |
Specify a CollectionMutator strategy instance to handle changes.
|
int |
size() |
Gets the size of this composite collection.
|
java.lang.Object[] |
toArray() |
Returns an array containing all of the elements in this composite.
|
<T> T[] |
toArray(T[] array) |
Returns an object array, populating the supplied array if possible.
|
java.util.Collection<E> |
toCollection() |
Returns a new collection containing all of the elements
|
public CompositeCollection()
public CompositeCollection(java.util.Collection<E> compositeCollection)
compositeCollection
- the Collection to be appended to the compositepublic CompositeCollection(java.util.Collection<E> compositeCollection1, java.util.Collection<E> compositeCollection2)
compositeCollection1
- the Collection to be appended to the compositecompositeCollection2
- the Collection to be appended to the compositepublic CompositeCollection(java.util.Collection<E>... compositeCollections)
compositeCollections
- the collections to compositepublic int size()
This implementation calls size()
on each collection.
size
in interface java.util.Collection<E>
public boolean isEmpty()
This implementation calls isEmpty()
on each collection.
isEmpty
in interface java.util.Collection<E>
public boolean contains(java.lang.Object obj)
This implementation calls contains()
on each collection.
contains
in interface java.util.Collection<E>
obj
- the object to search forpublic java.util.Iterator<E> iterator()
This implementation uses an IteratorChain
.
iterator
in interface java.util.Collection<E>
iterator
in interface java.lang.Iterable<E>
IteratorChain
instance which supports
remove()
. Iteration occurs over contained collections in
the order they were added, but this behavior should not be relied upon.IteratorChain
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<E>
public <T> T[] toArray(T[] array)
Collection
interface for full details.toArray
in interface java.util.Collection<E>
T
- the type of the elements in the collectionarray
- the array to use, populating if possiblepublic boolean add(E obj)
add
in interface java.util.Collection<E>
obj
- the object to addtrue
if the collection was modifiedjava.lang.UnsupportedOperationException
- if CollectionMutator hasn't been setjava.lang.UnsupportedOperationException
- if add is unsupportedjava.lang.ClassCastException
- if the object cannot be added due to its typejava.lang.NullPointerException
- if the object cannot be added because its nulljava.lang.IllegalArgumentException
- if the object cannot be addedpublic boolean remove(java.lang.Object obj)
remove
in interface java.util.Collection<E>
obj
- the object being removedjava.lang.UnsupportedOperationException
- if removed is unsupportedjava.lang.ClassCastException
- if the object cannot be removed due to its typejava.lang.NullPointerException
- if the object cannot be removed because its nulljava.lang.IllegalArgumentException
- if the object cannot be removedpublic boolean containsAll(java.util.Collection<?> coll)
This implementation calls contains()
for each element in the
specified collection.
containsAll
in interface java.util.Collection<E>
coll
- the collection to check forpublic boolean addAll(java.util.Collection<? extends E> coll)
addAll
in interface java.util.Collection<E>
coll
- the collection to addjava.lang.UnsupportedOperationException
- if CollectionMutator hasn't been setjava.lang.UnsupportedOperationException
- if add is unsupportedjava.lang.ClassCastException
- if the object cannot be added due to its typejava.lang.NullPointerException
- if the object cannot be added because its nulljava.lang.IllegalArgumentException
- if the object cannot be addedpublic boolean removeAll(java.util.Collection<?> coll)
This implementation calls removeAll
on each collection.
removeAll
in interface java.util.Collection<E>
coll
- the collection to removejava.lang.UnsupportedOperationException
- if removeAll is unsupportedpublic boolean retainAll(java.util.Collection<?> coll)
This implementation calls retainAll()
on each collection.
retainAll
in interface java.util.Collection<E>
coll
- the collection to removejava.lang.UnsupportedOperationException
- if retainAll is unsupportedpublic void clear()
This implementation calls clear()
on each collection.
clear
in interface java.util.Collection<E>
java.lang.UnsupportedOperationException
- if clear is unsupportedpublic void setMutator(CompositeCollection.CollectionMutator<E> mutator)
mutator
- the mutator to usepublic void addComposited(java.util.Collection<E> compositeCollection)
compositeCollection
- the Collection to be appended to the compositepublic void addComposited(java.util.Collection<E> compositeCollection1, java.util.Collection<E> compositeCollection2)
compositeCollection1
- the Collection to be appended to the compositecompositeCollection2
- the Collection to be appended to the compositepublic void addComposited(java.util.Collection<E>... compositeCollections)
compositeCollections
- the Collections to be appended to the compositepublic void removeComposited(java.util.Collection<E> coll)
coll
- collection to be removedpublic java.util.Collection<E> toCollection()
public java.util.List<java.util.Collection<E>> getCollections()
protected CompositeCollection.CollectionMutator<E> getMutator()
Copyright © 2001-2019 - Apache Software Foundation