aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/main/java/com/yahoo/documentapi/SimpleVisitorDocumentQueue.java
blob: 102f17a64b1d03ee00b8e1391c901d905d079b69 (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
32
33
34
35
36
37
38
39
40
41
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.documentapi;

import com.yahoo.document.Document;
import com.yahoo.document.DocumentId;
import com.yahoo.vdslib.DocumentList;

import java.util.LinkedList;
import java.util.List;

/**
 * A simple document queue that queues up all results and automatically acks
 * them.
 * <p>
 * Retrieving the list is not thread safe, so wait until visitor is done. This
 * is a simple class merely meant for testing.
 *
 * @author <a href="mailto:humbe@yahoo-inc.com">H&aring;kon Humberset</a>
 */
public class SimpleVisitorDocumentQueue extends DumpVisitorDataHandler {
    private final List<Document> documents = new LinkedList<Document>();

    // Inherit doc from VisitorDataHandler
    public void reset() {
        super.reset();
        documents.clear();
    }

    @Override
    public void onDocument(Document doc, long timestamp) {
        documents.add(doc);
    }

    public void onRemove(DocumentId docId) {}

    /** @return a list of all documents retrieved so far */
    public List<Document> getDocuments() {
        return documents;
    }

}