Revision created by MOE tool push_codebase.
[gae.git] / java / src / main / com / google / appengine / api / conversion / ConversionResult.java
blobccbf7b4269b507b8d93b6aee9649851ace513102
1 // Copyright 2011 Google Inc. All Rights Reserved.
3 package com.google.appengine.api.conversion;
5 import com.google.common.base.Objects;
6 import com.google.common.base.Preconditions;
8 /**
9 * A single immutable conversion result returned by the conversion service.
12 public final class ConversionResult {
13 private final ConversionErrorCode errorCode; private final Document output;
15 /**
16 * Constructs a conversion result when the conversion failed.
18 * @param errorCode the conversion error code
20 ConversionResult(ConversionErrorCode errorCode) {
21 this.errorCode = Preconditions.checkNotNull(errorCode);
22 this.output = null;
25 /**
26 * Constructs a conversion result when the conversion succeeded.
28 * @param output the output document
30 ConversionResult(Document output) {
31 this.errorCode = null;
32 this.output = Preconditions.checkNotNull(output);
35 /**
36 * Returns whether the conversion succeeded.
38 public boolean success() {
39 return output != null;
42 /**
43 * Returns the conversion error code, or null if the conversion succeeded.
45 public ConversionErrorCode getErrorCode() {
46 return errorCode;
49 /**
50 * Returns the conversion output document, or null if the conversion failed.
52 public Document getOutputDoc() {
53 return output;
56 @Override
57 public boolean equals(Object o) {
58 if (this == o) {
59 return true;
61 if (o == null || getClass() != o.getClass()) {
62 return false;
65 ConversionResult other = (ConversionResult) o;
66 return Objects.equal(errorCode, other.getErrorCode())
67 && Objects.equal(output, other.getOutputDoc());
70 @Override
71 public int hashCode() {
72 return Objects.hashCode(errorCode, output);