X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Futil%2Fdata%2FNodeImpl.java;h=0f719c8501ea00614740476b1110640ef04b3122;hb=c63257e8cc0ba1a5aca9364b22171abe7279d479;hp=785fa1f25d5a1f65c140c5895e9a1eb520ec7206;hpb=f9979af9d9963cc5ad92ddb63b6193cba2bb1df1;p=jSite2.git diff --git a/src/net/pterodactylus/util/data/NodeImpl.java b/src/net/pterodactylus/util/data/NodeImpl.java index 785fa1f..0f719c8 100644 --- a/src/net/pterodactylus/util/data/NodeImpl.java +++ b/src/net/pterodactylus/util/data/NodeImpl.java @@ -2,17 +2,19 @@ package net.pterodactylus.util.data; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.Iterator; import java.util.List; /** * Implementation of the {@link Node} interface. - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> * @param * The type of the element to store */ -class NodeImpl implements Node { +class NodeImpl> implements Node { /** The parent node of this node. */ private final Node parentNode; @@ -33,7 +35,7 @@ class NodeImpl implements Node { /** * Creates a new node with the given parent and element. - * + * * @param parentNode * The parent of this node * @param element @@ -88,7 +90,7 @@ class NodeImpl implements Node { * {@inheritDoc} */ public Node getChild(E element) { - for (Node childNode: children) { + for (Node childNode : children) { if (childNode.getElement().equals(element)) { return childNode; } @@ -107,7 +109,7 @@ class NodeImpl implements Node { * {@inheritDoc} */ public boolean hasChild(E element) { - for (Node childNode: children) { + for (Node childNode : children) { if (childNode.getElement().equals(element)) { return true; } @@ -120,7 +122,7 @@ class NodeImpl implements Node { */ public int getIndexOfChild(Node childNode) { int childIndex = 0; - for (Node node: children) { + for (Node node : children) { if (node.equals(childNode)) { return childIndex; } @@ -134,7 +136,7 @@ class NodeImpl implements Node { */ public int getIndexOfChild(E element) { int childIndex = 0; - for (Node node: children) { + for (Node node : children) { if (node.getElement().equals(element)) { return childIndex; } @@ -154,7 +156,7 @@ class NodeImpl implements Node { * {@inheritDoc} */ public void removeChild(E child) { - for (Node childNode: children) { + for (Node childNode : children) { if (child.equals(childNode.getElement())) { children.remove(childNode); break; @@ -187,7 +189,7 @@ class NodeImpl implements Node { * {@inheritDoc} */ public Node findChild(E element) { - for (Node childNode: children) { + for (Node childNode : children) { Node wantedNode = childNode.findChild(element); if (wantedNode != null) { return wantedNode; @@ -199,4 +201,29 @@ class NodeImpl implements Node { return null; } + /** + * {@inheritDoc} + */ + public void sortChildren() { + Collections.sort(children); + } + + /** + * {@inheritDoc} + */ + public void sortChildren(Comparator> comparator) { + Collections.sort(children, comparator); + } + + // + // INTERFACE Comparable + // + + /** + * {@inheritDoc} + */ + public int compareTo(Node otherNode) { + return element.compareTo(otherNode.getElement()); + } + } \ No newline at end of file