9856fc5db090df1a194ccd116c4f53c3e323f788
[msb/discovery.git] / sdclient / discovery-service / src / main / java / org / onap / msb / sdclient / wrapper / consul / model / ConsulResponse.java
1 /**
2  * Copyright 2016-2017 ZTE, Inc. and others.
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 package org.onap.msb.sdclient.wrapper.consul.model;
17
18 import com.google.common.base.Objects;
19
20 import java.math.BigInteger;
21
22 public class ConsulResponse<T> {
23
24     private final T response;
25     private final long lastContact;
26     private final boolean knownLeader;
27     private final BigInteger index;
28
29     public ConsulResponse(T response, long lastContact, boolean knownLeader, BigInteger index) {
30         this.response = response;
31         this.lastContact = lastContact;
32         this.knownLeader = knownLeader;
33         this.index = index;
34     }
35
36     public T getResponse() {
37         return response;
38     }
39
40     public long getLastContact() {
41         return lastContact;
42     }
43
44     public boolean isKnownLeader() {
45         return knownLeader;
46     }
47
48     public BigInteger getIndex() {
49         return index;
50     }
51
52     @Override
53     public String toString() {
54         return "ConsulResponse{" +
55                 "response=" + response +
56                 ", lastContact=" + lastContact +
57                 ", knownLeader=" + knownLeader +
58                 ", index=" + index +
59                 '}';
60     }
61
62     @Override
63     public boolean equals(Object o) {
64         if (this == o) return true;
65         if (o == null || getClass() != o.getClass()) return false;
66
67         ConsulResponse that = (ConsulResponse) o;
68
69         return Objects.equal(this.response, that.response) &&
70                 Objects.equal(this.lastContact, that.lastContact) &&
71                 Objects.equal(this.knownLeader, that.knownLeader) &&
72                 Objects.equal(this.index, that.index);
73     }
74
75     @Override
76     public int hashCode() {
77         return Objects.hashCode(response, lastContact, knownLeader, index);
78     }
79 }