X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Futil%2Fdata%2FNodeImpl.java;h=266cea1f49533e958b57c5101c88abd103cf0160;hb=b794bd6781463774f3a8ff4b86988b5288db2a72;hp=a30f76ea254c562855ba027e93ead0a763b52a6e;hpb=415d6680a02bfbd85ad3f154a7c7f2aee5453549;p=jSite2.git diff --git a/src/net/pterodactylus/util/data/NodeImpl.java b/src/net/pterodactylus/util/data/NodeImpl.java index a30f76e..266cea1 100644 --- a/src/net/pterodactylus/util/data/NodeImpl.java +++ b/src/net/pterodactylus/util/data/NodeImpl.java @@ -2,6 +2,8 @@ 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; @@ -12,7 +14,7 @@ import java.util.List; * @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; @@ -87,6 +89,65 @@ class NodeImpl implements Node { /** * {@inheritDoc} */ + public Node getChild(E element) { + for (Node childNode: children) { + if (childNode.getElement().equals(element)) { + return childNode; + } + } + return null; + } + + /** + * {@inheritDoc} + */ + public boolean hasChild(Node childNode) { + return children.contains(childNode); + } + + /** + * {@inheritDoc} + */ + public boolean hasChild(E element) { + for (Node childNode: children) { + if (childNode.getElement().equals(element)) { + return true; + } + } + return false; + } + + /** + * {@inheritDoc} + */ + public int getIndexOfChild(Node childNode) { + int childIndex = 0; + for (Node node: children) { + if (node.equals(childNode)) { + return childIndex; + } + childIndex++; + } + return -1; + } + + /** + * {@inheritDoc} + */ + public int getIndexOfChild(E element) { + int childIndex = 0; + for (Node node: children) { + if (node.getElement().equals(element)) { + return childIndex; + } + childIndex++; + } + return -1; + } + + /** + * {@inheritDoc} + */ public void removeChild(Node childNode) { children.remove(childNode); } @@ -113,8 +174,56 @@ class NodeImpl implements Node { /** * {@inheritDoc} */ + public void removeAllChildren() { + children.clear(); + } + + /** + * {@inheritDoc} + */ public Iterator> iterator() { return children.iterator(); } + /** + * {@inheritDoc} + */ + public Node findChild(E element) { + for (Node childNode: children) { + Node wantedNode = childNode.findChild(element); + if (wantedNode != null) { + return wantedNode; + } + } + if (this.element.equals(element)) { + return this; + } + 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