52 lines
1.0 KiB
Java
52 lines
1.0 KiB
Java
package sequence.utility;
|
|
|
|
import exceptions.InvalidPositionException;
|
|
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
|
|
|
|
// used on ArraySequenceFake
|
|
|
|
|
|
public class DNodeFake<E> implements Position<E> {
|
|
private E element = null;
|
|
private int index = -1;
|
|
|
|
|
|
public DNodeFake(E elem, int in_idex) {
|
|
|
|
element = elem;
|
|
index = in_idex;
|
|
}
|
|
public DNodeFake(E elem) {
|
|
|
|
element = elem;
|
|
}
|
|
|
|
public E element() throws InvalidPositionException {
|
|
if (index == -1)
|
|
throw new InvalidPositionException("Position is not in a list!");
|
|
return element;
|
|
}
|
|
|
|
|
|
public void setElement(E newElement) { element = newElement; }
|
|
|
|
public int getIndex() {
|
|
return index;
|
|
}
|
|
|
|
public void setIndex(int index) {
|
|
this.index = index;
|
|
}
|
|
}
|
|
|