@Test public void test() { Node root = new Node(5, null, null); IndexTree myTree = new IndexTree(root); myTree.addNode(new Node(4, null, null)); myTree.addNode(new Node(6, null, null)); Node elem = myTree.find(3); assertEquals(4, elem.getKey()); assertEquals(myTree.noOfElements, 3); assertEquals(elem.cost, 2); }
/** * Returns the next element of this enumeration if this enumeration object has at least one more * element to provide. * * @return the next element of this enumeration. * @throws java.util.NoSuchElementException if no more elements exist. */ @Override public IndexTreePath<E> nextElement() { Enumeration<IndexTreePath<E>> enumeration = queue.peek(); IndexTreePath<E> nextPath = enumeration.nextElement(); Enumeration<IndexTreePath<E>> children; if (nextPath.getEntry().isLeafEntry()) { children = EMPTY_ENUMERATION; } else { N node = index.getNode(nextPath.getEntry()); children = node.children(nextPath); } if (!enumeration.hasMoreElements()) { queue.remove(); } if (children.hasMoreElements()) { queue.offer(children); } return nextPath; }