public class NodePositionList<E> extends java.lang.Object implements PositionList<E>
| Modifier and Type | Field and Description |
|---|---|
protected DNode<E> |
header |
protected int |
size |
protected DNode<E> |
trailer |
| Constructor and Description |
|---|
NodePositionList() |
| Modifier and Type | Method and Description |
|---|---|
void |
addAfter(Position<E> p,
E element)
Inserts an element after position p.
|
void |
addBefore(Position<E> p,
E element)
Inserts an element before position p.
|
void |
addFirst(E element)
Inserts an element at the front of the list.
|
void |
addLast(E element)
Inserts an element at the back of the list.
|
protected DNode<E> |
checkPosition(Position<E> p) |
Position<E> |
first()
Returns the first node in the list.
|
boolean |
isEmpty()
Returns true if the list is empty.
|
Position<E> |
last()
Returns the last node in the list.
|
Position<E> |
next(Position<E> p)
Returns the node after position p.
|
Position<E> |
prev(Position<E> p)
Returns the node before position p.
|
Position<E> |
remove(Position<E> p)
Remove the element at a given position
|
E |
set(Position<E> p,
E element)
Replaces the element stored at the given node
|
int |
size()
Returns the number of elements in this list.
|
java.lang.String |
toString() |
public int size()
size in interface PositionList<E>public boolean isEmpty()
isEmpty in interface PositionList<E>public Position<E> first() throws EmptyListException
first in interface PositionList<E>EmptyListExceptionpublic Position<E> last() throws EmptyListException
last in interface PositionList<E>EmptyListExceptionpublic Position<E> next(Position<E> p) throws InvalidPositionException, BoundaryViolationException
next in interface PositionList<E>InvalidPositionExceptionBoundaryViolationExceptionpublic Position<E> prev(Position<E> p) throws InvalidPositionException, BoundaryViolationException
prev in interface PositionList<E>InvalidPositionExceptionBoundaryViolationExceptionpublic void addBefore(Position<E> p, E element) throws InvalidPositionException
addBefore in interface PositionList<E>InvalidPositionExceptionpublic void addFirst(E element) throws InvalidPositionException
addFirst in interface PositionList<E>InvalidPositionExceptionpublic void addAfter(Position<E> p, E element) throws InvalidPositionException
addAfter in interface PositionList<E>InvalidPositionExceptionpublic void addLast(E element) throws InvalidPositionException
addLast in interface PositionList<E>InvalidPositionExceptionpublic Position<E> remove(Position<E> p) throws InvalidPositionException
remove in interface PositionList<E>InvalidPositionExceptionpublic E set(Position<E> p, E element) throws InvalidPositionException
set in interface PositionList<E>InvalidPositionExceptionpublic java.lang.String toString()
toString in class java.lang.Objectprotected DNode<E> checkPosition(Position<E> p) throws InvalidPositionException
InvalidPositionException