/** * Queries whether this task is canceled. A task is considered canceled if it or any of its * parents have been canceled. * * @return {@code true} if this task or any parent is canceled. */ protected boolean taskCanceled() { boolean cancel = canceled; if (!cancel) { for (K parent = getParent(); !cancel && parent != null; parent = parent.getParent()) cancel = parent.canceled; } return cancel; }
/** * Cancels all tasks which succeed this one in the encounter order. This includes canceling all * the current task's right sibling, as well as the later right siblings of all its parents. */ protected void cancelLaterNodes() { // Go up the tree, cancel right siblings of this node and all parents for (@SuppressWarnings("unchecked") K parent = getParent(), node = (K) this; parent != null; node = parent, parent = parent.getParent()) { // If node is a left child of parent, then has a right sibling if (parent.leftChild == node) { K rightSibling = parent.rightChild; if (!rightSibling.canceled) rightSibling.cancel(); } } }