|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.commons.collections4.set.CompositeSet<E>
public class CompositeSet<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.
| Nested Class Summary | |
|---|---|
static interface |
CompositeSet.SetMutator<E>
Define callbacks for mutation operations. |
| Constructor Summary | |
|---|---|
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. |
|
| Method Summary | ||
|---|---|---|
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> set)
Add a Set to this composite. |
|
void |
addComposited(Set<E>[] sets)
Add these Sets to the list of sets in 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. |
|
|
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. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
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 composite| Method Detail |
|---|
public int size()
This implementation calls size() on each set.
size in interface Collection<E>size in interface Set<E>public boolean isEmpty()
This implementation calls isEmpty() on each set.
isEmpty in interface Collection<E>isEmpty in interface Set<E>public boolean contains(Object obj)
This implementation calls contains() on each set.
contains in interface Collection<E>contains in interface Set<E>obj - the object to search for
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.IteratorChainpublic Object[] toArray()
toArray in interface Collection<E>toArray in interface Set<E>public <T> T[] toArray(T[] array)
Collection interface for full details.
toArray in interface Collection<E>toArray in interface Set<E>T - the type of the elements in the collectionarray - the array to use, populating if possible
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 addedpublic boolean remove(Object obj)
CollectionMutator is defined for this CompositeSet then this
method will be called anyway.
remove in interface Collection<E>remove in interface Set<E>obj - object to be removed
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 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 remove
UnsupportedOperationException - 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 remove
UnsupportedOperationException - 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 add
IllegalArgumentException - if a SetMutator is set, but fails to resolve a collision
UnsupportedOperationException - if there is no SetMutator setCompositeSet.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 ObjectSet.equals(java.lang.Object)public int hashCode()
hashCode in interface Collection<E>hashCode in interface Set<E>hashCode in class ObjectSet.hashCode()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||