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) @NonNegative intsize()@PolySigned Object[]toArray()<@KeyForBottom S>
@Nullable S[]toArray(@PolyNull S[] a) toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Collection
parallelStream, removeIf, stream, toArray
-
Field Details
-
state
The current state. -
value
-
set
-
-
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
-
isEmpty
-
iterator
-
toString
-
addAll
-
toArray
-
toArray
-
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
-