/**
   * 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;
  }