IllegalStateException if adding an element would exceed the maximum capacity.
These sets do not allow null elements, and unless otherwise specified, passing
null for any argument will result in a NullPointerException.
Specifically, these sets are optimized for holding sets of style class names, which have the following characteristics:
nullFixedSizeSet, the inverse function isSuperSetOf(Collection) is providedHashSet (and comparable to the immutable sets provided by Set.of())
as they do not require a wrapper to hold each element.
These sets can only be appended, reject nulls, have a fixed maximum size (which will throw
an exception if exceeded), and can be frozen (made read-only without using a wrapper).
The fall back set implementation for large sets uses open addressing. It is
only lightly optimized as the expectation is that it will see little to no use.
It is still preferred over HashSet due to its low memory foot print, and
faster iteration.
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| private static class | FixedCapacitySet.
the element type T>A set which can hold a fixed maximum number of elements. |
| private static class | FixedCapacitySet.
the element type T>A set which can hold a fixed maximum number of elements. |
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private static final FixedCapacitySet | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private static <T> FixedCapacitySet | |
| protected final void | ensureNotFrozen()
Checks if the set is allowed to be mutated, and throws an
|
| public final void | |
| public abstract boolean | Returns: true if the given collection contains all elements of this
collection, otherwise falsea collection to check, cannot be c)nullChecks if the given collection contains all elements of this collection. |
| public static < the element type T> FixedCapacitySet | Returns: a new empty set, nevernullthe maximum possible number of elements the set can hold, cannot be negative maximumCapacity)Hides java. Creates a new |
| EMPTY | back to summary |
|---|---|
| private static final FixedCapacitySet<?> EMPTY | |
| frozen | back to summary |
|---|---|
| private boolean frozen | |
| FixedCapacitySet | back to summary |
|---|---|
| public FixedCapacitySet() | |
| empty | back to summary |
|---|---|
private static <T> FixedCapacitySet
| |
| ensureNotFrozen | back to summary |
|---|---|
| protected final void ensureNotFrozen() Checks if the set is allowed to be mutated, and throws an
| |
| freeze | back to summary |
|---|---|
| public final void freeze() Freezes this collection, turning it permanently read-only. After freezing,
any method that would modify the collection will instead throw
This can be used to avoid wrapping the collection with an unmodifiable collection or making a read-only copy. | |
| isSuperSetOf | back to summary |
|---|---|
| public abstract boolean isSuperSetOf(Collection<?> c) Checks if the given collection contains all elements
of this collection. This is the same as If the given collection is small, or has good
| |
| of | back to summary |
|---|---|
| public static <T> FixedCapacitySet Hides java. Creates a new
| |
| Modifier and Type | Field and Description |
|---|---|
| private T | |
| private T | |
| private int |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | add(T e)
Overrides java. Implements java. Adds the specified element to this set if it is not already present (optional operation). |
| public boolean | contains(Object o)
Overrides java. Implements java. Returns |
| public int | hashCode()
Overrides java. Implements java. Returns the hash code value for this set. |
| public boolean | isSuperSetOf(Collection<?> c)
Implements abstract com. Checks if the given collection contains all elements of this collection. |
| public Iterator | iterator()
Implements abstract java. Implements java. Returns an iterator over the elements in this set. |
| public int | size()
Implements abstract java. Implements java. Returns the number of elements in this set (its cardinality). |
| element1 | back to summary |
|---|---|
| private T element1 | |
| element2 | back to summary |
|---|---|
| private T element2 | |
| size | back to summary |
|---|---|
| private int size | |
| Duo | back to summary |
|---|---|
| private Duo() | |
| add | back to summary |
|---|---|
| public boolean add(T e) Overrides java. Implements java. Doc from java. Adds the specified element to this set if it is not already present
(optional operation). More formally, adds the specified element
The stipulation above does not imply that sets must accept all
elements; sets may refuse to add any particular element, including
| |
| contains | back to summary |
|---|---|
| public boolean contains(Object o) Overrides java. Implements java. Doc from java. Returns
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implements java. Doc from java. Returns the hash code value for this set. The hash code of a set is
defined to be the sum of the hash codes of the elements in the set,
where the hash code of a This implementation iterates over the set, calling the
| |
| isSuperSetOf | back to summary |
|---|---|
| public boolean isSuperSetOf(Collection<?> c) Implements abstract com. Doc from com. Checks if the given collection contains all elements
of this collection. This is the same as If the given collection is small, or has good
| |
| iterator | back to summary |
|---|---|
| public Iterator Implements abstract java. Implements java. Doc from java. Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).
| |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Doc from java. Returns the number of elements in this set (its cardinality). If this
set contains more than
| |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | add(T e)
Overrides java. Implements java. Adds the specified element to this set if it is not already present (optional operation). |
| public boolean | contains(Object o)
Overrides java. Implements java. Returns |
| public int | hashCode()
Overrides java. Implements java. Returns the hash code value for this set. |
| public boolean | isSuperSetOf(Collection<?> c)
Implements abstract com. Checks if the given collection contains all elements of this collection. |
| public Iterator | iterator()
Implements abstract java. Implements java. Returns an iterator over the elements in this set. |
| public int | size()
Implements abstract java. Implements java. Returns the number of elements in this set (its cardinality). |
| elements | back to summary |
|---|---|
| private final T[] elements | |
| size | back to summary |
|---|---|
| private int size | |
| Hashless | back to summary |
|---|---|
private Hashless(int capacity)
| |
| add | back to summary |
|---|---|
| public boolean add(T e) Overrides java. Implements java. Doc from java. Adds the specified element to this set if it is not already present
(optional operation). More formally, adds the specified element
The stipulation above does not imply that sets must accept all
elements; sets may refuse to add any particular element, including
| |
| contains | back to summary |
|---|---|
| public boolean contains(Object o) Overrides java. Implements java. Doc from java. Returns
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implements java. Doc from java. Returns the hash code value for this set. The hash code of a set is
defined to be the sum of the hash codes of the elements in the set,
where the hash code of a This implementation iterates over the set, calling the
| |
| isSuperSetOf | back to summary |
|---|---|
| public boolean isSuperSetOf(Collection<?> c) Implements abstract com. Doc from com. Checks if the given collection contains all elements
of this collection. This is the same as If the given collection is small, or has good
| |
| iterator | back to summary |
|---|---|
| public Iterator Implements abstract java. Implements java. Doc from java. Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).
| |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Doc from java. Returns the number of elements in this set (its cardinality). If this
set contains more than
| |
HashSet but
has worse worst case performance (for modification and contains) when there
are many collisions. Iteration speed will be similar to other array based
collections (which is to say, faster than HashSet).
| Modifier and Type | Field and Description |
|---|---|
| private final T[] | |
| private final int | |
| private final int | |
| private int |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | add(T e)
Overrides java. Implements java. Adds the specified element to this set if it is not already present (optional operation). |
| public boolean | contains(Object o)
Overrides java. Implements java. Returns |
| private int | |
| public int | hashCode()
Overrides java. Implements java. Returns the hash code value for this set. |
| public boolean | isSuperSetOf(Collection<?> c)
Implements abstract com. Checks if the given collection contains all elements of this collection. |
| public Iterator | iterator()
Implements abstract java. Implements java. Returns an iterator over the elements in this set. |
| public int | size()
Implements abstract java. Implements java. Returns the number of elements in this set (its cardinality). |
| elements | back to summary |
|---|---|
| private final T[] elements | |
| mask | back to summary |
|---|---|
| private final int mask | |
| requestedCapacity | back to summary |
|---|---|
| private final int requestedCapacity | |
| size | back to summary |
|---|---|
| private int size | |
| OpenAddressed | back to summary |
|---|---|
private OpenAddressed(int capacity)
| |
| add | back to summary |
|---|---|
| public boolean add(T e) Overrides java. Implements java. Doc from java. Adds the specified element to this set if it is not already present
(optional operation). More formally, adds the specified element
The stipulation above does not imply that sets must accept all
elements; sets may refuse to add any particular element, including
| |
| contains | back to summary |
|---|---|
| public boolean contains(Object o) Overrides java. Implements java. Doc from java. Returns
| |
| determineBucketIndex | back to summary |
|---|---|
| private int determineBucketIndex(Object o) | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implements java. Doc from java. Returns the hash code value for this set. The hash code of a set is
defined to be the sum of the hash codes of the elements in the set,
where the hash code of a This implementation iterates over the set, calling the
| |
| isSuperSetOf | back to summary |
|---|---|
| public boolean isSuperSetOf(Collection<?> c) Implements abstract com. Doc from com. Checks if the given collection contains all elements
of this collection. This is the same as If the given collection is small, or has good
| |
| iterator | back to summary |
|---|---|
| public Iterator Implements abstract java. Implements java. Doc from java. Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).
| |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Doc from java. Returns the number of elements in this set (its cardinality). If this
set contains more than
| |
| Modifier and Type | Field and Description |
|---|---|
| private T |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | add(T e)
Overrides java. Implements java. Adds the specified element to this set if it is not already present (optional operation). |
| public boolean | contains(Object o)
Overrides java. Implements java. Returns |
| public int | hashCode()
Overrides java. Implements java. Returns the hash code value for this set. |
| public boolean | isSuperSetOf(Collection<?> c)
Implements abstract com. Checks if the given collection contains all elements of this collection. |
| public Iterator | iterator()
Implements abstract java. Implements java. Returns an iterator over the elements in this set. |
| public int | size()
Implements abstract java. Implements java. Returns the number of elements in this set (its cardinality). |
| element | back to summary |
|---|---|
| private T element | |
| Single | back to summary |
|---|---|
| private Single() | |
| add | back to summary |
|---|---|
| public boolean add(T e) Overrides java. Implements java. Doc from java. Adds the specified element to this set if it is not already present
(optional operation). More formally, adds the specified element
The stipulation above does not imply that sets must accept all
elements; sets may refuse to add any particular element, including
| |
| contains | back to summary |
|---|---|
| public boolean contains(Object o) Overrides java. Implements java. Doc from java. Returns
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Implements java. Doc from java. Returns the hash code value for this set. The hash code of a set is
defined to be the sum of the hash codes of the elements in the set,
where the hash code of a This implementation iterates over the set, calling the
| |
| isSuperSetOf | back to summary |
|---|---|
| public boolean isSuperSetOf(Collection<?> c) Implements abstract com. Doc from com. Checks if the given collection contains all elements
of this collection. This is the same as If the given collection is small, or has good
| |
| iterator | back to summary |
|---|---|
| public Iterator Implements abstract java. Implements java. Doc from java. Returns an iterator over the elements in this set. The elements are returned in no particular order (unless this set is an instance of some class that provides a guarantee).
| |
| size | back to summary |
|---|---|
| public int size() Implements abstract java. Implements java. Doc from java. Returns the number of elements in this set (its cardinality). If this
set contains more than
| |