public void insertBefore(Node node) { NodeImpl nodeImpl = (NodeImpl) node; if (logger.isDebugEnabled()) { logger.debug("Inserting " + this + " before " + nodeImpl); } if (CHECK_INVARIANTS) { checkIsolated(); nodeImpl.checkInvariants(); } // Update this node's links. previous = nodeImpl.previous; next = nodeImpl; parent = nodeImpl.parent; // Update the links in the tree. if (previous == null) { // This node is the first in the list so we need to make it the head. parent.head = this; } else { // Add a link forward to this node. previous.next = this; } // Make this node the previous node before the one in the tree. nodeImpl.previous = this; if (CHECK_INVARIANTS) { nodeImpl.checkInvariants(); } }
public void insertAfter(Node node) { NodeImpl nodeImpl = (NodeImpl) node; if (logger.isDebugEnabled()) { logger.debug("Inserting " + this + " after " + nodeImpl); } if (CHECK_INVARIANTS) { checkIsolated(); nodeImpl.checkInvariants(); } // Update this node's links. previous = nodeImpl; next = nodeImpl.next; parent = nodeImpl.parent; // Update the links in the tree. if (next == null) { // This node is the last in the list so we need to make this node // the tail. parent.tail = this; } else { // Add a link back to this node. next.previous = this; } // Make this node the next node after the one in the tree. nodeImpl.next = this; if (CHECK_INVARIANTS) { nodeImpl.checkInvariants(); } }
public void remove() { if (logger.isDebugEnabled()) { logger.debug("Removing " + this); } if (CHECK_INVARIANTS) { checkInvariants(); } if (previous == null) { // This node is the first in the list so update the parent element's // head to reference the next node. parent.head = next; } else { // Update the previous node's next link so that it references the node // after this one. previous.next = next; } if (next == null) { // This node is the last in the list so update the parent element's // tail to reference the previous node. parent.tail = previous; } else { // Update the next node's previous link so that it references the node // before this one. next.previous = previous; } ElementImpl oldParent = parent; // Reset this node. previous = null; parent = null; next = null; if (CHECK_INVARIANTS) { oldParent.checkInvariants(); checkIsolated(); } }
/** * Replace this node with the specified node. * * @param node The node which will replace this one. */ private void replaceWith(NodeImpl node) { if (logger.isDebugEnabled()) { logger.debug("Replacing " + this + " with " + node); } if (CHECK_INVARIANTS) { node.checkIsolated(); checkInvariants(); } if (previous == null) { parent.head = node; } else { previous.next = node; } if (next == null) { parent.tail = node; } else { next.previous = node; } node.parent = parent; node.next = next; node.previous = previous; parent = null; next = null; previous = null; if (CHECK_INVARIANTS) { node.checkInvariants(); checkIsolated(); } }