public class CompositeSet<E> extends Objectimplements Set <E>, Serializable
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.
| Modifier and Type | Class and Description |
|---|---|
static interface |
CompositeSet
Define callbacks for mutation operations.
|
| Constructor and Description |
|---|
CompositeSet()
Create an empty CompositeSet.
|
CompositeSet(Set
Create a composite set with sets as the initial set of composited Sets.
|
CompositeSet(Set
Create a CompositeSet with just
set composited.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E obj)
Adds an object to the collection, throwing UnsupportedOperationException unless a SetMutator strategy is specified.
|
boolean |
addAll(Collection
Adds a collection of elements to this composite, throwing UnsupportedOperationException unless a SetMutator strategy is specified.
|
void |
addComposited(Set
Add these Sets to the list of sets in this composite
|
void |
addComposited(Set
Add a Set to this composite.
|
void |
addComposited(Set
Add these Sets to the list of sets in this composite.
|
void |
clear()
Removes all of the elements from this composite set.
|
boolean |
contains(Object
Checks whether this composite set contains the object.
|
boolean |
containsAll(Collection
Checks whether this composite contains all the elements in the specified collection.
|
boolean |
equals(Object
|
protected CompositeSet |
getMutator()
Get the set mutator to be used for this CompositeSet.
|
List |
getSets()
Gets the sets being decorated.
|
int |
hashCode()
|
boolean |
isEmpty()
Checks whether this composite set is empty.
|
Iterator |
iterator()
Gets an iterator over all the sets in this composite.
|
boolean |
remove(Object
If a
CollectionMutator is defined for this CompositeSet then this method will be called anyway.
|
boolean |
removeAll(Collection
Removes the elements in the specified collection from this composite set.
|
void |
removeComposited(Set
Removes a set from those being decorated in this composite.
|
boolean |
retainAll(Collection
Retains all the elements in the specified collection in this composite set, removing all others.
|
void |
setMutator(CompositeSet
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.
|
Set |
toSet()
Returns a new Set containing all of the elements.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitspliteratorparallelStream, removeIf, streampublic CompositeSet()
public CompositeSet(Set<E> set)
set composited.
set - the initial set in the composite
public int size()
This implementation calls size() on each set.
public boolean isEmpty()
This implementation calls isEmpty() on each set.
public boolean contains(Objectobj)
This implementation calls contains() on each set.
public Iterator<E> iterator()
This implementation uses an IteratorChain.
iterator in interface
Iterable<E>
iterator in interface
Collection<E>
iterator in interface
Set<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()
public <T> T[] toArray(T[] array)
Collection interface for full details.
public boolean add(E obj)
add in interface
Collection<E>
add in interface
Set<E>
obj - the object to add
true if the collection was modified
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
public boolean remove(Objectobj)
CollectionMutator is defined for this CompositeSet then this method will be called anyway.
public boolean containsAll(Collection<?> coll)
This implementation calls contains() for each element in the specified collection.
containsAll in interface
Collection<E>
containsAll in interface
Set<E>
coll - the collection to check for
public boolean addAll(Collection<? extends E> coll)
addAll in interface
Collection<E>
addAll in interface
Set<E>
coll - the collection to add
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
public boolean removeAll(Collection<?> coll)
This implementation calls removeAll on each collection.
removeAll in interface
Collection<E>
removeAll in interface
Set<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>
retainAll in interface
Set<E>
coll - the collection to remove
UnsupportedOperationException - if retainAll is unsupported
public void clear()
This implementation calls clear() on each set.
clear in interface
Collection<E>
clear in interface
Set<E>
UnsupportedOperationException - if clear is unsupported
public void setMutator(CompositeSet.SetMutator <E> mutator)
mutator - the mutator to use
public void addComposited(Set<E> set)
set - the set to add
IllegalArgumentException - if a SetMutator is set, but fails to resolve a collision
UnsupportedOperationException - if there is no SetMutator set
NullPointerException - if
set is null
CompositeSet.SetMutator
public void addComposited(Set<E> set1, Set <E> set2)
set1 - the first Set to be appended to the composite
set2 - the second Set to be appended to the composite
public void addComposited(Set<E>... sets)
sets - the Sets to be appended to the composite
public void removeComposited(Set<E> set)
set - set to be removed
public Set<E> toSet()
public List<Set <E>> getSets()
protected CompositeSet.SetMutator <E> getMutator()
public boolean equals(Objectobj)
equals in interface
Collection<E>
equals in interface
Set<E>
equals in class
Object
Set.equals(java.lang.Object)
public int hashCode()
hashCode in interface
Collection<E>
hashCode in interface
Set<E>
hashCode in class
Object
Set.hashCode()