public class ReferenceArraySet<K> extends AbstractReferenceSet<K> implements java.io.Serializable, java.lang.Cloneable
The main purpose of this implementation is that of wrapping cleanly the brute-force approach to the storage of a very small number of items: just put them into an array and scan linearly to find an item.
Constructor and Description |
---|
ReferenceArraySet()
Creates a new empty array set.
|
ReferenceArraySet(java.util.Collection<? extends K> c)
Creates a new array set copying the contents of a given set.
|
ReferenceArraySet(int capacity)
Creates a new empty array set of given initial capacity.
|
ReferenceArraySet(java.lang.Object[] a)
Creates a new array set using the given backing array.
|
ReferenceArraySet(java.lang.Object[] a,
int size)
Creates a new array set using the given backing array and the given number of elements of the array.
|
ReferenceArraySet(ReferenceCollection<K> c)
Creates a new array set copying the contents of a given collection.
|
ReferenceArraySet(ReferenceSet<K> c)
Creates a new array set copying the contents of a given collection.
|
ReferenceArraySet(java.util.Set<? extends K> c)
Creates a new array set copying the contents of a given set.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(K k) |
void |
clear() |
ReferenceArraySet<K> |
clone()
Returns a deep copy of this set.
|
boolean |
contains(java.lang.Object k) |
boolean |
isEmpty() |
ObjectIterator<K> |
iterator()
Returns a type-specific iterator on the elements of this collection.
|
static <K> ReferenceArraySet<K> |
of()
Creates a new empty array set.
|
static <K> ReferenceArraySet<K> |
of(K... a)
Creates a new array set using an array of elements.
|
static <K> ReferenceArraySet<K> |
of(K e)
Creates a new array set using the element given.
|
static <K> ReferenceArraySet<K> |
ofUnchecked()
Creates a new empty array set.
|
static <K> ReferenceArraySet<K> |
ofUnchecked(K... a)
Creates a new array set using an array of elements.
|
boolean |
remove(java.lang.Object k) |
int |
size() |
ObjectSpliterator<K> |
spliterator()
Returns a type-specific spliterator on the elements of this set.
|
java.lang.Object[] |
toArray() |
<K> K[] |
toArray(K[] a) |
equals, hashCode
toString
of, of
public ReferenceArraySet(java.lang.Object[] a)
It is the responsibility of the caller to ensure that the elements of a
are distinct.
a
- the backing array.public ReferenceArraySet()
public ReferenceArraySet(int capacity)
capacity
- the initial capacity.public ReferenceArraySet(ReferenceCollection<K> c)
c
- a collection.public ReferenceArraySet(java.util.Collection<? extends K> c)
c
- a collection.public ReferenceArraySet(ReferenceSet<K> c)
c
- a collection.public ReferenceArraySet(java.util.Set<? extends K> c)
c
- a collection.public ReferenceArraySet(java.lang.Object[] a, int size)
It is the responsibility of the caller to ensure that the first size
elements of a
are distinct.
a
- the backing array.size
- the number of valid elements in a
.public static <K> ReferenceArraySet<K> of()
of
in interface ReferenceSet<K>
public static <K> ReferenceArraySet<K> of(K e)
of
in interface ReferenceSet<K>
e
- the element that the returned set will contain.e
.@SafeVarargs public static <K> ReferenceArraySet<K> of(K... a)
Unlike the array accepting constructors, this method will throw if duplicate elements
are encountered. This adds a non-trivial validation burden. Use ofUnchecked()
if you
know your input has no duplicates, which will skip this validation.
of
in interface ReferenceSet<K>
a
- the backing array of the returned array set.a
.java.lang.IllegalArgumentException
- if there were duplicate entries.public static <K> ReferenceArraySet<K> ofUnchecked()
@SafeVarargs public static <K> ReferenceArraySet<K> ofUnchecked(K... a)
It is the responsibility of the caller to ensure that the elements of a
are distinct.
a
- the backing array of the returned array set.a
.public ObjectIterator<K> iterator()
ReferenceCollection
iterator
in interface ObjectIterable<K>
iterator
in interface ReferenceCollection<K>
iterator
in interface ReferenceSet<K>
iterator
in interface java.lang.Iterable<K>
iterator
in interface java.util.Collection<K>
iterator
in interface java.util.Set<K>
iterator
in class AbstractReferenceSet<K>
Iterable.iterator()
public ObjectSpliterator<K> spliterator()
Set spliterators must report at least Spliterator.DISTINCT
.
See Set.spliterator()
for more documentation on the requirements
of the returned spliterator.
In addition to the usual trait of DISTINCT
for
sets, the returned spliterator will also report
the trait ORDERED
.
The returned spliterator is late-binding; it will track structural changes
after the current item, up until the first trySplit()
,
at which point the maximum index will be fixed.
Structural changes before the current item or after the first
trySplit()
will result in unspecified behavior.
spliterator
in interface ObjectIterable<K>
spliterator
in interface ReferenceCollection<K>
spliterator
in interface ReferenceSet<K>
spliterator
in interface java.lang.Iterable<K>
spliterator
in interface java.util.Collection<K>
spliterator
in interface java.util.Set<K>
public boolean contains(java.lang.Object k)
public int size()
public boolean remove(java.lang.Object k)
public boolean add(K k)
public void clear()
public boolean isEmpty()
public java.lang.Object[] toArray()
public <K> K[] toArray(K[] a)
public ReferenceArraySet<K> clone()
This method performs a deep copy of this array set; the data stored in the set, however, is not cloned. Note that this makes a difference only for object keys.
clone
in class java.lang.Object