Package org.plumelib.util
Class LimitedSizeSet<T extends @Nullable Object>
java.lang.Object
org.plumelib.util.LimitedSizeSet<T>
- Type Parameters:
T- the type of elements in the set
- All Implemented Interfaces:
Serializable,Cloneable
public class LimitedSizeSet<T extends @Nullable Object>
extends Object
implements Serializable, Cloneable
LimitedSizeSet stores up to some maximum number of unique values. If more than that many elements
are added, then functionality is degraded: most operations return a conservative estimate
(because the internal representation is nulled, in order to save space).
If you need LimitedSizeSet<Integer>, use LimitedSizeIntSet instead.
If you need LimitedSizeSet<Long>, use LimitedSizeLongSet instead.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static booleanWhether assertions are enabled.protected @org.checkerframework.checker.index.qual.IndexOrHigh({"values"}) intThe number of active elements (equivalently, the first unused index).(package private) static final longUnique identifier for serialization.protected @Nullable T @Nullable @MinLen(1) [] -
Constructor Summary
ConstructorsConstructorDescriptionLimitedSizeSet(@org.checkerframework.checker.index.qual.Positive int maxValues) Create a new LimitedSizeSet that can hold maxValues values. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd an element to this set.voidaddAll(LimitedSizeSet<? extends T> s) Add all elements ofsto this set.clone()booleanReturns true if this set contains the given element.@org.checkerframework.checker.index.qual.Positive intmaxSize()An upper bound on how many distinct elements can be individually represented in the set.static <T extends @Nullable Object>
LimitedSizeSet<T>merge(@org.checkerframework.checker.index.qual.Positive int maxValues, List<LimitedSizeSet<? extends T>> slist) Merges a list ofLimitedSizeSet<T>objects into a single object that represents the values seen by the entire list.private voidnullRep()Null the representation, which happens when a client tries to add more elements to this set than it can contain (which is the integer that was passed to the constructor when creating this set).booleanReturns true if more elements have been added than this set can contain (which is the integer that was passed to the constructor when creating this set).@org.checkerframework.checker.index.qual.IndexOrHigh({"this.values"}) intsize()A lower bound on the number of elements in the set.toString()
-
Field Details
-
serialVersionUID
static final long serialVersionUIDUnique identifier for serialization. If you add or remove fields, change this number.- See Also:
-
values
-
numValues
protected @org.checkerframework.checker.index.qual.IndexOrHigh({"values"}) int numValuesThe number of active elements (equivalently, the first unused index). -
assertsEnabled
private static boolean assertsEnabledWhether assertions are enabled.
-
-
Constructor Details
-
LimitedSizeSet
public LimitedSizeSet(@org.checkerframework.checker.index.qual.Positive int maxValues) Create a new LimitedSizeSet that can hold maxValues values.- Parameters:
maxValues- the maximum number of values this set will be able to hold; must be positive
-
-
Method Details
-
add
Add an element to this set.- Parameters:
elt- the element to add to this set
-
addAll
Add all elements ofsto this set.- Parameters:
s- the elements to add to this set
-
contains
Returns true if this set contains the given element.- Parameters:
elt- the element whose membership to test- Returns:
- true if this set contains
elt
-
size
@Pure public @org.checkerframework.checker.index.qual.IndexOrHigh({"this.values"}) int size(@GuardSatisfied LimitedSizeSet<T extends @Nullable Object> this) A lower bound on the number of elements in the set. Returns either the number of elements that have been inserted in the set, or maxSize(), whichever is less.- Returns:
- a number that is a lower bound on the number of elements added to the set
-
maxSize
public @org.checkerframework.checker.index.qual.Positive int maxSize()An upper bound on how many distinct elements can be individually represented in the set. Returns maxValues+1 (where maxValues is the argument to the constructor).- Returns:
- maximum capacity of the set representation
-
repNulled
@EnsuresNonNullIf(result=false, expression="values") @Pure public boolean repNulled(@GuardSatisfied LimitedSizeSet<T extends @Nullable Object> this) Returns true if more elements have been added than this set can contain (which is the integer that was passed to the constructor when creating this set).- Returns:
- true if this set has been filled to capacity and its internal representation is nulled
-
nullRep
private void nullRep()Null the representation, which happens when a client tries to add more elements to this set than it can contain (which is the integer that was passed to the constructor when creating this set). -
clone
@SideEffectFree public LimitedSizeSet<T> clone(@GuardSatisfied LimitedSizeSet<T extends @Nullable Object> this) -
merge
public static <T extends @Nullable Object> LimitedSizeSet<T> merge(@org.checkerframework.checker.index.qual.Positive int maxValues, List<LimitedSizeSet<? extends T>> slist) Merges a list ofLimitedSizeSet<T>objects into a single object that represents the values seen by the entire list. Returns the new object, whose maxValues is the given integer.- Type Parameters:
T- (super)type of elements of the sets- Parameters:
maxValues- the maximum size for the returned LimitedSizeSetslist- a list of LimitedSizeSet, whose elements will be merged- Returns:
- a LimitedSizeSet that merges the elements of slist
-
toString
-