add even more methods
[jSite2.git] / src / net / pterodactylus / util / data / NodeImpl.java
index a30f76e..283a663 100644 (file)
@@ -87,6 +87,41 @@ class NodeImpl<E> implements Node<E> {
        /**
         * {@inheritDoc}
         */
+       public boolean hasChildNode(Node<E> childNode) {
+               return children.contains(childNode);
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public int getIndexOfChild(Node<E> childNode) {
+               int childIndex = 0;
+               for (Node<E> node: children) {
+                       if (node.equals(childNode)) {
+                               return childIndex;
+                       }
+                       childIndex++;
+               }
+               return -1;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
+       public int getIndexOfChild(E element) {
+               int childIndex = 0;
+               for (Node<E> node: children) {
+                       if (node.getElement().equals(element)) {
+                               return childIndex;
+                       }
+                       childIndex++;
+               }
+               return -1;
+       }
+
+       /**
+        * {@inheritDoc}
+        */
        public void removeChild(Node<E> childNode) {
                children.remove(childNode);
        }
@@ -113,8 +148,31 @@ class NodeImpl<E> implements Node<E> {
        /**
         * {@inheritDoc}
         */
+       public void removeAllChildren() {
+               children.clear();
+       }
+
+       /**
+        * {@inheritDoc}
+        */
        public Iterator<Node<E>> iterator() {
                return children.iterator();
        }
 
+       /**
+        * {@inheritDoc}
+        */
+       public Node<E> findChild(E element) {
+               for (Node<E> childNode: children) {
+                       Node<E> wantedNode = childNode.findChild(element);
+                       if (wantedNode != null) {
+                               return wantedNode;
+                       }
+               }
+               if (this.element.equals(element)) {
+                       return this;
+               }
+               return null;
+       }
+
 }
\ No newline at end of file