aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/main/java/com/yahoo/document/annotation/SerialIterator.java
blob: fdda53cda0783de03399013f6fe71639c56d8a46 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document.annotation;


import java.util.List;
import java.util.ListIterator;

/**
 * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
 */
public class SerialIterator extends RecursiveNodeIterator {
    SerialIterator(List<ListIterator<SpanNode>> iterators) {
        //the first iterator must be on top of the stack:
        for (int i = iterators.size() - 1; i > -1; i--) {
            stack.push(new PeekableListIterator<SpanNode>(iterators.get(i)));
        }
    }

    @Override
    public boolean hasNext() {
        if (stack.isEmpty()) {
            return false;
        }
        PeekableListIterator<SpanNode> iterator = stack.peek();
        if (!iterator.hasNext()) {
            stack.pop();
            return hasNext();
        }
        return true;
    }
}