Class CompositeSet<E>
java.lang.Object
org.apache.commons.collections4.set.CompositeSet<E>
- Type Parameters:
E- the type of the elements in this set
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,Set<E>
Decorates a set of other sets to provide a single unified view.
Changes made to this set will actually be made on the decorated set. Add operations require the use of a pluggable strategy. If no strategy is provided then add is unsupported.
From version 4.0, this class does not extend
CompositeCollection
anymore due to its input restrictions (only accepts Sets).
See COLLECTIONS-424
for more details.
- Since:
- 3.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDefines callbacks for mutation operations. -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty CompositeSet.CompositeSet(Set<E> set) Creates a CompositeSet with justsetcomposited.CompositeSet(Set<E>... sets) Creates a composite set with sets as the initial set of composited Sets. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds an object to the collection, throwing UnsupportedOperationException unless a SetMutator strategy is specified.booleanaddAll(Collection<? extends E> coll) Adds a collection of elements to this composite, throwing UnsupportedOperationException unless a SetMutator strategy is specified.voidaddComposited(Set<E> set) Adds a Set to this composite.voidaddComposited(Set<E>... sets) Adds these Sets to the list of sets in this compositevoidaddComposited(Set<E> set1, Set<E> set2) Adds these Sets to the list of sets in this composite.voidclear()Removes all of the elements from this composite set.booleanChecks whether this composite set contains the object.booleancontainsAll(Collection<?> coll) Checks whether this composite contains all the elements in the specified collection.booleanprotected CompositeSet.SetMutator<E> Gets the set mutator to be used for this CompositeSet.getSets()Gets the sets being decorated.inthashCode()booleanisEmpty()Checks whether this composite set is empty.iterator()Gets an iterator over all the sets in this composite.booleanIf aCollectionMutatoris defined for this CompositeSet then this method will be called anyway.booleanremoveAll(Collection<?> coll) Removes the elements in the specified collection from this composite set.voidremoveComposited(Set<E> set) Removes a set from those being decorated in this composite.booleanbooleanretainAll(Collection<?> coll) Retains all the elements in the specified collection in this composite set, removing all others.voidsetMutator(CompositeSet.SetMutator<E> mutator) Specify a SetMutator strategy instance to handle changes.intsize()Gets the size of this composite set.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.toSet()Returns a new Set containing all of the elements.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, streamMethods inherited from interface java.util.Set
spliterator
-
Constructor Details
-
CompositeSet
public CompositeSet()Creates an empty CompositeSet. -
CompositeSet
Creates a CompositeSet with justsetcomposited.- Parameters:
set- the initial set in the composite
-
CompositeSet
Creates a composite set with sets as the initial set of composited Sets.- Parameters:
sets- the initial sets in the composite
-
-
Method Details
-
add
Adds an object to the collection, throwing UnsupportedOperationException unless a SetMutator strategy is specified.- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Parameters:
obj- the object to add- Returns:
trueif the collection was modified- Throws:
UnsupportedOperationException- if SetMutator hasn't been set or 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 composite, throwing UnsupportedOperationException unless a SetMutator strategy is specified.- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceSet<E>- Parameters:
coll- the collection to add- Returns:
- true if the composite was modified
- Throws:
UnsupportedOperationException- if SetMutator hasn't been set or 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
Adds a Set to this composite.- Parameters:
set- the set to add- Throws:
IllegalArgumentException- if a SetMutator is set, but fails to resolve a collisionUnsupportedOperationException- if there is no SetMutator setNullPointerException- ifsetis null- See Also:
-
addComposited
Adds these Sets to the list of sets in this composite- Parameters:
sets- the Sets to be appended to the composite
-
addComposited
Adds these Sets to the list of sets in this composite.- Parameters:
set1- the first Set to be appended to the compositeset2- the second Set to be appended to the composite
-
clear
Removes all of the elements from this composite set.This implementation calls
clear()on each set.- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Throws:
UnsupportedOperationException- if clear is unsupported
-
contains
Checks whether this composite set contains the object.This implementation calls
contains()on each set. -
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>- Specified by:
containsAllin interfaceSet<E>- Parameters:
coll- the collection to check for- Returns:
- true if all elements contained
-
equals
-
getMutator
Gets the set mutator to be used for this CompositeSet.- Returns:
- the set mutator
-
getSets
-
hashCode
-
isEmpty
-
iterator
Gets an iterator over all the sets in this composite.This implementation uses an
IteratorChain.- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin interfaceSet<E>- Returns:
- an
IteratorChaininstance which supportsremove(). Iteration occurs over contained collections in the order they were added, but this behavior should not be relied upon. - See Also:
-
remove
If aCollectionMutatoris defined for this CompositeSet then this method will be called anyway. -
removeAll
Removes the elements in the specified collection from this composite set.This implementation calls
removeAllon each collection.- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceSet<E>- Parameters:
coll- the collection to remove- Returns:
- true if the composite was modified
- Throws:
UnsupportedOperationException- if removeAll is unsupported
-
removeComposited
Removes a set from those being decorated in this composite.- Parameters:
set- set to be removed
-
removeIf
-
retainAll
Retains all the elements in the specified collection in this composite set, removing all others.This implementation calls
retainAll()on each collection.- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceSet<E>- Parameters:
coll- the collection to remove- Returns:
- true if the composite was modified
- Throws:
UnsupportedOperationException- if retainAll is unsupported
-
setMutator
Specify a SetMutator strategy instance to handle changes.- Parameters:
mutator- the mutator to use
-
size
-
toArray
-
toArray
Returns an object array, populating the supplied array if possible. SeeCollectioninterface for full details. -
toSet
-