whitespace fixups
[jSite2.git] / src / net / pterodactylus / util / data / Node.java
index 3ba6004..3615b36 100644 (file)
@@ -1,36 +1,37 @@
 
 package net.pterodactylus.util.data;
 
+import java.util.Comparator;
 import java.util.Iterator;
 
 /**
  * A node that can be stored in a {@link Tree}. A node has exactly one parent
  * (which is <code>null</code> if the node is the {@link Tree#getRootNode()}
  * of the tree) and an arbitrary amount of child nodes.
- * 
+ *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  * @param <E>
  *            The type of the element to store
  */
-public interface Node<E> extends Iterable<Node<E>> {
+public interface Node<E extends Comparable<E>> extends Iterable<Node<E>>, Comparable<Node<E>> {
 
        /**
         * Returns the parent node of the node.
-        * 
+        *
         * @return The parent node
         */
        public Node<E> getParent();
 
        /**
         * Returns the element that is stored in the node.
-        * 
+        *
         * @return The node’s element
         */
        public E getElement();
 
        /**
         * Adds an element as a child to this node and returns the created node.
-        * 
+        *
         * @param child
         *            The child node’s element
         * @return The created child node
@@ -39,14 +40,14 @@ public interface Node<E> extends Iterable<Node<E>> {
 
        /**
         * Returns the number of children this node has.
-        * 
+        *
         * @return The number of children
         */
        public int size();
 
        /**
         * Returns the child at the given index.
-        * 
+        *
         * @param index
         *            The index of the child
         * @return The child at the given index
@@ -54,18 +55,40 @@ 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
         *            The child node
         * @return <code>true</code> if the given node is a direct child of this
         *         node, <code>false</code> otherwise
         */
-       public boolean hasChildNode(Node<E> childNode);
+       public boolean hasChild(Node<E> childNode);
+
+       /**
+        * Returns whether this node contains a child node containing the given
+        * element.
+        *
+        * @param element
+        *            The element
+        * @return <code>true</code> if this node contains a direct child node
+        *         containing the given element, <code>false</code> otherwise
+        */
+       public boolean hasChild(E element);
 
        /**
         * Returns the index of the given child node.
-        * 
+        *
         * @param childNode
         *            The child node
         * @return The index of the child node, or <code>-1</code> if the child
@@ -75,7 +98,7 @@ public interface Node<E> extends Iterable<Node<E>> {
 
        /**
         * Returns the index of the child node containing the given element.
-        * 
+        *
         * @param element
         *            The element
         * @return The index of the child node, or <code>-1</code> if the child
@@ -86,7 +109,7 @@ public interface Node<E> extends Iterable<Node<E>> {
        /**
         * Remove the given child node from this node. If the given node is not a
         * child of this node, nothing happens.
-        * 
+        *
         * @param childNode
         *            The child node to remove
         */
@@ -95,7 +118,7 @@ public interface Node<E> extends Iterable<Node<E>> {
        /**
         * Removes the child node that contains the given element. The element in
         * the node is checked using {@link Object#equals(Object)}.
-        * 
+        *
         * @param child
         *            The child element to remove
         */
@@ -103,13 +126,18 @@ public interface Node<E> extends Iterable<Node<E>> {
 
        /**
         * Removes the child at the given index.
-        * 
+        *
         * @param childIndex
         *            The index of the child to remove
         */
        public void removeChild(int childIndex);
 
        /**
+        * Removes all children from this node.
+        */
+       public void removeAllChildren();
+
+       /**
         * {@inheritDoc}
         */
        public Iterator<Node<E>> iterator();
@@ -117,7 +145,7 @@ public interface Node<E> extends Iterable<Node<E>> {
        /**
         * Searches this node’s children recursively for a node that contains the
         * given element.
-        * 
+        *
         * @param element
         *            The element to search
         * @return The node that contains the given element, or <code>null</code>
@@ -125,4 +153,17 @@ public interface Node<E> extends Iterable<Node<E>> {
         */
        public Node<E> findChild(E element);
 
+       /**
+        * Sorts all children according to their natural order.
+        */
+       public void sortChildren();
+
+       /**
+        * Sorts all children with the given comparator.
+        *
+        * @param comparator
+        *            The comparator used to sort the children
+        */
+       public void sortChildren(Comparator<Node<E>> comparator);
+
 }
\ No newline at end of file