aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/main/java/com/yahoo/document/DocumentPut.java
blob: f91ef9a9ee263500bba94f35aacb5aea1441b6ee (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
76
77
78
79
80
81
82
83
84
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.document;

import java.util.Objects;
import com.yahoo.api.annotations.Beta;

/**
 * @author Vegard Sjonfjell
 */
public class DocumentPut extends DocumentOperation {

    private final Document document;
    private boolean createIfNonExistent;

    public DocumentPut(Document document) {
        this.document = document;
    }

    public DocumentPut(DocumentType docType, DocumentId docId) {
        this.document = new Document(docType, docId);
    }

    public DocumentPut(DocumentType docType, String docId) {
        this.document = new Document(docType, docId);
    }

    public Document getDocument() {
        return document;
    }

    public DocumentId getId() {
        return document.getId();
    }

    /**
     * Copy constructor
     *
     * @param other the DocumentPut to copy
     */
    public DocumentPut(DocumentPut other) {
        super(other);
        this.document = new Document(other.getDocument());
        createIfNonExistent = other.createIfNonExistent;
    }

    /**
     * Base this DocumentPut on another, but use newDocument as the Document.
     */
    public DocumentPut(DocumentPut other, Document newDocument) {
        super(other);
        this.document = newDocument;
        createIfNonExistent = other.createIfNonExistent;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        DocumentPut that = (DocumentPut) o;
        return document.equals(that.document) &&
               (createIfNonExistent == that.createIfNonExistent) &&
               Objects.equals(getCondition(), that.getCondition());
    }

    @Override
    public int hashCode() {
        return Objects.hash(document, getCondition());
    }

    @Override
    public String toString() {
        return "put of document " + getId();
    }

    @Beta
    public void setCreateIfNonExistent(boolean value) {
        createIfNonExistent = value;
    }

    @Beta
    public boolean getCreateIfNonExistent() {
        return createIfNonExistent;
    }
}