E - the type of the elements in the collection
public class CompositeCollection<E> extends Objectimplements Collection <E>, 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 and Description |
|---|---|
static interface |
CompositeCollection
Pluggable strategy to handle changes to the composite.
|
| Constructor and Description |
|---|
CompositeCollection()
Create an empty CompositeCollection.
|
CompositeCollection(Collection
Create a Composite Collection with an array of collections.
|
CompositeCollection(Collection
Create a Composite Collection with one collection.
|
CompositeCollection(Collection
Create a Composite Collection with two collections.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E obj)
Adds an object to the collection, throwing UnsupportedOperationException unless a CollectionMutator strategy is specified.
|
boolean |
addAll(Collection
Adds a collection of elements to this collection, throwing UnsupportedOperationException unless a CollectionMutator strategy is specified.
|
void |
addComposited(Collection
Add these Collections to the list of collections in this composite
|
void |
addComposited(Collection
Add these Collections to the list of collections in this composite
|
void |
addComposited(Collection
Add these Collections to the list of collections in this composite
|
void |
clear()
Removes all of the elements from this collection .
|
boolean |
contains(Object
Checks whether this composite collection contains the object.
|
boolean |
containsAll(Collection
Checks whether this composite contains all the elements in the specified collection.
|
List |
getCollections()
Gets the collections being decorated.
|
protected CompositeCollection |
getMutator()
Get the collection mutator to be used for this CompositeCollection.
|
boolean |
isEmpty()
Checks whether this composite collection is empty.
|
Iterator |
iterator()
Gets an iterator over all the collections in this composite.
|
boolean |
remove(Object
Removes an object from the collection, throwing UnsupportedOperationException unless a CollectionMutator strategy is specified.
|
boolean |
removeAll(Collection
Removes the elements in the specified collection from this composite collection.
|
void |
removeComposited(Collection
Removes a collection from the those being decorated in this composite.
|
boolean |
retainAll(Collection
Retains all the elements in the specified collection in this composite collection, removing all others.
|
void |
setMutator(CompositeCollection
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.
|
<T> T[] |
toArray(T[] array)
Returns an object array, populating the supplied array if possible.
|
Collection |
toCollection()
Returns a new collection containing all of the elements
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitequals, hashCode, parallelStream, removeIf, spliterator, streampublic CompositeCollection()
public CompositeCollection(Collection<E> compositeCollection)
compositeCollection - the Collection to be appended to the composite
public CompositeCollection(Collection<E> compositeCollection1, Collection <E> compositeCollection2)
compositeCollection1 - the Collection to be appended to the composite
compositeCollection2 - the Collection to be appended to the composite
public CompositeCollection(Collection<E>... compositeCollections)
compositeCollections - the collections to composite
public int size()
This implementation calls size() on each collection.
size in interface
Collection<E>
public boolean isEmpty()
This implementation calls isEmpty() on each collection.
isEmpty in interface
Collection<E>
public boolean contains(Objectobj)
This implementation calls contains() on each collection.
contains in interface
Collection<E>
obj - the object to search for
public Iterator<E> iterator()
This implementation uses an IteratorChain.
iterator in interface
Iterable<E>
iterator in interface
Collection<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 Object[] toArray()
toArray in interface
Collection<E>
public <T> T[] toArray(T[] array)
Collection interface for full details.
toArray in interface
Collection<E>
T - the type of the elements in the collection
array - the array to use, populating if possible
public boolean add(E obj)
add in interface
Collection<E>
obj - the object to add
true if the collection was modified
UnsupportedOperationException - if CollectionMutator hasn't been set
UnsupportedOperationException - if add is unsupported
ClassCastException - if the object cannot be added due to its type
NullPointerException - if the object cannot be added because its null
IllegalArgumentException - if the object cannot be added
public boolean remove(Objectobj)
remove in interface
Collection<E>
obj - the object being removed
UnsupportedOperationException - if removed is unsupported
ClassCastException - if the object cannot be removed due to its type
NullPointerException - if the object cannot be removed because its null
IllegalArgumentException - if the object cannot be removed
public boolean containsAll(Collection<?> coll)
This implementation calls contains() for each element in the specified collection.
containsAll in interface
Collection<E>
coll - the collection to check for
public boolean addAll(Collection<? extends E> coll)
addAll in interface
Collection<E>
coll - the collection to add
UnsupportedOperationException - if CollectionMutator hasn't been set
UnsupportedOperationException - if add is unsupported
ClassCastException - if the object cannot be added due to its type
NullPointerException - if the object cannot be added because its null
IllegalArgumentException - if the object cannot be added
public boolean removeAll(Collection<?> coll)
This implementation calls removeAll on each collection.
removeAll in interface
Collection<E>
coll - the collection to remove
UnsupportedOperationException - if removeAll is unsupported
public boolean retainAll(Collection<?> coll)
This implementation calls retainAll() on each collection.
retainAll in interface
Collection<E>
coll - the collection to remove
UnsupportedOperationException - if retainAll is unsupported
public void clear()
This implementation calls clear() on each collection.
clear in interface
Collection<E>
UnsupportedOperationException - if clear is unsupported
public void setMutator(CompositeCollection.CollectionMutator <E> mutator)
mutator - the mutator to use
public void addComposited(Collection<E> compositeCollection)
compositeCollection - the Collection to be appended to the composite
public void addComposited(Collection<E> compositeCollection1, Collection <E> compositeCollection2)
compositeCollection1 - the Collection to be appended to the composite
compositeCollection2 - the Collection to be appended to the composite
public void addComposited(Collection<E>... compositeCollections)
compositeCollections - the Collections to be appended to the composite
public void removeComposited(Collection<E> coll)
coll - collection to be removed
public Collection<E> toCollection()
public List<Collection <E>> getCollections()
protected CompositeCollection.CollectionMutator <E> getMutator()