/**
  * Returns true if the lists are the same.
  *
  * @return true if the lists contain the same elements in the same order
  * @param list list to compare to current list
  */
 @Override
 public boolean equals(Object list) {
   // resolve simple cases first
   if (list == null) return false;
   if (list == this) return true;
   if (!(list instanceof DoubleLinkedList)) return false;
   // we have to take an object to override correctly so cast it back to a DLL
   DoubleLinkedList castList = (DoubleLinkedList) list;
   castList.resetIterator();
   this.resetIterator();
   // compare element by element
   while (castList.hasNext() && this.hasNext()) {
     if (castList.next().getElement() != this.next().getElement()) {
       return false;
     }
   }
   // lengths are not equal
   if ((castList.hasNext() && !this.hasNext()) || (!castList.hasNext() && this.hasNext())) {
     return false;
   }
   return true;
 }
 /**
  * Appends a list to the current list.
  *
  * @param list appends the nodes of list to the end of this list. list may be destroyed
  */
 public void append(DoubleLinkedList<T> list) {
   list.resetIterator();
   while (list.hasNext()) {
     addToBack(list.next().getElement());
   }
 }