public static class ObjectLists.Singleton<K> extends AbstractObjectList<K> implements RandomAccess, Serializable, Cloneable
This class may be useful to implement your own in case you subclass a type-specific list.
AbstractObjectList.ObjectSubList<K>| Modifier | Constructor and Description |
|---|---|
protected |
Singleton(K element) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addAll(Collection<? extends K> c) |
boolean |
addAll(int i,
Collection<? extends K> c)
Adds all of the elements in the specified collection to this list (optional operation).
|
void |
addElements(int index,
K[] a)
Add (hopefully quickly) elements to this type-specific list.
|
void |
addElements(int index,
K[] a,
int offset,
int length)
Add (hopefully quickly) elements to this type-specific list.
|
void |
clear() |
Object |
clone() |
boolean |
contains(Object k)
Returns true if this list contains the specified element.
|
K |
get(int i) |
ObjectListIterator<K> |
iterator()
Returns a type-specific iterator on the elements of 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) |
boolean |
remove(Object k) |
boolean |
removeAll(Collection<?> c) |
void |
removeElements(int from,
int to)
Removes (hopefully quickly) elements of this type-specific list.
|
boolean |
retainAll(Collection<?> c) |
void |
setElements(int index,
K[] a)
Set (hopefully quickly) elements to match the array given.
|
void |
setElements(int index,
K[] a,
int offset,
int length)
Set (hopefully quickly) elements to match the array given.
|
void |
setElements(K[] a)
Set (hopefully quickly) elements to match the array given.
|
int |
size() |
void |
size(int size)
Sets the size of this list.
|
void |
sort(Comparator<? super K> comparator) |
ObjectList<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() |
void |
unstableSort(Comparator<? super K> comparator)
Sorts this list using a sort not assured to be stable.
|
add, add, compareTo, ensureIndex, ensureRestrictedIndex, equals, getElements, hashCode, indexOf, lastIndexOf, peek, pop, push, set, top, toStringcontainsAll, isEmpty, toArrayfinalize, getClass, notify, notifyAll, wait, wait, waitcontainsAll, isEmpty, replaceAll, spliterator, toArrayparallelStream, removeIf, streamprotected Singleton(K element)
public boolean remove(Object k)
remove in interface Collection<K>remove in interface List<K>remove in class AbstractCollection<K>public K remove(int i)
AbstractObjectListThis implementation always throws an UnsupportedOperationException.
public boolean contains(Object k)
AbstractObjectListThis implementation delegates to indexOf().
contains in interface Collection<K>contains in interface List<K>contains in class AbstractObjectList<K>List.contains(Object)public Object[] toArray()
toArray in interface Collection<K>toArray in interface List<K>toArray in class AbstractCollection<K>public ObjectListIterator<K> listIterator()
AbstractObjectListThis implementation delegates to listIterator(0).
listIterator in interface ObjectList<K>listIterator in interface List<K>listIterator in class AbstractObjectList<K>List.listIterator()public ObjectListIterator<K> iterator()
AbstractObjectListNote that this specification strengthens the one given in
Iterable.iterator(), which was already
strengthened in the corresponding type-specific class,
but was weakened by the fact that this interface extends Collection.
This implementation delegates to AbstractObjectList.listIterator().
iterator in interface ObjectCollection<K>iterator in interface ObjectIterable<K>iterator in interface ObjectList<K>iterator in interface Iterable<K>iterator in interface Collection<K>iterator in interface List<K>iterator in class AbstractObjectList<K>Iterable.iterator()public ObjectListIterator<K> listIterator(int i)
AbstractObjectListThis implementation is based on the random-access methods.
listIterator in interface ObjectList<K>listIterator in interface List<K>listIterator in class AbstractObjectList<K>List.listIterator(int)public ObjectList<K> subList(int from, int to)
ObjectListfrom, inclusive, to the index to, exclusive.
Note that this specification strengthens the one given in List.subList(int,int).
subList in interface ObjectList<K>subList in interface List<K>subList in class AbstractObjectList<K>List.subList(int,int)public boolean addAll(int i,
Collection<? extends K> c)
AbstractObjectListpublic boolean addAll(Collection<? extends K> c)
AbstractObjectListThis 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 AbstractObjectList<K>public boolean removeAll(Collection<?> c)
removeAll in interface Collection<K>removeAll in interface List<K>removeAll in class AbstractCollection<K>public boolean retainAll(Collection<?> c)
retainAll in interface Collection<K>retainAll in interface List<K>retainAll in class AbstractCollection<K>public void sort(Comparator<? super K> comparator)
public void unstableSort(Comparator<? super K> comparator)
ObjectListList.sort(java.util.Comparator) in that the results are
not assured to be stable, but may be a bit faster.
Unless a subclass specifies otherwise, the results of the method if the list is concurrently modified during the sort are unspecified.
unstableSort in interface ObjectList<K>public void removeElements(int from,
int to)
AbstractObjectListThis is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.
removeElements in interface ObjectList<K>removeElements in class AbstractObjectList<K>from - the start index (inclusive).to - the end index (exclusive).public void addElements(int index,
K[] a)
AbstractObjectListThis implementation delegates to the analogous method for array fragments.
addElements in interface ObjectList<K>addElements in class AbstractObjectList<K>index - the index at which to add elements.a - the array containing the elements.public void addElements(int index,
K[] a,
int offset,
int length)
AbstractObjectListThis is a trivial iterator-based implementation. It is expected that implementations will override this method with a more optimized version.
addElements in interface ObjectList<K>addElements in class AbstractObjectList<K>index - the index at which to add elements.a - the array containing the elements.offset - the offset of the first element to add.length - the number of elements to add.public void setElements(K[] a)
ObjectListsetElements in interface ObjectList<K>a - the array containing the elements.public void setElements(int index,
K[] a)
ObjectListsetElements in interface ObjectList<K>index - the index at which to start setting elements.a - the array containing the elements.public void setElements(int index,
K[] a,
int offset,
int length)
ObjectList
ListIterator iter = listIterator(index);
int i = 0;
while (i < length) {
iter.next();
iter.set(a[offset + i++]);
}
However, the exact implementation may be more efficient, taking into account
whether random access is faster or not, or at the discretion of subclasses,
abuse internals.setElements in interface ObjectList<K>index - the index at which to start setting elements.a - the array containing the elementsoffset - the offset of the first element to add.length - the number of elements to add.public int size()
size in interface Collection<K>size in interface List<K>size in class AbstractCollection<K>public void size(int size)
ObjectListIf 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 ObjectList<K>size in class AbstractObjectList<K>size - the new size.public void clear()
AbstractObjectListThis implementation delegates to AbstractObjectList.removeElements(int, int).
clear in interface Collection<K>clear in interface List<K>clear in class AbstractObjectList<K>Copyright © 2020. All rights reserved.