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 SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceDefines callbacks for mutation operations.
- 
Constructor SummaryConstructorsConstructorDescriptionCreates 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 SummaryModifier 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.Objectclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.CollectionparallelStream, streamMethods inherited from interface java.util.Setspliterator
- 
Constructor Details- 
CompositeSetpublic CompositeSet()Creates an empty CompositeSet.
- 
CompositeSetCreates a CompositeSet with justsetcomposited.- Parameters:
- set- the initial set in the composite
 
- 
CompositeSetCreates a composite set with sets as the initial set of composited Sets.- Parameters:
- sets- the initial sets in the composite
 
 
- 
- 
Method Details- 
addAdds an object to the collection, throwing UnsupportedOperationException unless a SetMutator strategy is specified.- Specified by:
- addin interface- Collection<E>
- Specified by:
- addin interface- Set<E>
- Parameters:
- obj- the object to add
- Returns:
- trueif the collection was modified
- Throws:
- UnsupportedOperationException- if SetMutator hasn't been set or 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
 
- 
addAllAdds a collection of elements to this composite, throwing UnsupportedOperationException unless a SetMutator strategy is specified.- Specified by:
- addAllin interface- Collection<E>
- Specified by:
- addAllin interface- Set<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 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
 
- 
addCompositedAdds a Set to this composite.- Parameters:
- set- the set to add
- Throws:
- IllegalArgumentException- if a SetMutator is set, but fails to resolve a collision
- UnsupportedOperationException- if there is no SetMutator set
- NullPointerException- if- setis null
- See Also:
 
- 
addCompositedAdds these Sets to the list of sets in this composite- Parameters:
- sets- the Sets to be appended to the composite
 
- 
addCompositedAdds these Sets to the list of sets in this composite.- Parameters:
- set1- the first Set to be appended to the composite
- set2- the second Set to be appended to the composite
 
- 
clearRemoves all of the elements from this composite set.This implementation calls clear()on each set.- Specified by:
- clearin interface- Collection<E>
- Specified by:
- clearin interface- Set<E>
- Throws:
- UnsupportedOperationException- if clear is unsupported
 
- 
containsChecks whether this composite set contains the object.This implementation calls contains()on each set.
- 
containsAllChecks 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 interface- Collection<E>
- Specified by:
- containsAllin interface- Set<E>
- Parameters:
- coll- the collection to check for
- Returns:
- true if all elements contained
 
- 
equals
- 
getMutatorGets the set mutator to be used for this CompositeSet.- Returns:
- the set mutator
 
- 
getSets
- 
hashCode
- 
isEmpty
- 
iteratorGets an iterator over all the sets in this composite.This implementation uses an IteratorChain.- Specified by:
- iteratorin interface- Collection<E>
- Specified by:
- iteratorin interface- Iterable<E>
- Specified by:
- iteratorin interface- Set<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:
 
- 
removeIf aCollectionMutatoris defined for this CompositeSet then this method will be called anyway.
- 
removeAllRemoves the elements in the specified collection from this composite set.This implementation calls removeAllon each collection.- Specified by:
- removeAllin interface- Collection<E>
- Specified by:
- removeAllin interface- Set<E>
- Parameters:
- coll- the collection to remove
- Returns:
- true if the composite was modified
- Throws:
- UnsupportedOperationException- if removeAll is unsupported
 
- 
removeCompositedRemoves a set from those being decorated in this composite.- Parameters:
- set- set to be removed
 
- 
removeIf
- 
retainAllRetains all the elements in the specified collection in this composite set, removing all others.This implementation calls retainAll()on each collection.- Specified by:
- retainAllin interface- Collection<E>
- Specified by:
- retainAllin interface- Set<E>
- Parameters:
- coll- the collection to remove
- Returns:
- true if the composite was modified
- Throws:
- UnsupportedOperationException- if retainAll is unsupported
 
- 
setMutatorSpecify a SetMutator strategy instance to handle changes.- Parameters:
- mutator- the mutator to use
 
- 
size
- 
toArray
- 
toArrayReturns an object array, populating the supplied array if possible. SeeCollectioninterface for full details.
- 
toSet
 
-