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>
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.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends E> c) Triggers combining.void
If the set has size > MAXIMUM_COMBINE_SIZE, the set will be added to theadded
list, which may then be later combined only when needed.void
clear()
boolean
boolean
containsAll
(Collection<?> c) boolean
isEmpty()
iterator()
Triggers combining.boolean
Triggers combining.boolean
removeAll
(Collection<?> c) Triggers combining.boolean
retainAll
(Collection<?> c) Triggers combining.int
size()
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 Details
-
UnionSet
public UnionSet() -
UnionSet
-
UnionSet
-
-
Method Details
-
size
public int size()Triggers combining.- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceSet<E>
- Specified by:
size
in classAbstractCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceSet<E>
- Overrides:
isEmpty
in classAbstractCollection<E>
-
contains
- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceSet<E>
- Overrides:
contains
in classAbstractCollection<E>
-
iterator
Triggers combining.TODO: Iterate without combining - benchmark speed versus complexity
-
toArray
Triggers combining.- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceSet<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
toArray
public <T> T[] toArray(T[] a) Triggers combining.- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceSet<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
add
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceSet<E>
- Overrides:
add
in classAbstractCollection<E>
-
remove
Triggers combining.- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceSet<E>
- Overrides:
remove
in classAbstractCollection<E>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceSet<E>
- Overrides:
containsAll
in classAbstractCollection<E>
-
addAll
Triggers combining.- Specified by:
addAll
in interfaceCollection<E>
- Specified by:
addAll
in interfaceSet<E>
- Overrides:
addAll
in classAbstractCollection<E>
- See Also:
-
addAll
If the set has size > MAXIMUM_COMBINE_SIZE, the set will be added to theadded
list, which may then be later combined only when needed. Because of this potentially delayed combining, any set added should not be subsequently altered. -
retainAll
Triggers combining.- Specified by:
retainAll
in interfaceCollection<E>
- Specified by:
retainAll
in interfaceSet<E>
- Overrides:
retainAll
in classAbstractCollection<E>
-
removeAll
Triggers combining.- Specified by:
removeAll
in interfaceCollection<E>
- Specified by:
removeAll
in interfaceSet<E>
- Overrides:
removeAll
in classAbstractSet<E>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceSet<E>
- Overrides:
clear
in classAbstractCollection<E>
-