X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fnet%2Fpterodactylus%2Futil%2Fdata%2FNode.java;h=3615b36c077465e33cdea0c557835fec3436d572;hb=2ab79371be9e363e182cb2dec74986d18ef46c47;hp=7737d5027c649766523224194db23bdc868e5b28;hpb=415d6680a02bfbd85ad3f154a7c7f2aee5453549;p=jSite2.git
diff --git a/src/net/pterodactylus/util/data/Node.java b/src/net/pterodactylus/util/data/Node.java
index 7737d50..3615b36 100644
--- a/src/net/pterodactylus/util/data/Node.java
+++ b/src/net/pterodactylus/util/data/Node.java
@@ -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 null
if the node is the {@link Tree#getRootNode()}
* of the tree) and an arbitrary amount of child nodes.
- *
+ *
* @author David âBombeâ Roden <bombe@freenetproject.org>
* @param
* The type of the element to store
*/
-public interface Node extends Iterable> {
+public interface Node> extends Iterable>, Comparable> {
/**
* Returns the parent node of the node.
- *
+ *
* @return The parent node
*/
public Node 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 extends Iterable> {
/**
* 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,9 +55,61 @@ 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
+ * The child node
+ * @return true
if the given node is a direct child of this
+ * node, false
otherwise
+ */
+ public boolean hasChild(Node childNode);
+
+ /**
+ * Returns whether this node contains a child node containing the given
+ * element.
+ *
+ * @param element
+ * The element
+ * @return true
if this node contains a direct child node
+ * containing the given element, false
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 -1
if the child
+ * node is not a child node of this node
+ */
+ public int getIndexOfChild(Node childNode);
+
+ /**
+ * Returns the index of the child node containing the given element.
+ *
+ * @param element
+ * The element
+ * @return The index of the child node, or -1
if the child
+ * node is not a child node of this node
+ */
+ public int getIndexOfChild(E element);
+
+ /**
* 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
*/
@@ -65,7 +118,7 @@ public interface Node extends Iterable> {
/**
* 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
*/
@@ -73,15 +126,44 @@ public interface Node extends Iterable> {
/**
* 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> iterator();
+ /**
+ * 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 null
+ * if no node could be found
+ */
+ public Node 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> comparator);
+
}
\ No newline at end of file