summaryrefslogtreecommitdiffstats
path: root/persistence/src/main/java/com/yahoo/persistence/spi/DocEntry.java
blob: cf7ef2cc50c77f057bd5be12afaf3c8fa65d8c71 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.persistence.spi;

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

/**
 * Class that represents an entry retrieved by iterating.
 */
public class DocEntry implements Comparable<DocEntry> {


    @Override
    public int compareTo(DocEntry docEntry) {
        return new Long(timestamp).compareTo(docEntry.getTimestamp());
    }

    public enum Type {
        PUT_ENTRY,
        REMOVE_ENTRY
    }

    long timestamp;
    Type type;

    DocumentId docId;
    Document document;

    public DocEntry(long timestamp, Document doc, Type type, DocumentId docId) {
        this.timestamp = timestamp;
        this.type = type;
        this.docId = docId;
        document = doc;
    }


    public DocEntry(long timestamp, Document doc) {
        this(timestamp, doc, Type.PUT_ENTRY, doc.getId());
    }

    public DocEntry(long timestamp, DocumentId docId) {
        this(timestamp, null, Type.REMOVE_ENTRY, docId);
    }

    public DocEntry(long timestamp, Type type) {
        this(timestamp, null, type, null);
    }

    public Type getType() { return type; }

    public long getTimestamp() { return timestamp; }

    public DocumentId getDocumentId() { return docId; }

    public Document getDocument() { return document; }
}