void checkValidity(SpanNode node, List<SpanNode> childrenToCheck) { if (!node.isValid()) { throw new IllegalStateException("Cannot reuse SpanNode instance " + node + ", is INVALID."); } if (node.getParent() != null) { if (node.getParent() != this) { throw new IllegalStateException(node + " is already a child of " + node.getParent() + ", cannot be added to " + this); } else if (node.getParent() == this && childrenToCheck.contains(node)) { throw new IllegalStateException(node + " is already a child of " + this + ", cannot be added twice to the same parent node."); } } }
/** * WARNING! Only to be used by deserializers! Sets the root of this SpanTree instance. * * @param root the root to set for this SpanTree instance. */ public void setRoot(SpanNode root) { if (!root.isValid()) { throw new IllegalStateException("Cannot use invalid node " + root + " as root node."); } if (root.getParent() != null) { if (root.getParent() != this) { throw new IllegalStateException(root + " is already a child of " + root.getParent() + ", cannot be root of " + this); } } this.root = root; root.setParent(this); }