public static class ReferenceLists.Singleton<K> extends AbstractReferenceList<K> implements RandomAccess, Serializable, Cloneable
This class may be useful to implement your own in case you subclass a type-specific list.
AbstractReferenceList.ReferenceSubList<K>| Modifier and Type | Method and Description |
|---|---|
boolean |
addAll(Collection<? extends K> c)
Adds all of the elements in the specified collection to this collection
(optional operation).
|
boolean |
addAll(int i,
Collection<? extends K> c)
Adds all of the elements in the specified collection to this list
(optional operation).
|
void |
clear()
Removes all of the elements from this collection (optional operation).
|
Object |
clone()
Creates and returns a copy of this object.
|
boolean |
contains(Object k)
Returns true if this list contains the specified element.
|
K |
get(int i)
Returns the element at the specified position in this list.
|
ObjectListIterator<K> |
iterator()
Returns an iterator over the elements contained in this collection.
|
ObjectListIterator<K> |
listIterator()
Returns a type-specific list iterator on the list.
|
ObjectListIterator<K> |
listIterator(int i)
Returns a type-specific list iterator on the list starting at a given
index.
|
K |
remove(int i)
Removes the element at the specified position in this list (optional
operation).
|
boolean |
remove(Object k)
Removes a single instance of the specified element from this
collection, if it is present (optional operation).
|
boolean |
removeAll(Collection<?> c)
Removes all of this collection's elements that are also contained in the
specified collection (optional operation).
|
boolean |
retainAll(Collection<?> c)
Retains only the elements in this collection that are contained in the
specified collection (optional operation).
|
int |
size()
Returns the number of elements in this collection.
|
void |
size(int size)
Sets the size of this list.
|
ReferenceList<K> |
subList(int from,
int to)
Returns a type-specific view of the portion of this list from the index
from, inclusive, to the index to, exclusive. |
Object[] |
toArray()
Returns an array containing all of the elements in this collection.
|
add, add, addElements, addElements, equals, getElements, hashCode, indexOf, lastIndexOf, peek, pop, push, removeElements, set, top, toStringcontainsAll, isEmpty, toArraycontainsAll, isEmpty, replaceAll, sort, spliterator, toArrayparallelStream, removeIf, streampublic K get(int i)
java.util.Listpublic 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 List<K>remove in class AbstractCollection<K>k - element to be removed from this collection, if presentpublic K remove(int i)
AbstractReferenceList
This implementation always throws an
UnsupportedOperationException.
public boolean contains(Object k)
AbstractReferenceList
This implementation delegates to indexOf().
contains in interface Collection<K>contains in interface List<K>contains in class AbstractReferenceList<K>k - element whose presence in this collection is to be testedList.contains(Object)public Object[] toArray()
java.util.AbstractCollectionThe returned array will be "safe" in that no references to it are maintained by this collection. (In other words, this method must allocate a new array even if this collection is backed by an array). The caller is thus free to modify the returned array.
This method acts as bridge between array-based and collection-based APIs.
This implementation returns an array containing all the elements
returned by this collection's iterator, in the same order, stored in
consecutive elements of the array, starting with index 0.
The length of the returned array is equal to the number of elements
returned by the iterator, even if the size of this collection changes
during iteration, as might happen if the collection permits
concurrent modification during iteration. The size method is
called only as an optimization hint; the correct result is returned
even if the iterator returns a different number of elements.
This method is equivalent to:
List<E> list = new ArrayList<E>(size());
for (E e : this)
list.add(e);
return list.toArray();
toArray in interface Collection<K>toArray in interface List<K>toArray in class AbstractCollection<K>Arrays.asList(Object[])public ObjectListIterator<K> listIterator()
AbstractReferenceList
This implementation delegates to listIterator(0).
listIterator in interface ReferenceList<K>listIterator in interface List<K>listIterator in class AbstractReferenceList<K>List.listIterator()public ObjectListIterator<K> iterator()
AbstractReferenceList
This implementation delegates to AbstractReferenceList.listIterator().
iterator in interface ObjectIterable<K>iterator in interface ReferenceCollection<K>iterator in interface ReferenceList<K>iterator in interface Iterable<K>iterator in interface Collection<K>iterator in interface List<K>iterator in class AbstractReferenceList<K>Iterable.iterator()public ObjectListIterator<K> listIterator(int i)
AbstractReferenceListThis implementation is based on the random-access methods.
listIterator in interface ReferenceList<K>listIterator in interface List<K>listIterator in class AbstractReferenceList<K>i - index of the first element to be returned from the
list iterator (by a call to next)List.listIterator(int)public ReferenceList<K> subList(int from, int to)
ReferenceListfrom, inclusive, to the index to, exclusive.
Note that this specification strengthens the one given in
List.subList(int,int).
subList in interface ReferenceList<K>subList in interface List<K>subList in class AbstractReferenceList<K>from - low endpoint (inclusive) of the subListto - high endpoint (exclusive) of the subListList.subList(int,int)public boolean addAll(int i,
Collection<? extends K> c)
AbstractReferenceListaddAll in interface List<K>addAll in class AbstractReferenceList<K>i - index at which to insert the first element from the
specified collectionc - collection containing elements to be added to this listpublic boolean addAll(Collection<? extends K> c)
AbstractReferenceListThis implementation iterates over the specified collection, and adds each object returned by the iterator to this collection, in turn.
Note that this implementation will throw an UnsupportedOperationException unless add is overridden (assuming the specified collection is non-empty).
This implementation delegates to the type-specific version of
List.addAll(int, Collection).
addAll in interface Collection<K>addAll in interface List<K>addAll in class AbstractReferenceList<K>c - collection containing elements to be added to this collectionAbstractCollection.add(Object)public boolean removeAll(Collection<?> c)
java.util.AbstractCollectionThis implementation iterates over this collection, checking each element returned by the iterator in turn to see if it's contained in the specified collection. If it's so contained, it's removed from this collection with the iterator's remove method.
Note that this implementation will throw an UnsupportedOperationException if the iterator returned by the iterator method does not implement the remove method and this collection contains one or more elements in common with the specified collection.
removeAll in interface Collection<K>removeAll in interface List<K>removeAll in class AbstractCollection<K>c - collection containing elements to be removed from this collectionAbstractCollection.remove(Object),
AbstractCollection.contains(Object)public boolean retainAll(Collection<?> c)
java.util.AbstractCollectionThis implementation iterates over this collection, checking each element returned by the iterator in turn to see if it's contained in the specified collection. If it's not so contained, it's removed from this collection with the iterator's remove method.
Note that this implementation will throw an UnsupportedOperationException if the iterator returned by the iterator method does not implement the remove method and this collection contains one or more elements not present in the specified collection.
retainAll in interface Collection<K>retainAll in interface List<K>retainAll in class AbstractCollection<K>c - collection containing elements to be retained in this collectionAbstractCollection.remove(Object),
AbstractCollection.contains(Object)public int size()
java.util.Collectionsize in interface Collection<K>size in interface List<K>size in class AbstractCollection<K>public void size(int size)
ReferenceList
If the specified size is smaller than the current size, the last elements
are discarded. Otherwise, they are filled with
0/null/false.
size in interface ReferenceList<K>size in class AbstractReferenceList<K>size - the new size.public void clear()
AbstractReferenceListThis 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.
This implementation delegates to AbstractReferenceList.removeElements(int, int).
clear in interface Collection<K>clear in interface List<K>clear in class AbstractReferenceList<K>public Object clone()
java.lang.Objectx, the expression:
will be true, and that the expression:x.clone() != x
will bex.clone().getClass() == x.getClass()
true, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x)
true, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
super.clone. If a class and all of its superclasses (except
Object) obey this convention, it will be the case that
x.clone().getClass() == x.getClass().
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by super.clone before returning it. Typically, this means
copying any mutable objects that comprise the internal "deep structure"
of the object being cloned and replacing the references to these
objects with references to the copies. If a class contains only
primitive fields or references to immutable objects, then it is usually
the case that no fields in the object returned by super.clone
need to be modified.
The method clone for class Object performs a
specific cloning operation. First, if the class of this object does
not implement the interface Cloneable, then a
CloneNotSupportedException is thrown. Note that all arrays
are considered to implement the interface Cloneable and that
the return type of the clone method of an array type T[]
is T[] where T is any reference or primitive type.
Otherwise, this method creates a new instance of the class of this
object and initializes all its fields with exactly the contents of
the corresponding fields of this object, as if by assignment; the
contents of the fields are not themselves cloned. Thus, this method
performs a "shallow copy" of this object, not a "deep copy" operation.
The class Object does not itself implement the interface
Cloneable, so calling the clone method on an object
whose class is Object will result in throwing an
exception at run time.