From: David ‘Bombe’ Roden Date: Mon, 26 May 2008 19:42:13 +0000 (+0200) Subject: add getChild(E) X-Git-Url: https://git.pterodactylus.net/?p=jSite2.git;a=commitdiff_plain;h=f9979af9d9963cc5ad92ddb63b6193cba2bb1df1 add getChild(E) --- diff --git a/src/net/pterodactylus/util/data/Node.java b/src/net/pterodactylus/util/data/Node.java index 2f6ec74..560fc34 100644 --- a/src/net/pterodactylus/util/data/Node.java +++ b/src/net/pterodactylus/util/data/Node.java @@ -54,6 +54,17 @@ public interface Node extends Iterable> { public Node getChild(int index); /** + * Returns the direct child node that contains the given element. + * + * @param element + * The element + * @return The direct child node containing the given element, or + * null if this node does not have a child node + * containing the given element + */ + public Node getChild(E element); + + /** * Returns whether the given node is a direct child of this node. * * @param childNode diff --git a/src/net/pterodactylus/util/data/NodeImpl.java b/src/net/pterodactylus/util/data/NodeImpl.java index 5c04aee..785fa1f 100644 --- a/src/net/pterodactylus/util/data/NodeImpl.java +++ b/src/net/pterodactylus/util/data/NodeImpl.java @@ -87,6 +87,18 @@ class NodeImpl implements Node { /** * {@inheritDoc} */ + public Node getChild(E element) { + for (Node childNode: children) { + if (childNode.getElement().equals(element)) { + return childNode; + } + } + return null; + } + + /** + * {@inheritDoc} + */ public boolean hasChild(Node childNode) { return children.contains(childNode); }