aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/main/java/com/yahoo/documentapi/DocumentUpdateResponse.java
blob: 109ec2523fe25275a4a6941b32908213db0bf7f0 (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
85
86
87
88
89
90
91
92
93
94
95
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.documentapi;

import com.yahoo.document.DocumentUpdate;
import com.yahoo.messagebus.Trace;

/**
 * The asynchronous response to a document update operation.
 * This is a <i>value object</i>.
 *
 * @author Einar M R Rosenvinge
 */
public class DocumentUpdateResponse extends Response {

    /** The document update of this response, if any */
    private final DocumentUpdate documentUpdate;

    /** Creates a successful response */
    public DocumentUpdateResponse(long requestId) {
        this(requestId, null);
    }

    /**
     * Creates a successful response containing a document update
     *
     * @param documentUpdate the DocumentUpdate to encapsulate in the Response
     */
    public DocumentUpdateResponse(long requestId, DocumentUpdate documentUpdate) {
        super(requestId);
        this.documentUpdate = documentUpdate;
    }

    /**
     * Creates a response containing a textual message
     *
     * @param textMessage the message to encapsulate in the Response
     * @param outcome     the outcome of this operation
     */
    public DocumentUpdateResponse(long requestId, String textMessage, Outcome outcome) {
        this(requestId, null, textMessage, outcome);
    }

    /**
     * Creates a response containing a textual message and/or a document update
     *
     * @param documentUpdate the DocumentUpdate to encapsulate in the Response
     * @param textMessage    the message to encapsulate in the Response
     * @param outcome        the outcome of this operation
     */
    public DocumentUpdateResponse(long requestId, DocumentUpdate documentUpdate, String textMessage, Outcome outcome) {
        this(requestId, documentUpdate, textMessage, outcome, null);
    }


    /**
     * Creates a response containing a textual message and/or a document update
     *
     * @param documentUpdate the DocumentUpdate to encapsulate in the Response
     * @param textMessage    the message to encapsulate in the Response
     * @param outcome        the outcome of this operation
     */
    public DocumentUpdateResponse(long requestId, DocumentUpdate documentUpdate, String textMessage, Outcome outcome, Trace trace) {
        super(requestId, textMessage, outcome, trace);
        this.documentUpdate = documentUpdate;
    }


    /**
     * Returns the document update of this response or null if there is none
     *
     * @return the DocumentUpdate, or null
     */
    public DocumentUpdate getDocumentUpdate() { return documentUpdate; }

    public int hashCode() {
        return super.hashCode() + (documentUpdate == null ? 0 : documentUpdate.hashCode());
    }

    public boolean equals(Object o) {
        if (!(o instanceof DocumentUpdateResponse)) {
            return false;
        }

        DocumentUpdateResponse docResp = (DocumentUpdateResponse) o;

        return super.equals(docResp) && ((documentUpdate == null && docResp.documentUpdate == null) || (
                documentUpdate != null && docResp.documentUpdate != null &&
                        documentUpdate.equals(docResp.documentUpdate)));
    }

    public String toString() {
        return "Update" + super.toString() + (documentUpdate == null ? "" : " " + documentUpdate);
    }

}