aboutsummaryrefslogtreecommitdiffstats
path: root/vdslib/src/main/java/com/yahoo/vdslib/DynamicEntry.java
blob: 81226c6460473a2e9bb04cb9c8b501f56446eece (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vdslib;

import com.yahoo.document.DocumentOperation;
import com.yahoo.document.DocumentPut;
import com.yahoo.document.DocumentRemove;
import com.yahoo.document.DocumentUpdate;

/**
 * Represents an in-memory entry.
 *
 * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
 */
class DynamicEntry extends Entry {
    private DocumentOperation op;
    private boolean bodyStripped;

    DynamicEntry(DocumentOperation op, boolean bodyStripped) {
        this.op = op;
        this.bodyStripped = bodyStripped;
    }

    DynamicEntry(DocumentUpdate op) {
        this.op = op;
        this.bodyStripped = false;
    }

    DynamicEntry(DocumentRemove op) {
        this.op = op;
        this.bodyStripped = false;
    }

    @Override
    public boolean valid() {
        return true;
    }

    @Override
    public boolean isRemoveEntry() {
        return op instanceof DocumentRemove;
    }

    @Override
    public boolean isBodyStripped() {
        return bodyStripped;
    }

    @Override
    public boolean isUpdateEntry() {
        return op instanceof DocumentUpdate;
    }

    @Override
    public long getTimestamp() {
        if (op instanceof DocumentPut) {
            DocumentPut put = (DocumentPut) op;
            final Long lastModified = put.getDocument().getLastModified();
            if (lastModified != null) {
                return lastModified;
            }
        }
        return 0L;
    }

    @Override
    public DocumentOperation getDocumentOperation() {
        return op;
    }

    @Override
    public DocumentOperation getHeader() {
	return op;
        //TODO: Only return header fields of Document here...?
    }
}