add sortChildren
[jSite2.git] / src / net / pterodactylus / util / data / Node.java
index 37588b5..950ed99 100644 (file)
@@ -1,6 +1,7 @@
 
 package net.pterodactylus.util.data;
 
+import java.util.Comparator;
 import java.util.Iterator;
 
 /**
@@ -12,7 +13,7 @@ import java.util.Iterator;
  * @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.
@@ -54,6 +55,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
@@ -61,7 +73,18 @@ public interface Node<E> extends Iterable<Node<E>> {
         * @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.
@@ -130,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