public class DoubleNode<C> {
private C data;
private DoubleNode<C> next,prev;
public DoubleNode(C the_data){
data=the_data;
next=null;
prev=null;
}
public C getData(){
return data;
}
public void setNext(DoubleNode<C> theNext){
next=theNext;
}
public DoubleNode<C> getNext(){
return next;
}
public void setPrev(DoubleNode<C> thePrev){
prev=thePrev;
}
public DoubleNode<C> getPrev(){
return prev;
}
public void print(){
System.out.println(this.toString());
}
public String toString() {
return "[" + data.toString() + ";" + formatRef(prev) + ";" + formatRef(next) + "]";
}
private static <T>String formatRef(DoubleNode<T> ref) {
if (ref == null)
return "null";
else
return "<" + ref.data.toString() + ">";
}
public static void main(String [] args) {
DoubleNode<String> node=new DoubleNode<>("foo");
DoubleNode<String> other=new DoubleNode<>("bar");
node.setNext(other);
other.setPrev(node);
System.out.println(node.toString());
}
}