/** @see #findByPath(Object...) */ public TreeNode<T> findByPath(List<T> path) { Optional<TreeNode<T>> result = TreeQuery.findByPath(treeDef(), this, TreeNode::getContent, path, Function.identity()); if (result.isPresent()) { return result.get(); } else { throw new IllegalArgumentException(this.toString() + " has no element with path " + path); } }
/** * Searches breadth-first for the TreeNode with the given content. * * @throws IllegalArgumentException if no such node exists */ public TreeNode<T> findByContent(T content) { requireNonNull(content); Optional<TreeNode<T>> opt = TreeStream.breadthFirst(treeDef(), this).filter(node -> node.getContent().equals(content)).findFirst(); if (opt.isPresent()) { return opt.get(); } else { throw new IllegalArgumentException(this.toString() + " has no child with content " + content); } } }