private boolean getNext() {
        if (next != null) {
            return true;
        }

        if (stack == null) {
            stack = new ArrayList<>();
        }
        while (true) {
            if (it.hasNext()) {
                Hit hit = it.next();
                if (hit instanceof HitGroup) {
                    stack.add(it);
                    if (ordered) {
                        it = ((HitGroup)hit).iterator();
                    } else {
                        it = ((HitGroup)hit).unorderedIterator();
                    }
                } else {
                    next = hit;
                    return true;
                }
            } else if (!stack.isEmpty()) {
                it = stack.remove(stack.size()-1);
            } else {
                return false;
            }
        }
    }
Create a deep hit iterator based on the given hit iterator.

@param it      The hits iterator to traverse.
@param ordered Whether the hits should be ordered.
container-search/src/main/java/com/yahoo/search/result/DeepHitIterator.java