protected Option getElement()

in src/main/java/org/apache/sling/query/impl/iterator/SuppIterator.java [58:89]


    protected Option<T> getElement() {
        if (outputElement == null) {
            if (!output.hasNext()) {
                return null;
            }
            outputElement = output.next();
        }

        int outputIndex = outputElement.getArgumentId();
        boolean emptyResponse = outputElement.isEmpty();

        // loop to next index or end of list
        while (outputIndex <= currentIndex && output.hasNext()) {
            if (emptyResponse) {
                emptyResponse = outputElement.isEmpty();
            }
            outputElement = output.next();
            outputIndex = outputElement.getArgumentId();
        }

        if (emptyResponse) {
            if (outputIndex > currentIndex) {
                return Option.empty(currentIndex++);
            }
            return null;
        }

        if (outputIndex <= currentIndex) {
            outputElement = null;
        }
        return input.get(currentIndex++);
    }