- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- com.aoapps.collections.UnionSet<E>
-
- All Implemented Interfaces:
Iterable<E>,Collection<E>,Set<E>
public class UnionSet<E> extends AbstractSet<E>
In order to efficiently provide a union of fewer, larger sets, this provides a set view on top of other sets. Any set that is added to this union set via
addAll(Set)must not be modified after being added. For performance purposes, defensive copying is not performed.- Author:
- AO Industries, Inc.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E e)booleanaddAll(Collection<? extends E> c)Triggers combining.voidaddAll(Set<? extends E> set)If the set has size > MAXIMUM_COMBINE_SIZE, the set will be added to theaddedlist, which may then be later combined only when needed.voidclear()booleancontains(Object o)booleancontainsAll(Collection<?> c)booleanisEmpty()Iterator<E>iterator()Triggers combining.booleanremove(Object o)Triggers combining.booleanremoveAll(Collection<?> c)Triggers combining.booleanretainAll(Collection<?> c)Triggers combining.intsize()Triggers combining.Object[]toArray()Triggers combining.<T> T[]toArray(T[] a)Triggers combining.-
Methods inherited from class java.util.AbstractSet
equals, hashCode
-
Methods inherited from class java.util.AbstractCollection
toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.Set
spliterator
-
-
-
-
Constructor Detail
-
UnionSet
public UnionSet()
-
UnionSet
public UnionSet(Collection<? extends E> c)
-
-
Method Detail
-
size
public int size()
Triggers combining.- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceSet<E>- Specified by:
sizein classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceSet<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
contains
public boolean contains(Object o)
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceSet<E>- Overrides:
containsin classAbstractCollection<E>
-
iterator
public Iterator<E> iterator()
Triggers combining. TODO: Iterate without combining - benchmark speed versus complexity
-
toArray
public Object[] toArray()
Triggers combining.- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceSet<E>- Overrides:
toArrayin classAbstractCollection<E>
-
toArray
public <T> T[] toArray(T[] a)
Triggers combining.- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceSet<E>- Overrides:
toArrayin classAbstractCollection<E>
-
add
public boolean add(E e)
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceSet<E>- Overrides:
addin classAbstractCollection<E>
-
remove
public boolean remove(Object o)
Triggers combining.- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceSet<E>- Overrides:
removein classAbstractCollection<E>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAllin interfaceCollection<E>- Specified by:
containsAllin interfaceSet<E>- Overrides:
containsAllin classAbstractCollection<E>
-
addAll
public boolean addAll(Collection<? extends E> c)
Triggers combining.- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceSet<E>- Overrides:
addAllin classAbstractCollection<E>- See Also:
addAll(java.util.Set)
-
addAll
public void addAll(Set<? extends E> set)
If the set has size > MAXIMUM_COMBINE_SIZE, the set will be added to theaddedlist, which may then be later combined only when needed. Because of this potentially delayed combining, any set added should not be subsequently altered.
-
retainAll
public boolean retainAll(Collection<?> c)
Triggers combining.- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceSet<E>- Overrides:
retainAllin classAbstractCollection<E>
-
removeAll
public boolean removeAll(Collection<?> c)
Triggers combining.- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceSet<E>- Overrides:
removeAllin classAbstractSet<E>
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceSet<E>- Overrides:
clearin classAbstractCollection<E>
-
-