|
net.datastructures - version 5.0 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectnet.datastructures.NodePositionList<E>
public class NodePositionList<E>
Realization of a PositionList using a doubly-linked list of nodes.
| Field Summary | |
|---|---|
protected DNode<E> |
header
|
protected int |
numElts
|
protected DNode<E> |
trailer
|
| Constructor Summary | |
|---|---|
NodePositionList()
Constructor that creates an empty list; O(1) time |
|
| Method Summary | ||
|---|---|---|
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 |
|
protected DNode<E> |
checkPosition(Position<E> p)
Checks if position is valid for this list and converts it to DNode if it is valid; O(1) time |
|
Position<E> |
first()
Returns the first position in the list; O(1) time |
|
static
|
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 |
|
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 |
|
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 |
|
String |
toString()
Returns a textual representation of the list |
|
static
|
toString(PositionList<E> l)
Returns a textual representation of a given node list |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected int numElts
protected DNode<E> header
protected DNode<E> trailer
| Constructor Detail |
|---|
public NodePositionList()
| Method Detail |
|---|
protected DNode<E> checkPosition(Position<E> p)
throws InvalidPositionException
InvalidPositionExceptionpublic 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>EmptyListException
public Position<E> last()
throws EmptyListException
last in interface PositionList<E>EmptyListException
public Position<E> prev(Position<E> p)
throws InvalidPositionException,
BoundaryViolationException
prev in interface PositionList<E>InvalidPositionException
BoundaryViolationException
public Position<E> next(Position<E> p)
throws InvalidPositionException,
BoundaryViolationException
next in interface PositionList<E>InvalidPositionException
BoundaryViolationException
public void addBefore(Position<E> p,
E element)
throws InvalidPositionException
addBefore in interface PositionList<E>InvalidPositionException
public void addAfter(Position<E> p,
E element)
throws InvalidPositionException
addAfter 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 E remove(Position<E> p)
throws InvalidPositionException
remove in interface PositionList<E>InvalidPositionException
public E set(Position<E> p,
E element)
throws InvalidPositionException
set in interface PositionList<E>InvalidPositionExceptionpublic Iterator<E> iterator()
iterator in interface Iterable<E>iterator in interface PositionList<E>public Iterable<Position<E>> positions()
positions in interface PositionList<E>
public boolean isFirst(Position<E> p)
throws InvalidPositionException
InvalidPositionException
public boolean isLast(Position<E> p)
throws InvalidPositionException
InvalidPositionException
public void swapElements(Position<E> a,
Position<E> b)
throws InvalidPositionException
InvalidPositionExceptionpublic static <E> String forEachToString(PositionList<E> L)
public static <E> String toString(PositionList<E> l)
public String toString()
toString in class Object
|
net.datastructures - version 5.0 | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||