public abstract class AbstractSequentialList extends AbstractList implements Rollbackable
get
, set
, add
, and
remove
) atop the list iterator, opposite of AbstractList's
approach of implementing the iterator atop random access.
To implement a list, you need an implementation for size()
and listIterator
. With just hasNext
,
next
, hasPrevious
, previous
,
nextIndex
, and previousIndex
, you have an
unmodifiable list. For a modifiable one, add set
, and for
a variable-size list, add add
and remove
.
The programmer should provide a no-argument constructor, and one that accepts another Collection, as recommended by the Collection interface. Unfortunately, there is no way to enforce this in Java.
Collection
,
List
,
AbstractList
,
AbstractCollection
,
ListIterator
,
LinkedList
$CHECKPOINT, $RECORD$$CHECKPOINT
Modifier | Constructor and Description |
---|---|
protected |
AbstractSequentialList()
The main constructor, for use by subclasses.
|
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)
Insert an element into the list at a given position (optional operation).
|
boolean |
addAll(int index,
Collection c)
Insert the contents of a collection into the list at a given position
(optional operation).
|
java.lang.Object |
get(int index)
Get the element at a given index in this list.
|
java.util.Iterator |
iterator()
Obtain an Iterator over this list, whose sequence is the list order.
|
abstract java.util.ListIterator |
listIterator(int index)
Returns a ListIterator over the list, starting from position index.
|
java.lang.Object |
remove(int index)
Remove the element at a given position in this list (optional operation).
|
java.lang.Object |
set(int index,
java.lang.Object o)
Replace an element of this list with another object (optional operation).
|
add, clear, equals, getModCount, hashCode, indexOf, lastIndexOf, listIterator, removeRange, setModCount, subList
$GET$CHECKPOINT, $SET$CHECKPOINT, addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, size, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
$GET$CHECKPOINT, $SET$CHECKPOINT
$GET$CHECKPOINT, $SET$CHECKPOINT, addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, size, toArray, toArray
protected AbstractSequentialList()
public abstract java.util.ListIterator listIterator(int index)
listIterator
in interface List
listIterator
in class AbstractList
index
- the starting position of the listjava.lang.IndexOutOfBoundsException
- if index < 0 || index > size()AbstractList.modCount
public void add(int index, java.lang.Object o)
add
in interface List
add
in class AbstractList
index
- the location to insert the itemo
- the object to insertjava.lang.UnsupportedOperationException
- if this list does not support the
add operationjava.lang.IndexOutOfBoundsException
- if index < 0 || index > size()java.lang.ClassCastException
- if o cannot be added to this list due to its
typejava.lang.IllegalArgumentException
- if o cannot be added to this list for
some other reason.java.lang.NullPointerException
- if o is null and the list does not permit
the addition of null values.AbstractList.modCount
public boolean addAll(int index, Collection c)
This implementation grabs listIterator(index), then proceeds to use add for each element returned by c's iterator. Sun's online specs are wrong, claiming that this also calls next(): listIterator.add() correctly skips the added element.
addAll
in interface List
addAll
in class AbstractList
index
- the location to insert the collectionc
- the collection to insertjava.lang.UnsupportedOperationException
- if this list does not support the
addAll operationjava.lang.IndexOutOfBoundsException
- if index < 0 || index > size()java.lang.ClassCastException
- if some element of c cannot be added to this
list due to its typejava.lang.IllegalArgumentException
- if some element of c cannot be added
to this list for some other reasonjava.lang.NullPointerException
- if the specified collection is nulljava.lang.NullPointerException
- if an object, o, in c is null and the list
does not permit the addition of null values.add(int, Object)
public java.lang.Object get(int index)
get
in interface List
get
in class AbstractList
index
- the index of the element to be returnedjava.lang.IndexOutOfBoundsException
- if index < 0 || index >= size()public java.util.Iterator iterator()
iterator
in interface Collection
iterator
in interface List
iterator
in class AbstractList
AbstractList.modCount
public java.lang.Object remove(int index)
remove
in interface List
remove
in class AbstractList
index
- the position within the list of the object to removejava.lang.UnsupportedOperationException
- if this list does not support the
remove operationjava.lang.IndexOutOfBoundsException
- if index < 0 || index >= size()AbstractList.modCount
public java.lang.Object set(int index, java.lang.Object o)
set
in interface List
set
in class AbstractList
index
- the position within this list of the element to be replacedo
- the object to replace it withjava.lang.UnsupportedOperationException
- if this list does not support the
set operationjava.lang.IndexOutOfBoundsException
- if index < 0 || index >= size()java.lang.ClassCastException
- if o cannot be added to this list due to its
typejava.lang.IllegalArgumentException
- if o cannot be added to this list for
some other reasonjava.lang.NullPointerException
- if o is null and the list does not allow
a value to be set to null.public void $COMMIT(long timestamp)
Rollbackable
$COMMIT
in interface Rollbackable
$COMMIT
in interface Collection
$COMMIT
in interface List
$COMMIT
in class AbstractList
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 AbstractList
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)