示例#1
0
 /**
  * Remove the supplied node
  *
  * @param n The node to be removed
  * @return Whether node was removed (If it returns false, the node does not exist in the list)
  */
 private boolean removeNode(DoubleNode<E> n) {
   if (contains(n)) {
     n.getPrev().setNext(n.getNext());
     n.getNext().setPrev(n.getPrev());
     n = null;
     size--;
     return true;
   }
   return false;
 }
示例#2
0
 /**
  * Add an item before the supplied node
  *
  * @param node The node to add before
  * @param value The value to add
  */
 private void addBefore(DoubleNode<E> node, E value) {
   if (node == head) {
     throw new IllegalArgumentException("Cannot add node before head");
   }
   DoubleNode<E> n = new DoubleNode<>(value);
   node.getPrev().setNext(n);
   n.setPrev(node.getPrev());
   node.setPrev(n);
   n.setNext(node);
   size++;
 }
示例#3
0
 /**
  * Get the last item in the list
  *
  * @return The last item in the list
  */
 public E getLast() {
   return tail.getPrev().getValue();
 }