@Override public T next() { if (!hasNext()) { throw new IllegalStateException(); } T next = currentBranch.next(); previousBranch = currentBranch; if (iterateChildren(next)) { currentBranch = new Branch<>(previousBranch, provider.getChildren(next)); } return next; }