public class SafeLinkedList extends AbstractList implements List, Cloneable, Serializable
| Modifier and Type | Class and Description |
|---|---|
protected static class |
SafeLinkedList.Node
A Node in the List.
|
| Modifier and Type | Field and Description |
|---|---|
protected int |
m_cNodes
The size of the List.
|
protected SafeLinkedList.Node |
m_current
The Node at the "cached position" in the List.
|
protected SafeLinkedList.Node |
m_head
The first Node in the List (or null if empty).
|
protected int |
m_iPos
The "cached position" in the List.
|
protected SafeLinkedList.Node |
m_tail
The last Node in the List (or null if empty).
|
modCount| Constructor and Description |
|---|
SafeLinkedList()
Construct an empty List.
|
SafeLinkedList(Collection collection)
Construct a List containing the elements of the specified Collection.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(int i, Object o)
Inserts the specified element at the specified position in this List.
|
boolean |
add(Object o)
Appends the specified element to the end of this List.
|
boolean |
addAll(Collection collection)
Appends all of the elements in the specified collection to the end of this List, in the order that they are returned by the specified collection's iterator.
|
boolean |
addAll(int i, Collection collection)
Inserts all of the elements in the specified collection at the specified location in this List.
|
void |
clear()
Removes all of the elements from this List.
|
Object |
clone()
Create a clone of the SafeLinkedList.
|
boolean |
contains(Object o)
Returns true if this List contains the specified element.
|
boolean |
containsAll(Collection collection)
Returns true if this List contains all of the elements of the specified collection.
|
Object |
get(int i)
Returns the element at the specified position in this List.
|
Object |
getFirst()
Returns the first element in the list, or null if empty.
|
protected SafeLinkedList.Node |
getNode(int i)
Find and return the specified Node.
|
int |
indexOf(Object o)
Returns the index in this List of the first occurrence of the specified element, or -1 if this List does not contain this element.
|
protected SafeLinkedList.Node |
instantiateNode(Object o)
Instantiate a Node.
|
int |
lastIndexOf(Object o)
Returns the index in this List of the last occurrence of the specified element, or -1 if this List does not contain this element.
|
static void |
main(String[] asArg)
Self-test for SafeLinkedList.
|
protected void |
markPosition(int i, SafeLinkedList.Node node)
Remember that a certain Node occurs at a certain index.
|
Object |
remove(int i)
Removes the element at the specified position in this List.
|
boolean |
remove(Object o)
Removes the first occurrence in this List of the specified element.
|
Object |
removeFirst()
Removes and returns the first element in the list.
|
protected void |
reset()
Completely reset the state of the List.
|
Object |
set(int i, Object o)
Replaces the element at the specified position in this List with the specified element.
|
int |
size()
Returns the number of elements in this List.
|
Object[] |
toArray()
Returns an array containing all of the elements in this List in the order that the elements occur in the List.
|
Object[] |
toArray(Object[] a)
Returns an array with a runtime type is that of the specified array and that contains all of the elements in this List.
|
equals, hashCode, iterator, listIterator, listIterator, removeRange, subListisEmpty, removeAll, retainAll, toStringfinalize, getClass, notify, notifyAll, wait, wait, waitequals, hashCode, isEmpty, iterator, listIterator, listIterator, removeAll, replaceAll, retainAll, sort, spliterator, subListparallelStream, removeIf, streamprotected SafeLinkedList.Node m_head
protected SafeLinkedList.Node m_tail
protected volatile int m_cNodes
protected transient int m_iPos
protected transient SafeLinkedList.Node m_current
public SafeLinkedList()
public SafeLinkedList(Collection collection)
collection - the Collection to fill this List frompublic int size()
synchronized(list) { int c = list.size() ... }
size in interface Collectionsize in interface Listsize in class AbstractCollectionpublic boolean add(Object o)
add in interface Collectionadd in interface Listadd in class AbstractListo - element to be appended to this Listpublic boolean remove(Object o)
remove in interface Collectionremove in interface Listremove in class AbstractCollectiono - element to be removed from this List, if presentpublic boolean contains(Object o)
contains in interface Collectioncontains in interface Listcontains in class AbstractCollectiono - element whose presence in this List is to be testedpublic boolean containsAll(Collection collection)
containsAll in interface CollectioncontainsAll in interface ListcontainsAll in class AbstractCollectioncollection - collection to be checked for containment in this Listpublic int indexOf(Object o)
indexOf in interface ListindexOf in class AbstractListo - element to search for.public int lastIndexOf(Object o)
lastIndexOf in interface ListlastIndexOf in class AbstractListo - element to search for.
public void add(int i,
Object o)
add in interface Listadd in class AbstractListi - the index at which to insert the specified elemento - element to be insertedIndexOutOfBoundsException - if the index is out of range (index < 0 || index > size()).public Object remove(int i)
remove in interface Listremove in class AbstractListi - the index of the element to removedIndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()).public Object removeFirst()
public Object get(int i)
get in interface Listget in class AbstractListi - the index of the element to returnIndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size()).public Object getFirst()
public Object set(int i, Object o)
set in interface Listset in class AbstractListi - the index of the element to replaceo - the value to be stored at the specified positionIndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
public boolean addAll(int i,
Collection collection)
addAll in interface ListaddAll in class AbstractListi - the index at which insertion will occurcollection - a collection whose elements are to be inserted into this ListIndexOutOfBoundsException - if the index is out of range (index < 0 || index > size()).public boolean addAll(Collection collection)
addAll in interface CollectionaddAll in interface ListaddAll in class AbstractCollectioncollection - a collection whose elements are to be added to this Listpublic void clear()
clear in interface Collectionclear in interface Listclear in class AbstractListpublic Object[] toArray()
toArray in interface CollectiontoArray in interface ListtoArray in class AbstractCollectionpublic Object[] toArray(Object[] a)
If the List fits in the specified array with room to spare (i.e., the array has more elements than the List), the element in the array immediately following the end of the last element is set to null. This is useful in determining the length of the List only if the caller knows that the List does not contain any null elements.)
toArray in interface CollectiontoArray in interface ListtoArray in class AbstractCollectiona - the array into which the elements of the List are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purposeArrayStoreException - if the runtime type of the specified array is not a supertype of the runtime type of every element in this Listpublic Object clone()
protected void markPosition(int i,
SafeLinkedList.Node node)
i - the index; the marker is updated only if the index is greater than zero and less than size() - 1node - the Nodeprotected void reset()
protected SafeLinkedList.Node instantiateNode(Object o)
o - the value for the Nodeprotected SafeLinkedList.Node getNode(int i)
i - the Node indexIndexOutOfBoundsException - if the index is out of range (index < 0 || index > size()).