From f9979af9d9963cc5ad92ddb63b6193cba2bb1df1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 26 May 2008 21:42:13 +0200 Subject: [PATCH] add getChild(E) --- src/net/pterodactylus/util/data/Node.java | 11 +++++++++++ src/net/pterodactylus/util/data/NodeImpl.java | 12 ++++++++++++ 2 files changed, 23 insertions(+) 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); } -- 2.7.4