public class NodePositionList<E> extends java.lang.Object implements PositionList<E>
| Constructor and Description |
|---|
NodePositionList()
Constructor that creates an empty list; O(1) time
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAfter(Position<E> p,
E element)
Insert the given element after the given position;
O(1) time
|
void |
addBefore(Position<E> p,
E element)
Insert the given element before the given position;
O(1) time
|
void |
addFirst(E element)
Insert the given element at the beginning of the list, returning
the new position; O(1) time
|
void |
addLast(E element)
Insert the given element at the end of the list, returning
the new position; O(1) time
|
Position<E> |
first()
Returns the first position in the list; O(1) time
|
static <E> java.lang.String |
forEachToString(PositionList<E> L)
Returns a textual representation of a given node list using for-each
|
boolean |
isEmpty()
Returns whether the list is empty; O(1) time
|
boolean |
isFirst(Position<E> p)
Returns whether a position is the first one; O(1) time
|
boolean |
isLast(Position<E> p)
Returns whether a position is the last one; O(1) time
|
java.util.Iterator<E> |
iterator()
Returns an iterator of all the elements in the list.
|
Position<E> |
last()
Returns the last position in the list; O(1) time
|
Position<E> |
next(Position<E> p)
Returns the position after the given one; O(1) time
|
java.lang.Iterable<Position<E>> |
positions()
Returns an iterable collection of all the nodes in the list.
|
Position<E> |
prev(Position<E> p)
Returns the position before the given one; O(1) time
|
E |
remove(Position<E> p)
Remove the given position from the list; O(1) time
|
E |
set(Position<E> p,
E element)
Replace the element at the given position with the new element
and return the old element; O(1) time
|
int |
size()
Returns the number of elements in the list; O(1) time
|
void |
swapElements(Position<E> a,
Position<E> b)
Swap the elements of two give positions; O(1) time
|
java.lang.String |
toString()
Returns a textual representation of the list
|
static <E> java.lang.String |
toString(PositionList<E> l)
Returns a textual representation of a given node list
|
public NodePositionList()
public void addAfter(Position<E> p, E element) throws InvalidPositionException
addAfter in interface PositionList<E>InvalidPositionExceptionpublic void addBefore(Position<E> p, E element) throws InvalidPositionException
addBefore in interface PositionList<E>InvalidPositionExceptionpublic void addFirst(E element)
addFirst in interface PositionList<E>public void addLast(E element)
addLast in interface PositionList<E>public Position<E> first() throws EmptyListException
first in interface PositionList<E>EmptyListExceptionpublic static <E> java.lang.String forEachToString(PositionList<E> L)
public boolean isEmpty()
isEmpty in interface PositionList<E>public boolean isFirst(Position<E> p) throws InvalidPositionException
InvalidPositionExceptionpublic boolean isLast(Position<E> p) throws InvalidPositionException
InvalidPositionExceptionpublic java.util.Iterator<E> iterator()
iterator in interface java.lang.Iterable<E>iterator in interface PositionList<E>public 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 java.lang.Iterable<Position<E>> positions()
positions in interface PositionList<E>public Position<E> prev(Position<E> p) throws InvalidPositionException, BoundaryViolationException
prev in interface PositionList<E>InvalidPositionExceptionBoundaryViolationExceptionpublic 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 int size()
size in interface PositionList<E>public void swapElements(Position<E> a, Position<E> b) throws InvalidPositionException
InvalidPositionExceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic static <E> java.lang.String toString(PositionList<E> l)