add getChild(E)
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 26 May 2008 19:42:13 +0000 (21:42 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 26 May 2008 19:42:13 +0000 (21:42 +0200)
src/net/pterodactylus/util/data/Node.java
src/net/pterodactylus/util/data/NodeImpl.java

index 2f6ec74..560fc34 100644 (file)
@@ -54,6 +54,17 @@ public interface Node<E> extends Iterable<Node<E>> {
        public Node<E> 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
+        *         <code>null</code> if this node does not have a child node
+        *         containing the given element
+        */
+       public Node<E> getChild(E element);
+
+       /**
         * Returns whether the given node is a direct child of this node.
         * 
         * @param childNode
index 5c04aee..785fa1f 100644 (file)
@@ -87,6 +87,18 @@ class NodeImpl<E> implements Node<E> {
        /**
         * {@inheritDoc}
         */
+       public Node<E> getChild(E element) {
+               for (Node<E> childNode: children) {
+                       if (childNode.getElement().equals(element)) {
+                               return childNode;
+                       }
+               }
+               return null;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
        public boolean hasChild(Node<E> childNode) {
                return children.contains(childNode);
        }