예제 #1
0
  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();
    }
  }
예제 #2
0
  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();
    }
  }
예제 #3
0
 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);
   }
 }
예제 #4
0
 /** @param sequence The sequence number of the element to get. */
 public T get(long sequence) {
   return index.get(sequence);
 }
예제 #5
0
 public void clear() {
   while (head != null) {
     head.unlink();
   }
   index.clear();
 }