Class CompositeCollection<E>
- Type Parameters:
E- the type of the elements in the collection
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>
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.
- Since:
- 3.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacePluggable strategy to handle changes to the composite. -
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty CompositeCollection.CompositeCollection(Collection<E> compositeCollection) Create a Composite Collection with one collection.CompositeCollection(Collection<E>... compositeCollections) Create a Composite Collection with an array of collections.CompositeCollection(Collection<E> compositeCollection1, Collection<E> compositeCollection2) Create a Composite Collection with two collections. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds an object to the collection, throwing UnsupportedOperationException unless a CollectionMutator strategy is specified.booleanaddAll(Collection<? extends E> coll) Adds a collection of elements to this collection, throwing UnsupportedOperationException unless a CollectionMutator strategy is specified.voidaddComposited(Collection<E> compositeCollection) Add these Collections to the list of collections in this compositevoidaddComposited(Collection<E>... compositeCollections) Add these Collections to the list of collections in this compositevoidaddComposited(Collection<E> compositeCollection1, Collection<E> compositeCollection2) Add these Collections to the list of collections in this compositevoidclear()Removes all of the elements from this collection.booleanChecks whether this composite collection contains the object.booleancontainsAll(Collection<?> coll) Checks whether this composite contains all the elements in the specified collection.List<Collection<E>> Gets the collections being decorated.protected CompositeCollection.CollectionMutator<E> Gets the collection mutator to be used for this CompositeCollection.booleanisEmpty()Checks whether this composite collection is empty.iterator()Gets an iterator over all the collections in this composite.booleanRemoves an object from the collection, throwing UnsupportedOperationException unless a CollectionMutator strategy is specified.booleanremoveAll(Collection<?> coll) Removes the elements in the specified collection from this composite collection.voidremoveComposited(Collection<E> coll) Removes a collection from the those being decorated in this composite.booleanRemoves all of the elements of this collection that satisfy the given predicate from this composite collection.booleanretainAll(Collection<?> coll) Retains all the elements in the specified collection in this composite collection, removing all others.voidsetMutator(CompositeCollection.CollectionMutator<E> mutator) Specify a CollectionMutator strategy instance to handle changes.intsize()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.Returns a new collection containing all of the elementsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Collection
equals, hashCode, parallelStream, spliterator, stream
-
Constructor Details
-
CompositeCollection
public CompositeCollection()Create an empty CompositeCollection. -
CompositeCollection
Create a Composite Collection with one collection.- Parameters:
compositeCollection- the Collection to be appended to the composite
-
CompositeCollection
Create a Composite Collection with an array of collections.- Parameters:
compositeCollections- the collections to composite
-
CompositeCollection
Create a Composite Collection with two collections.- Parameters:
compositeCollection1- the Collection to be appended to the compositecompositeCollection2- the Collection to be appended to the composite
-
-
Method Details
-
add
Adds an object to the collection, throwing UnsupportedOperationException unless a CollectionMutator strategy is specified.- Specified by:
addin interfaceCollection<E>- Parameters:
obj- the object to add- Returns:
trueif the collection was modified- Throws:
UnsupportedOperationException- if CollectionMutator hasn't been setUnsupportedOperationException- if add is unsupportedClassCastException- if the object cannot be added due to its typeNullPointerException- if the object cannot be added because its nullIllegalArgumentException- if the object cannot be added
-
addAll
Adds a collection of elements to this collection, throwing UnsupportedOperationException unless a CollectionMutator strategy is specified.- Specified by:
addAllin interfaceCollection<E>- Parameters:
coll- the collection to add- Returns:
- true if the collection was modified
- Throws:
UnsupportedOperationException- if CollectionMutator hasn't been setUnsupportedOperationException- if add is unsupportedClassCastException- if the object cannot be added due to its typeNullPointerException- if the object cannot be added because its nullIllegalArgumentException- if the object cannot be added
-
addComposited
Add these Collections to the list of collections in this composite- Parameters:
compositeCollection- the Collection to be appended to the composite
-
addComposited
Add these Collections to the list of collections in this composite- Parameters:
compositeCollections- the Collections to be appended to the composite
-
addComposited
Add these Collections to the list of collections in this composite- Parameters:
compositeCollection1- the Collection to be appended to the compositecompositeCollection2- the Collection to be appended to the composite
-
clear
Removes all of the elements from this collection.This implementation calls
clear()on each collection.- Specified by:
clearin interfaceCollection<E>- Throws:
UnsupportedOperationException- if clear is unsupported
-
contains
Checks whether this composite collection contains the object.This implementation calls
contains()on each collection.- Specified by:
containsin interfaceCollection<E>- Parameters:
obj- the object to search for- Returns:
- true if obj is contained in any of the contained collections
-
containsAll
Checks whether this composite contains all the elements in the specified collection.This implementation calls
contains()for each element in the specified collection.- Specified by:
containsAllin interfaceCollection<E>- Parameters:
coll- the collection to check for- Returns:
- true if all elements contained
-
getCollections
Gets the collections being decorated.- Returns:
- Unmodifiable list of all collections in this composite.
-
getMutator
Gets the collection mutator to be used for this CompositeCollection.- Returns:
- CollectionMutator<E>
-
isEmpty
Checks whether this composite collection is empty.This implementation calls
isEmpty()on each collection.- Specified by:
isEmptyin interfaceCollection<E>- Returns:
- true if all of the contained collections are empty
-
iterator
Gets an iterator over all the collections in this composite.This implementation uses an
IteratorChain. -
remove
Removes an object from the collection, throwing UnsupportedOperationException unless a CollectionMutator strategy is specified.- Specified by:
removein interfaceCollection<E>- Parameters:
obj- the object being removed- Returns:
- true if the collection is changed
- Throws:
UnsupportedOperationException- if removed is unsupportedClassCastException- if the object cannot be removed due to its typeNullPointerException- if the object cannot be removed because its nullIllegalArgumentException- if the object cannot be removed
-
removeAll
Removes the elements in the specified collection from this composite collection.This implementation calls
removeAllon each collection.- Specified by:
removeAllin interfaceCollection<E>- Parameters:
coll- the collection to remove- Returns:
- true if the collection was modified
- Throws:
UnsupportedOperationException- if removeAll is unsupported
-
removeComposited
Removes a collection from the those being decorated in this composite.- Parameters:
coll- collection to be removed
-
removeIf
Removes all of the elements of this collection that satisfy the given predicate from this composite collection.This implementation calls
removeIfon each collection.- Specified by:
removeIfin interfaceCollection<E>- Parameters:
filter- a predicate which returns true for elements to be removed- Returns:
- true if the collection was modified
- Throws:
UnsupportedOperationException- if removeIf is unsupported- Since:
- 4.4
-
retainAll
Retains all the elements in the specified collection in this composite collection, removing all others.This implementation calls
retainAll()on each collection.- Specified by:
retainAllin interfaceCollection<E>- Parameters:
coll- the collection to remove- Returns:
- true if the collection was modified
- Throws:
UnsupportedOperationException- if retainAll is unsupported
-
setMutator
Specify a CollectionMutator strategy instance to handle changes.- Parameters:
mutator- the mutator to use
-
size
Gets the size of this composite collection.This implementation calls
size()on each collection.- Specified by:
sizein interfaceCollection<E>- Returns:
- total number of elements in all contained containers
-
toArray
Returns an array containing all of the elements in this composite.- Specified by:
toArrayin interfaceCollection<E>- Returns:
- an object array of all the elements in the collection
-
toArray
Returns an object array, populating the supplied array if possible. SeeCollectioninterface for full details.- Specified by:
toArrayin interfaceCollection<E>- Type Parameters:
T- the type of the elements in the collection- Parameters:
array- the array to use, populating if possible- Returns:
- an array of all the elements in the collection
-
toCollection
Returns a new collection containing all of the elements- Returns:
- A new ArrayList containing all of the elements in this composite. The new collection is not backed by this composite.
-