T
- the type of elements in the setpublic class LimitedSizeSet<T>
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable
If you need LimitedSizeSet<Integer>
, use LimitedSizeIntSet
instead.
If you need LimitedSizeSet<Long>
, use LimitedSizeLongSet
instead.
Modifier and Type | Field and Description |
---|---|
protected @IndexOrHigh(value="values") int |
numValues
The number of active elements (equivalently, the first unused index).
|
protected T[] |
values
|
Constructor and Description |
---|
LimitedSizeSet(@Positive int maxValues)
Create a new LimitedSizeSet that can hold maxValues values.
|
Modifier and Type | Method and Description |
---|---|
void |
add(T elt)
Add an element to this set.
|
void |
addAll(LimitedSizeSet<? extends T> s)
Add all elements of
s to this set. |
LimitedSizeSet<T> |
clone() |
boolean |
contains(T elt)
Return true if this set contains the given element.
|
@Positive int |
maxSize()
An upper bound on how many distinct elements can be individually represented in the set.
|
static <T> LimitedSizeSet<T> |
merge(@Positive int maxValues,
java.util.List<LimitedSizeSet<? extends T>> slist)
Merges a list of
LimitedSizeSet<T> objects into a single object that represents the
values seen by the entire list. |
boolean |
repNulled()
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).
|
@IndexOrHigh(value="this.values") int |
size()
A lower bound on the number of elements in the set.
|
java.lang.String |
toString() |
protected T[] values
protected @IndexOrHigh(value="values") int numValues
public LimitedSizeSet(@Positive int maxValues)
maxValues
- the maximum number of values this set will be able to hold; must be positivepublic void add(T elt)
elt
- the element to add to this setpublic void addAll(LimitedSizeSet<? extends T> s)
s
to this set.s
- the elements to add to this set@Pure public boolean contains(T elt)
elt
- the element whose membership to testelt
@Pure public @IndexOrHigh(value="this.values") int size(@GuardSatisfied LimitedSizeSet<T> this)
public @Positive int maxSize()
@EnsuresNonNullIf(result=false, expression="values") @Pure public boolean repNulled(@GuardSatisfied LimitedSizeSet<T> this)
@SideEffectFree public LimitedSizeSet<T> clone(@GuardSatisfied LimitedSizeSet<T> this)
clone
in class java.lang.Object
public static <T> LimitedSizeSet<T> merge(@Positive int maxValues, java.util.List<LimitedSizeSet<? extends T>> slist)
LimitedSizeSet<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.T
- (super)type of elements of the setsmaxValues
- the maximum size for the returned LimitedSizeSetslist
- a list of LimitedSizeSet, whose elements will be merged@SideEffectFree public java.lang.String toString(@GuardSatisfied LimitedSizeSet<T> this)
toString
in class java.lang.Object