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 ArraySequence public class ArrayPosition implements Position { private E element = null; private int index = -1; public ArrayPosition(E elem, int in_idex) { element = elem; index = in_idex; } public ArrayPosition(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; } }