Package org.plumelib.util
Class AbstractMostlySingletonSet<T extends @Signed Object>
java.lang.Object
org.plumelib.util.AbstractMostlySingletonSet<T>
- Type Parameters:
T
- the type of elements of the set
- All Implemented Interfaces:
Iterable<T>
,Collection<T>
,Set<T>
- Direct Known Subclasses:
IdentityMostlySingletonSet
,MostlySingletonSet
public abstract class AbstractMostlySingletonSet<T extends @Signed Object>
extends Object
implements Set<T>
Base class for arbitrary-size sets that is very efficient (more efficient than HashSet) for 0 and
1 elements.
Does not support storing null
.
This class exists because it has multiple subclasses (currently MostlySingletonSet
and
IdentityMostlySingletonSet
).
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
The possible states of this set. -
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
Create an AbstractMostlySingletonSet.protected
Create an AbstractMostlySingletonSet. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addAll
(Collection<? extends T> c) protected void
checkRep()
Throw an exception if the internal representation is corrupted.void
clear()
boolean
containsAll
(@GuardSatisfied Collection<?> c) boolean
isEmpty()
iterator()
boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) @org.checkerframework.checker.index.qual.NonNegative int
size()
@PolySigned Object[]
toArray()
<@KeyForBottom S>
@Nullable S[]toArray
(@PolyNull S[] a) toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Field Details
-
state
The current state. -
value
The current value, non-null when the state is SINGLETON. -
set
The wrapped set, non-null when the state is ANY.
-
-
Constructor Details
-
AbstractMostlySingletonSet
Create an AbstractMostlySingletonSet.- Parameters:
s
- the state
-
AbstractMostlySingletonSet
Create an AbstractMostlySingletonSet.- Parameters:
s
- the statev
- the value
-
-
Method Details
-
checkRep
protected void checkRep()Throw an exception if the internal representation is corrupted. -
size
public @org.checkerframework.checker.index.qual.NonNegative int size(@GuardSatisfied AbstractMostlySingletonSet<T extends @Signed Object> this) -
isEmpty
-
iterator
-
toString
-
addAll
public boolean addAll(@GuardSatisfied AbstractMostlySingletonSet<T extends @Signed Object> this, Collection<? extends T> c) -
toArray
-
toArray
public <@KeyForBottom S> @Nullable S[] toArray(@PolyNull S[] a) -
remove
-
containsAll
public boolean containsAll(@GuardSatisfied AbstractMostlySingletonSet<T extends @Signed Object> this, @GuardSatisfied Collection<?> c) - Specified by:
containsAll
in interfaceCollection<T extends @Signed Object>
- Specified by:
containsAll
in interfaceSet<T extends @Signed Object>
-
retainAll
public boolean retainAll(@GuardSatisfied AbstractMostlySingletonSet<T extends @Signed Object> this, Collection<?> c) -
removeAll
public boolean removeAll(@GuardSatisfied AbstractMostlySingletonSet<T extends @Signed Object> this, Collection<?> c) -
clear
-