Class CompositeSet<E>
- Type Parameters:
E
- the type of the elements in this set
- All Implemented Interfaces:
Serializable
,Iterable<E>
,Collection<E>
,Set<E>
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 interface
Define callbacks for mutation operations. -
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty CompositeSet.CompositeSet
(Set<E> set) Create a CompositeSet with justset
composited.CompositeSet
(Set<E>... sets) Create a composite set with sets as the initial set of composited Sets. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds an object to the collection, throwing UnsupportedOperationException unless a SetMutator strategy is specified.boolean
addAll
(Collection<? extends E> coll) Adds a collection of elements to this composite, throwing UnsupportedOperationException unless a SetMutator strategy is specified.void
addComposited
(Set<E> set) Add a Set to this composite.void
addComposited
(Set<E>... sets) Add these Sets to the list of sets in this compositevoid
addComposited
(Set<E> set1, Set<E> set2) Add these Sets to the list of sets in this composite.void
clear()
Removes all of the elements from this composite set.boolean
Checks whether this composite set contains the object.boolean
containsAll
(Collection<?> coll) Checks whether this composite contains all the elements in the specified collection.boolean
protected CompositeSet.SetMutator<E>
Get the set mutator to be used for this CompositeSet.getSets()
Gets the sets being decorated.int
hashCode()
boolean
isEmpty()
Checks whether this composite set is empty.iterator()
Gets an iterator over all the sets in this composite.boolean
If aCollectionMutator
is defined for this CompositeSet then this method will be called anyway.boolean
removeAll
(Collection<?> coll) Removes the elements in the specified collection from this composite set.void
removeComposited
(Set<E> set) Removes a set from those being decorated in this composite.boolean
boolean
retainAll
(Collection<?> coll) Retains all the elements in the specified collection in this composite set, removing all others.void
setMutator
(CompositeSet.SetMutator<E> mutator) Specify a SetMutator strategy instance to handle changes.int
size()
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, wait
Methods inherited from interface java.util.Collection
parallelStream, stream
Methods inherited from interface java.util.Set
spliterator
-
Constructor Details
-
CompositeSet
public CompositeSet()Create an empty CompositeSet. -
CompositeSet
Create a CompositeSet with justset
composited.- Parameters:
set
- the initial set in the composite
-
CompositeSet
Create a composite set with sets as the initial set of composited Sets.- Parameters:
sets
- the initial sets in the composite
-
-
Method Details
-
size
Gets the size of this composite set.This implementation calls
size()
on each set. -
isEmpty
Checks whether this composite set is empty.This implementation calls
isEmpty()
on each set. -
contains
Checks whether this composite set contains the object.This implementation calls
contains()
on each set. -
iterator
Gets an iterator over all the sets in this composite.This implementation uses an
IteratorChain
.- Specified by:
iterator
in interfaceCollection<E>
- Specified by:
iterator
in interfaceIterable<E>
- Specified by:
iterator
in interfaceSet<E>
- Returns:
- an
IteratorChain
instance which supportsremove()
. Iteration occurs over contained collections in the order they were added, but this behavior should not be relied upon. - See Also:
-
toArray
Returns an array containing all of the elements in this composite. -
toArray
Returns an object array, populating the supplied array if possible. SeeCollection
interface for full details. -
add
Adds an object to the collection, throwing UnsupportedOperationException unless a SetMutator strategy is specified.- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceSet<E>
- Parameters:
obj
- the object to add- Returns:
true
if 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
-
remove
If aCollectionMutator
is defined for this CompositeSet then this method will be called anyway. -
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:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceSet<E>
- Parameters:
coll
- the collection to check for- Returns:
- true if all elements contained
-
addAll
Adds a collection of elements to this composite, throwing UnsupportedOperationException unless a SetMutator strategy is specified.- Specified by:
addAll
in interfaceCollection<E>
- Specified by:
addAll
in 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
-
removeIf
- Specified by:
removeIf
in interfaceCollection<E>
- Since:
- 4.4
-
removeAll
Removes the elements in the specified collection from this composite set.This implementation calls
removeAll
on each collection.- Specified by:
removeAll
in interfaceCollection<E>
- Specified by:
removeAll
in interfaceSet<E>
- Parameters:
coll
- the collection to remove- Returns:
- true if the composite was modified
- Throws:
UnsupportedOperationException
- if removeAll is unsupported
-
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:
retainAll
in interfaceCollection<E>
- Specified by:
retainAll
in interfaceSet<E>
- Parameters:
coll
- the collection to remove- Returns:
- true if the composite was modified
- Throws:
UnsupportedOperationException
- if retainAll is unsupported
-
clear
Removes all of the elements from this composite set.This implementation calls
clear()
on each set.- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceSet<E>
- Throws:
UnsupportedOperationException
- if clear is unsupported
-
setMutator
Specify a SetMutator strategy instance to handle changes.- Parameters:
mutator
- the mutator to use
-
addComposited
Add 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
- ifset
is null- See Also:
-
addComposited
Add 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
-
addComposited
Add these Sets to the list of sets in this composite- Parameters:
sets
- the Sets to be appended to the composite
-
removeComposited
Removes a set from those being decorated in this composite.- Parameters:
set
- set to be removed
-
toSet
Returns a new Set containing all of the elements.- Returns:
- A new HashSet containing all of the elements in this composite. The new collection is not backed by this composite.
-
getSets
Gets the sets being decorated.- Returns:
- Unmodifiable list of all sets in this composite.
-
getMutator
Get the set mutator to be used for this CompositeSet.- Returns:
- the set mutator
-
equals
-
hashCode
-