modificato arraysequence in fake e aggiunti una nuova versione. fidato alcuni metodi che restituivano void invece di position. sono necessari ulteriori test
This commit is contained in:
51
sequence/utility/DNodeFake.java
Normal file
51
sequence/utility/DNodeFake.java
Normal file
@@ -0,0 +1,51 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user