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
Nested ClassesModifier and TypeClassDescriptionstatic enumThe possible states of this set. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreate an AbstractMostlySingletonSet.protectedCreate an AbstractMostlySingletonSet. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddAll(Collection<? extends T> c) protected voidcheckRep()Throw an exception if the internal representation is corrupted.voidclear()booleancontainsAll(@GuardSatisfied Collection<?> c) booleanisEmpty()iterator()booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) @org.checkerframework.checker.index.qual.NonNegative intsize()@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, waitMethods 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:
containsAllin interfaceCollection<T extends @Signed Object>- Specified by:
containsAllin 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
-