public class DoubleList { private DoubleListNode first; private DoubleListNode last; //Constructor public DoubleList() { this(null,null); } //setters public DoubleList(DoubleListNode f,DoubleListNode l) { setFirst(f); setLast(l); } public void setFirst(DoubleListNode f) { first = f; } public void setLast(DoubleListNode l) { last = l; } public DoubleListNode getLast() { return last; } public DoubleListNode getFirst() { return first; } public boolean isEmpty() { return first == null; } public synchronized void insertAtFront(Object o) { if (isEmpty()) first=last=new DoubleListNode(o); else { DoubleListNode temp = first; first=new DoubleListNode(o); first.setNextNode(temp); temp.setPreviousNode(first); } } public synchronized void insertAtRear(Object o) { if(isEmpty()) last=first=new DoubleListNode(o); else { DoubleListNode temp = last; last = new DoubleListNode(o); last.setPreviousNode(temp); temp.setNextNode(last); } } public String printInverse() { if (isEmpty()) return "empty"; StringBuffer buffer = new StringBuffer(); DoubleListNode current = last; while (current != null ) {buffer.append(current.getData().toString()); current = current.getPreviousNode(); } return buffer.toString(); } }