Initial code import
[msb/apigateway.git] / apiroute / apiroute-service / src / main / java / org / openo / msb / wrapper / consul / model / ConsulResponse.java
1 /**
2 * Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.openo.msb.wrapper.consul.model;
18
19 import com.google.common.base.Objects;
20
21 import java.math.BigInteger;
22
23 public class ConsulResponse<T> {
24
25     private final T response;
26     private final long lastContact;
27     private final boolean knownLeader;
28     private final BigInteger index;
29
30     public ConsulResponse(T response, long lastContact, boolean knownLeader, BigInteger index) {
31         this.response = response;
32         this.lastContact = lastContact;
33         this.knownLeader = knownLeader;
34         this.index = index;
35     }
36
37     public T getResponse() {
38         return response;
39     }
40
41     public long getLastContact() {
42         return lastContact;
43     }
44
45     public boolean isKnownLeader() {
46         return knownLeader;
47     }
48
49     public BigInteger getIndex() {
50         return index;
51     }
52
53     @Override
54     public String toString() {
55         return "ConsulResponse{" +
56                 "response=" + response +
57                 ", lastContact=" + lastContact +
58                 ", knownLeader=" + knownLeader +
59                 ", index=" + index +
60                 '}';
61     }
62
63     @Override
64     public boolean equals(Object o) {
65         if (this == o) return true;
66         if (o == null || getClass() != o.getClass()) return false;
67
68         ConsulResponse that = (ConsulResponse) o;
69
70         return Objects.equal(this.response, that.response) &&
71                 Objects.equal(this.lastContact, that.lastContact) &&
72                 Objects.equal(this.knownLeader, that.knownLeader) &&
73                 Objects.equal(this.index, that.index);
74     }
75
76     @Override
77     public int hashCode() {
78         return Objects.hashCode(response, lastContact, knownLeader, index);
79     }
80 }