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); } }
public void addFirst(T node) { node.linkToHead(this); }