public class CompositeSet<E>
extends java.lang.Object
implements java.util.Set<E>, java.io.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(java.util.Set<E>... sets)
Create a composite set with sets as the initial set of composited Sets.
|
CompositeSet(java.util.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(java.util.Collection<? extends E> coll)
Adds a collection of elements to this composite, throwing
UnsupportedOperationException unless a SetMutator strategy is specified.
|
void |
addComposited(java.util.Set<E>... sets)
Add these Sets to the list of sets in this composite
|
void |
addComposited(java.util.Set<E> set)
Add a Set to this composite.
|
void |
addComposited(java.util.Set<E> set1,
java.util.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(java.lang.Object obj)
Checks whether this composite set contains the object.
|
boolean |
containsAll(java.util.Collection<?> coll)
Checks whether this composite contains all the elements in the specified collection.
|
boolean |
equals(java.lang.Object obj) |
java.util.List<java.util.Set<E>> |
getSets()
Gets the sets being decorated.
|
int |
hashCode() |
boolean |
isEmpty()
Checks whether this composite set is empty.
|
java.util.Iterator<E> |
iterator()
Gets an iterator over all the sets in this composite.
|
boolean |
remove(java.lang.Object obj)
If a
CollectionMutator is defined for this CompositeSet then this
method will be called anyway. |
boolean |
removeAll(java.util.Collection<?> coll)
Removes the elements in the specified collection from this composite set.
|
void |
removeComposited(java.util.Set<E> set)
Removes a set from those being decorated in this composite.
|
boolean |
retainAll(java.util.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.
|
java.lang.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.
|
java.util.Set<E> |
toSet()
Returns a new Set containing all of the elements.
|
public CompositeSet()
public CompositeSet(java.util.Set<E> set)
set
composited.set
- the initial set in the compositepublic CompositeSet(java.util.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(java.lang.Object obj)
This implementation calls contains()
on each set.
public java.util.Iterator<E> iterator()
This implementation uses an IteratorChain
.
iterator
in interface java.lang.Iterable<E>
iterator
in interface java.util.Collection<E>
iterator
in interface java.util.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 java.lang.Object[] toArray()
public <T> T[] toArray(T[] array)
Collection
interface for full details.public boolean add(E obj)
add
in interface java.util.Collection<E>
add
in interface java.util.Set<E>
obj
- the object to addtrue
if the collection was modifiedjava.lang.UnsupportedOperationException
- if SetMutator hasn't been set or add is unsupportedjava.lang.ClassCastException
- if the object cannot be added due to its typejava.lang.NullPointerException
- if the object cannot be added because its nulljava.lang.IllegalArgumentException
- if the object cannot be addedpublic boolean remove(java.lang.Object obj)
CollectionMutator
is defined for this CompositeSet then this
method will be called anyway.public boolean containsAll(java.util.Collection<?> coll)
This implementation calls contains()
for each element in the
specified collection.
public boolean addAll(java.util.Collection<? extends E> coll)
addAll
in interface java.util.Collection<E>
addAll
in interface java.util.Set<E>
coll
- the collection to addjava.lang.UnsupportedOperationException
- if SetMutator hasn't been set or add is unsupportedjava.lang.ClassCastException
- if the object cannot be added due to its typejava.lang.NullPointerException
- if the object cannot be added because its nulljava.lang.IllegalArgumentException
- if the object cannot be addedpublic boolean removeAll(java.util.Collection<?> coll)
This implementation calls removeAll
on each collection.
public boolean retainAll(java.util.Collection<?> coll)
This implementation calls retainAll()
on each collection.
public void clear()
This implementation calls clear()
on each set.
public void setMutator(CompositeSet.SetMutator<E> mutator)
mutator
- the mutator to usepublic void addComposited(java.util.Set<E> set)
set
- the set to addjava.lang.IllegalArgumentException
- if a SetMutator is set, but fails to resolve a collisionjava.lang.UnsupportedOperationException
- if there is no SetMutator setjava.lang.NullPointerException
- if set
is nullCompositeSet.SetMutator
public void addComposited(java.util.Set<E> set1, java.util.Set<E> set2)
set1
- the first Set to be appended to the compositeset2
- the second Set to be appended to the compositepublic void addComposited(java.util.Set<E>... sets)
sets
- the Sets to be appended to the compositepublic void removeComposited(java.util.Set<E> set)
set
- set to be removedpublic java.util.Set<E> toSet()
public java.util.List<java.util.Set<E>> getSets()
public boolean equals(java.lang.Object obj)
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"