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