E
- the type of the elements in this setpublic class CompositeSet<E> extends Object implements 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.SetMutator<E>
Define callbacks for mutation operations.
|
Constructor and Description |
---|
CompositeSet()
Create an empty CompositeSet.
|
CompositeSet(Set<E>... sets)
Create a composite set with sets as the initial set of composited Sets.
|
CompositeSet(Set<E> 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<? extends E> coll)
Adds a collection of elements to this composite, throwing
UnsupportedOperationException unless a SetMutator strategy is specified.
|
void |
addComposited(Set<E>... sets)
Add these Sets to the list of sets in this composite
|
void |
addComposited(Set<E> set)
Add a Set to this composite.
|
void |
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 |
contains(Object obj)
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 |
equals(Object obj) |
protected CompositeSet.SetMutator<E> |
getMutator()
Get the set mutator to be used for this CompositeSet.
|
List<Set<E>> |
getSets()
Gets the sets being decorated.
|
int |
hashCode() |
boolean |
isEmpty()
Checks whether this composite set is empty.
|
Iterator<E> |
iterator()
Gets an iterator over all the sets in this composite.
|
boolean |
remove(Object obj)
If a
CollectionMutator 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 |
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.
|
Set<E> |
toSet()
Returns a new Set containing all of the elements.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
spliterator
parallelStream, removeIf, stream
public CompositeSet()
public CompositeSet(Set<E> set)
set
composited.set
- the initial set in the compositepublic CompositeSet(Set<E>... sets)
sets
- the initial sets in the compositepublic int size()
This implementation calls size()
on each set.
public boolean isEmpty()
This implementation calls isEmpty()
on each set.
public boolean contains(Object obj)
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 addtrue
if the collection was modifiedUnsupportedOperationException
- 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 addedpublic boolean remove(Object obj)
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 forpublic boolean addAll(Collection<? extends E> coll)
addAll
in interface Collection<E>
addAll
in interface Set<E>
coll
- the collection to addUnsupportedOperationException
- 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 addedpublic 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 removeUnsupportedOperationException
- if removeAll is unsupportedpublic 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 removeUnsupportedOperationException
- if retainAll is unsupportedpublic void clear()
This implementation calls clear()
on each set.
clear
in interface Collection<E>
clear
in interface Set<E>
UnsupportedOperationException
- if clear is unsupportedpublic void setMutator(CompositeSet.SetMutator<E> mutator)
mutator
- the mutator to usepublic void addComposited(Set<E> set)
set
- the set to addIllegalArgumentException
- if a SetMutator is set, but fails to resolve a collisionUnsupportedOperationException
- if there is no SetMutator setNullPointerException
- if set
is nullCompositeSet.SetMutator
public void addComposited(Set<E> set1, Set<E> set2)
set1
- the first Set to be appended to the compositeset2
- the second Set to be appended to the compositepublic void addComposited(Set<E>... sets)
sets
- the Sets to be appended to the compositepublic void removeComposited(Set<E> set)
set
- set to be removedpublic Set<E> toSet()
public List<Set<E>> getSets()
protected CompositeSet.SetMutator<E> getMutator()
public boolean equals(Object obj)
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()
Copyright © 2001–2018 The Apache Software Foundation. All rights reserved.