public class LinkedList extends AbstractSequentialList implements List, java.lang.Cloneable, java.io.Serializable, Rollbackable
LinkedList is not synchronized, so if you need multi-threaded access,
consider using:
List l = Collections.synchronizedList(new LinkedList(...));
The iterators are fail-fast, meaning that any structural
modification, except for remove()
called on the iterator
itself, cause the iterator to throw a{
List
,
ArrayList
,
Vector
,
Collections.synchronizedList(List)
,
Serialized Form$CHECKPOINT, $RECORD$$CHECKPOINT
Constructor and Description |
---|
LinkedList()
Create an empty linked list.
|
LinkedList(Collection c)
Create a linked list containing the elements, in order, of a given
collection.
|
Modifier and Type | Method and Description |
---|---|
void |
$COMMIT(long timestamp)
Commit changes up to the given timestamp, but not including changes
made at timestamp and afterward.
|
void |
$RESTORE(long timestamp,
boolean trim)
Restore a previous state to all the private fields of this rollbackable
object.
|
void |
add(int index,
java.lang.Object o)
Inserts an element in the given position in the list.
|
boolean |
add(java.lang.Object o)
Adds an element to the end of the list.
|
boolean |
addAll(Collection c)
Append the elements of the collection in iteration order to the end of
this list.
|
boolean |
addAll(int index,
Collection c)
Insert the elements of the collection in iteration order at the given
index of this list.
|
void |
addFirst(java.lang.Object o)
Insert an element at the first of the list.
|
void |
addLast(java.lang.Object o)
Insert an element at the last of the list.
|
void |
clear()
Remove all elements from this list.
|
java.lang.Object |
clone()
Create a shallow copy of this LinkedList (the elements are not cloned).
|
boolean |
contains(java.lang.Object o)
Returns true if the list contains the given object.
|
java.lang.Object |
get(int index)
Return the element at index.
|
java.lang.Object |
getFirst()
Returns the first element in the list.
|
java.lang.Object |
getLast()
Returns the last element in the list.
|
int |
indexOf(java.lang.Object o)
Returns the first index where the element is located in the list, or -1.
|
int |
lastIndexOf(java.lang.Object o)
Returns the last index where the element is located in the list, or -1.
|
java.util.ListIterator |
listIterator(int index)
Obtain a ListIterator over this list, starting at a given index.
|
java.lang.Object |
remove(int index)
Removes the element at the given position from the list.
|
boolean |
remove(java.lang.Object o)
Removes the entry at the lowest index in the list that matches the given
object, comparing by
o == null ? e = null : o.equals(e) . |
java.lang.Object |
removeFirst()
Remove and return the first element in the list.
|
java.lang.Object |
removeLast()
Remove and return the last element in the list.
|
java.lang.Object |
set(int index,
java.lang.Object o)
Replace the element at the given location in the list.
|
int |
size()
Returns the size of the list.
|
java.lang.Object[] |
toArray()
Returns an array which contains the elements of the list in order.
|
java.lang.Object[] |
toArray(java.lang.Object[] a)
Returns an Array whose component type is the runtime component type of
the passed-in Array.
|
iterator
equals, getModCount, hashCode, listIterator, removeRange, setModCount, subList
$GET$CHECKPOINT, $SET$CHECKPOINT, containsAll, isEmpty, removeAll, retainAll, toString
finalize, getClass, notify, notifyAll, wait, wait, wait
$GET$CHECKPOINT, $SET$CHECKPOINT, containsAll, equals, hashCode, isEmpty, iterator, listIterator, removeAll, retainAll, subList
public LinkedList()
public LinkedList(Collection c)
c
- the collection to populate this list fromjava.lang.NullPointerException
- if c is nullpublic java.lang.Object getFirst()
java.util.NoSuchElementException
- if the list is emptypublic java.lang.Object getLast()
java.util.NoSuchElementException
- if the list is emptypublic java.lang.Object removeFirst()
java.util.NoSuchElementException
- if the list is emptypublic java.lang.Object removeLast()
java.util.NoSuchElementException
- if the list is emptypublic void addFirst(java.lang.Object o)
o
- the element to insertpublic void addLast(java.lang.Object o)
o
- the element to insertpublic boolean contains(java.lang.Object o)
o == null ? e = null : o.equals(e)
.contains
in interface Collection
contains
in interface List
contains
in class AbstractCollection
o
- the element to look forpublic int size()
size
in interface Collection
size
in interface List
size
in class AbstractCollection
public boolean add(java.lang.Object o)
add
in interface Collection
add
in interface List
add
in class AbstractList
o
- the entry to addAbstractList.add(int, Object)
public boolean remove(java.lang.Object o)
o == null ? e = null : o.equals(e)
.remove
in interface Collection
remove
in interface List
remove
in class AbstractCollection
o
- the object to removeIterator.remove()
public boolean addAll(Collection c)
addAll
in interface Collection
addAll
in interface List
addAll
in class AbstractCollection
c
- the collection to appendjava.lang.NullPointerException
- if c is nullAbstractCollection.add(Object)
public boolean addAll(int index, Collection c)
addAll
in interface List
addAll
in class AbstractSequentialList
c
- the collection to appendindex
- the location to insert the collectionjava.lang.NullPointerException
- if c is nulljava.lang.IndexOutOfBoundsException
- if index < 0 || index > size()AbstractSequentialList.add(int, Object)
public void clear()
clear
in interface Collection
clear
in interface List
clear
in class AbstractList
AbstractList.remove(int)
,
AbstractList.removeRange(int, int)
public java.lang.Object get(int index)
get
in interface List
get
in class AbstractSequentialList
index
- the place to lookjava.lang.IndexOutOfBoundsException
- if index < 0 || index >= size()public java.lang.Object set(int index, java.lang.Object o)
set
in interface List
set
in class AbstractSequentialList
index
- which index to changeo
- the new elementjava.lang.IndexOutOfBoundsException
- if index < 0 || index >= size()public void add(int index, java.lang.Object o)
add
in interface List
add
in class AbstractSequentialList
index
- where to insert the elemento
- the element to insertjava.lang.IndexOutOfBoundsException
- if index < 0 || index > size()AbstractList.modCount
public java.lang.Object remove(int index)
remove
in interface List
remove
in class AbstractSequentialList
index
- the location of the element to removejava.lang.IndexOutOfBoundsException
- if index < 0 || index > size()AbstractList.modCount
public int indexOf(java.lang.Object o)
indexOf
in interface List
indexOf
in class AbstractList
o
- the element to look forpublic int lastIndexOf(java.lang.Object o)
lastIndexOf
in interface List
lastIndexOf
in class AbstractList
o
- the element to look forpublic java.util.ListIterator listIterator(int index)
listIterator
in interface List
listIterator
in class AbstractSequentialList
index
- the index of the element to be returned by the first call to
next(), or size() to be initially positioned at the end of the listjava.lang.IndexOutOfBoundsException
- if index < 0 || index > size()AbstractList.modCount
public java.lang.Object clone()
clone
in class java.lang.Object
public java.lang.Object[] toArray()
toArray
in interface Collection
toArray
in interface List
toArray
in class AbstractCollection
public java.lang.Object[] toArray(java.lang.Object[] a)
toArray
in interface Collection
toArray
in interface List
toArray
in class AbstractCollection
a
- the passed-in Arrayjava.lang.ArrayStoreException
- if the runtime type of a does not allow
an element in this listjava.lang.NullPointerException
- if a is nullpublic void $COMMIT(long timestamp)
Rollbackable
$COMMIT
in interface Rollbackable
$COMMIT
in interface Collection
$COMMIT
in interface List
$COMMIT
in class AbstractSequentialList
timestamp
- The timestamp.public void $RESTORE(long timestamp, boolean trim)
Rollbackable
$RESTORE
in interface Rollbackable
$RESTORE
in interface Collection
$RESTORE
in interface List
$RESTORE
in class AbstractSequentialList
timestamp
- The timestamp taken at the time when the previous
state was recorded.trim
- Whether to delete the records used for the rollback.Checkpoint.rollback(long, boolean)