| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ResponseItem |
|
| 0.0;0 |
| 1 | /* | |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one | |
| 3 | * or more contributor license agreements. See the NOTICE file | |
| 4 | * distributed with this work for additional information | |
| 5 | * regarding copyright ownership. The ASF licenses this file | |
| 6 | * to you under the Apache License, Version 2.0 (the | |
| 7 | * "License"); you may not use this file except in compliance | |
| 8 | * with the License. You may obtain a copy of the License at | |
| 9 | * | |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 11 | * | |
| 12 | * Unless required by applicable law or agreed to in writing, | |
| 13 | * software distributed under the License is distributed on an | |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| 15 | * KIND, either express or implied. See the License for the | |
| 16 | * specific language governing permissions and limitations under the License. | |
| 17 | */ | |
| 18 | package org.apache.shindig.social.opensocial.service; | |
| 19 | ||
| 20 | import org.apache.shindig.social.ResponseError; | |
| 21 | ||
| 22 | import com.google.common.base.Objects; | |
| 23 | ||
| 24 | /** | |
| 25 | * Represents the response items that get handed back as json within the | |
| 26 | * DataResponse. | |
| 27 | */ | |
| 28 | public final class ResponseItem { | |
| 29 | /** | |
| 30 | * The ResponseError associated with the item. | |
| 31 | */ | |
| 32 | private final ResponseError error; | |
| 33 | ||
| 34 | /** | |
| 35 | * The error message. | |
| 36 | */ | |
| 37 | private final String errorMessage; | |
| 38 | ||
| 39 | /** | |
| 40 | * The response value. | |
| 41 | */ | |
| 42 | private final Object response; | |
| 43 | ||
| 44 | /** | |
| 45 | * Create a ResponseItem specifying the ResponseError and error Message. | |
| 46 | * @param error a ResponseError | |
| 47 | * @param errorMessage the Error Message | |
| 48 | */ | |
| 49 | 6 | public ResponseItem(ResponseError error, String errorMessage) { |
| 50 | 6 | this.error = error; |
| 51 | 6 | this.errorMessage = errorMessage; |
| 52 | 6 | this.response = null; |
| 53 | 6 | } |
| 54 | ||
| 55 | /** | |
| 56 | * Create a ResponseItem specifying a value. | |
| 57 | */ | |
| 58 | 61 | public ResponseItem(Object response) { |
| 59 | 61 | this.error = null; |
| 60 | 61 | this.errorMessage = null; |
| 61 | 61 | this.response = response; |
| 62 | 61 | } |
| 63 | ||
| 64 | /** | |
| 65 | * Get the response value. | |
| 66 | */ | |
| 67 | public Object getResponse() { | |
| 68 | 58 | return response; |
| 69 | } | |
| 70 | ||
| 71 | /** | |
| 72 | * Get the ResponseError associated with this ResponseItem. | |
| 73 | * @return the ResponseError associated with this ResponseItem | |
| 74 | */ | |
| 75 | public ResponseError getError() { | |
| 76 | 66 | return error; |
| 77 | } | |
| 78 | ||
| 79 | /** | |
| 80 | * Get the Error Message associated with this Response Item. | |
| 81 | * @return the Error Message | |
| 82 | */ | |
| 83 | public String getErrorMessage() { | |
| 84 | 5 | return errorMessage; |
| 85 | } | |
| 86 | ||
| 87 | @Override | |
| 88 | public boolean equals(Object o) { | |
| 89 | 10 | if (this == o) { |
| 90 | 2 | return true; |
| 91 | } | |
| 92 | ||
| 93 | 8 | if (!(o instanceof ResponseItem)) { |
| 94 | 4 | return false; |
| 95 | } | |
| 96 | ||
| 97 | 4 | ResponseItem that = (ResponseItem) o; |
| 98 | 4 | return (error == that.error) |
| 99 | && Objects.equal(errorMessage, that.errorMessage) | |
| 100 | && Objects.equal(response, that.response); | |
| 101 | } | |
| 102 | ||
| 103 | @Override | |
| 104 | public int hashCode() { | |
| 105 | 8 | int result = (error != null ? error.hashCode() : 0); |
| 106 | 8 | result = 31 * result + (errorMessage != null ? errorMessage.hashCode() : 0); |
| 107 | 8 | result = 31 * result + (response != null ? response.hashCode() : 0); |
| 108 | 8 | return result; |
| 109 | } | |
| 110 | } |