Files
unisa_strutture_dati_2013_2014/position/utility/DNode.java

39 lines
1.1 KiB
Java

package position.utility;
import exceptions.*;
import position.Position;
/**
* A simple node class for a doubly-linked list. Each DNode has a
* reference to a stored element, a previous node, and a next node.
*
* @author Roberto Tamassia
*/
//Copyright (c) 2003 Brown University, Providence, RI
//Additional modifications and methods by xgiovio
public class DNode<E> implements Position<E> {
private DNode<E> prev = null;
private DNode<E> next = null;
private E element = null;
public DNode(DNode<E> newPrev, DNode<E> newNext, E elem) {
prev = newPrev;
next = newNext;
element = elem;
}
public E element() throws InvalidPositionException {
if ((prev == null) && (next == null))
throw new InvalidPositionException("Position is not in a list!");
return element;
}
public DNode<E> getNext() { return next; }
public DNode<E> getPrev() { return prev; }
public void setNext(DNode<E> newNext) { next = newNext; }
public void setPrev(DNode<E> newPrev) { prev = newPrev; }
public void setElement(E newElement) { element = newElement; }
}