public class ReferenceArraySet<K> extends AbstractReferenceSet<K> implements Serializable, 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(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(Object[] a)
Creates a new array set using the given backing array.
|
ReferenceArraySet(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.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(K k)
Ensures that this collection contains the specified element (optional
operation).
|
void |
clear()
Removes all of the elements from this collection (optional operation).
|
ReferenceArraySet<K> |
clone()
Returns a deep copy of this set.
|
boolean |
contains(Object k)
Returns true if this collection contains the specified element.
|
boolean |
isEmpty()
Returns true if this collection contains no elements.
|
ObjectIterator<K> |
iterator()
Returns an iterator over the elements contained in this collection.
|
boolean |
remove(Object k)
Removes a single instance of the specified element from this
collection, if it is present (optional operation).
|
int |
size()
Returns the number of elements in this collection.
|
equals, hashCodetoStringaddAll, containsAll, removeAll, retainAll, toArray, toArrayaddAll, containsAll, removeAll, retainAll, spliterator, toArray, toArrayparallelStream, removeIf, streampublic ReferenceArraySet(Object[] a)
It is responsibility of the caller 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(Collection<? extends K> c)
c - a collection.public ReferenceArraySet(Object[] a, int size)
It is responsibility of the caller that the first size elements
of a are distinct.
a - the backing array.size - the number of valid elements in a.public ObjectIterator<K> iterator()
java.util.AbstractCollectioniterator in interface ObjectIterable<K>iterator in interface ReferenceCollection<K>iterator in interface ReferenceSet<K>iterator in interface Iterable<K>iterator in interface Collection<K>iterator in interface Set<K>iterator in class AbstractReferenceSet<K>Iterable.iterator()public boolean contains(Object k)
java.util.AbstractCollectionThis implementation iterates over the elements in the collection, checking each element in turn for equality with the specified element.
contains in interface Collection<K>contains in interface Set<K>contains in class AbstractCollection<K>k - element whose presence in this collection is to be testedpublic int size()
java.util.Collectionsize in interface Collection<K>size in interface Set<K>size in class AbstractCollection<K>public boolean remove(Object k)
java.util.AbstractCollectionThis implementation iterates over the collection looking for the specified element. If it finds the element, it removes the element from the collection using the iterator's remove method.
Note that this implementation throws an UnsupportedOperationException if the iterator returned by this collection's iterator method does not implement the remove method and this collection contains the specified object.
remove in interface Collection<K>remove in interface Set<K>remove in class AbstractCollection<K>k - element to be removed from this collection, if presentpublic boolean add(K k)
java.util.AbstractCollectionCollections that support this operation may place limitations on what elements may be added to this collection. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.
If a collection refuses to add a particular element for any reason other than that it already contains the element, it must throw an exception (rather than returning false). This preserves the invariant that a collection always contains the specified element after this call returns.
This implementation always throws an UnsupportedOperationException.
add in interface Collection<K>add in interface Set<K>add in class AbstractCollection<K>k - element whose presence in this collection is to be ensuredpublic void clear()
java.util.AbstractCollectionThis implementation iterates over this collection, removing each element using the Iterator.remove operation. Most implementations will probably choose to override this method for efficiency.
Note that this implementation will throw an UnsupportedOperationException if the iterator returned by this collection's iterator method does not implement the remove method and this collection is non-empty.
clear in interface Collection<K>clear in interface Set<K>clear in class AbstractCollection<K>public boolean isEmpty()
java.util.AbstractCollectionThis implementation returns size() == 0.
isEmpty in interface Collection<K>isEmpty in interface Set<K>isEmpty in class AbstractCollection<K>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.