public T lower(long sequence, boolean inclusive) {
    Entry<Long, T> lower = index.floorEntry(sequence);
    if (lower == null) {
      return null;
    }

    if (inclusive) {
      return lower.getValue();
    }

    if (lower.getKey() == sequence) {
      return lower.getValue().prev;
    } else {
      return lower.getValue();
    }
  }
  public T upper(long sequence, boolean inclusive) {
    if (head == null || head.prev.getSequence() < sequence) {
      return null;
    }

    Entry<Long, T> upper = index.ceilingEntry(sequence);
    if (upper == null) {
      return null;
    }

    if (inclusive) {
      return upper.getValue();
    }

    if (upper.getKey() == sequence) {
      return upper.getValue().next;
    } else {
      return upper.getValue();
    }
  }
 public void add(T node) {
   T prev = null;
   if (head != null) {
     // Optimize for case where this is at tail:
     if (head.prev.getSequence() < node.getSequence()) {
       prev = head.prev;
     } else {
       Entry<Long, T> entry = index.lowerEntry(node.getSequence());
       if (entry != null) {
         prev = entry.getValue();
       }
     }
   }
   // T prev = index.lower(node);
   // If this the lowest then the new head is this.
   if (prev == null) {
     node.linkToHead(this);
   } else {
     prev.linkAfter(node);
   }
 }
 /** @param sequence The sequence number of the element to get. */
 public T get(long sequence) {
   return index.get(sequence);
 }
 public void clear() {
   while (head != null) {
     head.unlink();
   }
   index.clear();
 }