Skip to content

Commit e9dfdd3

Browse files
committedAug 9, 2020
Override equals and hashCode for ConsulRequest and UrlParameter implementations.
1 parent cae493e commit e9dfdd3

25 files changed

+438
-4
lines changed
 

‎build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies {
1919

2020
testImplementation "org.mockito:mockito-core:2.23.0"
2121
testImplementation "org.hamcrest:hamcrest-library:1.3"
22+
testImplementation "nl.jqno.equalsverifier:equalsverifier:3.4.1"
2223
testImplementation "org.slf4j:slf4j-simple:1.7.25"
2324
testImplementation "com.pszymczyk.consul:embedded-consul:1.0.2"
2425
}

‎src/main/java/com/ecwid/consul/SingleUrlParameters.java

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.Collections;
44
import java.util.List;
5+
import java.util.Objects;
56

67
/**
78
* @author Vasily Vasilkov (vgv@ecwid.com)
@@ -29,4 +30,22 @@ public List<String> toUrlParameters() {
2930
return Collections.singletonList(key);
3031
}
3132
}
33+
34+
@Override
35+
public boolean equals(Object o) {
36+
if (this == o) {
37+
return true;
38+
}
39+
if (!(o instanceof SingleUrlParameters)) {
40+
return false;
41+
}
42+
SingleUrlParameters that = (SingleUrlParameters) o;
43+
return Objects.equals(key, that.key) &&
44+
Objects.equals(value, that.value);
45+
}
46+
47+
@Override
48+
public int hashCode() {
49+
return Objects.hash(key, value);
50+
}
3251
}

‎src/main/java/com/ecwid/consul/v1/NodeMetaParameters.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import java.util.ArrayList;
66
import java.util.List;
77
import java.util.Map;
8+
import java.util.Objects;
89

9-
public class NodeMetaParameters implements UrlParameters {
10+
public final class NodeMetaParameters implements UrlParameters {
1011

1112
private final Map<String, String> nodeMeta;
1213

@@ -29,4 +30,21 @@ public List<String> toUrlParameters() {
2930

3031
return params;
3132
}
33+
34+
@Override
35+
public boolean equals(Object o) {
36+
if (this == o) {
37+
return true;
38+
}
39+
if (!(o instanceof NodeMetaParameters)) {
40+
return false;
41+
}
42+
NodeMetaParameters that = (NodeMetaParameters) o;
43+
return Objects.equals(nodeMeta, that.nodeMeta);
44+
}
45+
46+
@Override
47+
public int hashCode() {
48+
return Objects.hash(nodeMeta);
49+
}
3250
}

‎src/main/java/com/ecwid/consul/v1/QueryParams.java

+22
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.util.ArrayList;
77
import java.util.List;
8+
import java.util.Objects;
89

910
/**
1011
* @author Vasily Vasilkov (vgv@ecwid.com)
@@ -146,4 +147,25 @@ public List<String> toUrlParameters() {
146147

147148
return params;
148149
}
150+
151+
@Override
152+
public boolean equals(Object o) {
153+
if (this == o) {
154+
return true;
155+
}
156+
if (!(o instanceof QueryParams)) {
157+
return false;
158+
}
159+
QueryParams that = (QueryParams) o;
160+
return waitTime == that.waitTime &&
161+
index == that.index &&
162+
Objects.equals(datacenter, that.datacenter) &&
163+
consistencyMode == that.consistencyMode &&
164+
Objects.equals(near, that.near);
165+
}
166+
167+
@Override
168+
public int hashCode() {
169+
return Objects.hash(datacenter, consistencyMode, waitTime, index, near);
170+
}
149171
}

‎src/main/java/com/ecwid/consul/v1/TagsParameters.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import com.ecwid.consul.UrlParameters;
44

55
import java.util.ArrayList;
6+
import java.util.Arrays;
67
import java.util.List;
78

8-
public class TagsParameters implements UrlParameters {
9+
public final class TagsParameters implements UrlParameters {
910

1011
private final String[] tags;
1112

@@ -27,4 +28,21 @@ public List<String> toUrlParameters() {
2728

2829
return params;
2930
}
31+
32+
@Override
33+
public boolean equals(Object o) {
34+
if (this == o) {
35+
return true;
36+
}
37+
if (!(o instanceof TagsParameters)) {
38+
return false;
39+
}
40+
TagsParameters that = (TagsParameters) o;
41+
return Arrays.equals(tags, that.tags);
42+
}
43+
44+
@Override
45+
public int hashCode() {
46+
return Arrays.hashCode(tags);
47+
}
3048
}

‎src/main/java/com/ecwid/consul/v1/catalog/CatalogNodesRequest.java

+21
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.Collections;
1111
import java.util.List;
1212
import java.util.Map;
13+
import java.util.Objects;
1314

1415
public final class CatalogNodesRequest implements ConsulRequest {
1516

@@ -106,4 +107,24 @@ public List<UrlParameters> asUrlParameters() {
106107

107108
return params;
108109
}
110+
111+
@Override
112+
public boolean equals(Object o) {
113+
if (this == o) {
114+
return true;
115+
}
116+
if (!(o instanceof CatalogNodesRequest)) {
117+
return false;
118+
}
119+
CatalogNodesRequest that = (CatalogNodesRequest) o;
120+
return Objects.equals(datacenter, that.datacenter) &&
121+
Objects.equals(near, that.near) &&
122+
Objects.equals(nodeMeta, that.nodeMeta) &&
123+
Objects.equals(queryParams, that.queryParams);
124+
}
125+
126+
@Override
127+
public int hashCode() {
128+
return Objects.hash(datacenter, near, nodeMeta, queryParams);
129+
}
109130
}

‎src/main/java/com/ecwid/consul/v1/catalog/CatalogServiceRequest.java

+26
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import com.ecwid.consul.v1.QueryParams;
99

1010
import java.util.ArrayList;
11+
import java.util.Arrays;
1112
import java.util.Collections;
1213
import java.util.List;
1314
import java.util.Map;
15+
import java.util.Objects;
1416

1517
public final class CatalogServiceRequest implements ConsulRequest {
1618

@@ -148,4 +150,28 @@ public List<UrlParameters> asUrlParameters() {
148150

149151
return params;
150152
}
153+
154+
@Override
155+
public boolean equals(Object o) {
156+
if (this == o) {
157+
return true;
158+
}
159+
if (!(o instanceof CatalogServiceRequest)) {
160+
return false;
161+
}
162+
CatalogServiceRequest that = (CatalogServiceRequest) o;
163+
return Objects.equals(datacenter, that.datacenter) &&
164+
Arrays.equals(tags, that.tags) &&
165+
Objects.equals(near, that.near) &&
166+
Objects.equals(nodeMeta, that.nodeMeta) &&
167+
Objects.equals(queryParams, that.queryParams) &&
168+
Objects.equals(token, that.token);
169+
}
170+
171+
@Override
172+
public int hashCode() {
173+
int result = Objects.hash(datacenter, near, nodeMeta, queryParams, token);
174+
result = 31 * result + Arrays.hashCode(tags);
175+
return result;
176+
}
151177
}

‎src/main/java/com/ecwid/consul/v1/catalog/CatalogServicesRequest.java

+21
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.Collections;
1111
import java.util.List;
1212
import java.util.Map;
13+
import java.util.Objects;
1314

1415
public final class CatalogServicesRequest implements ConsulRequest {
1516

@@ -106,4 +107,24 @@ public List<UrlParameters> asUrlParameters() {
106107

107108
return params;
108109
}
110+
111+
@Override
112+
public boolean equals(Object o) {
113+
if (this == o) {
114+
return true;
115+
}
116+
if (!(o instanceof CatalogServicesRequest)) {
117+
return false;
118+
}
119+
CatalogServicesRequest that = (CatalogServicesRequest) o;
120+
return Objects.equals(datacenter, that.datacenter) &&
121+
Objects.equals(nodeMeta, that.nodeMeta) &&
122+
Objects.equals(queryParams, that.queryParams) &&
123+
Objects.equals(token, that.token);
124+
}
125+
126+
@Override
127+
public int hashCode() {
128+
return Objects.hash(datacenter, nodeMeta, queryParams, token);
129+
}
109130
}

‎src/main/java/com/ecwid/consul/v1/event/EventListRequest.java

+23
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import java.util.ArrayList;
99
import java.util.List;
10+
import java.util.Objects;
1011

1112
public final class EventListRequest implements ConsulRequest {
1213

@@ -127,4 +128,26 @@ public List<UrlParameters> asUrlParameters() {
127128

128129
return params;
129130
}
131+
132+
@Override
133+
public boolean equals(Object o) {
134+
if (this == o) {
135+
return true;
136+
}
137+
if (!(o instanceof EventListRequest)) {
138+
return false;
139+
}
140+
EventListRequest that = (EventListRequest) o;
141+
return Objects.equals(name, that.name) &&
142+
Objects.equals(node, that.node) &&
143+
Objects.equals(service, that.service) &&
144+
Objects.equals(tag, that.tag) &&
145+
Objects.equals(queryParams, that.queryParams) &&
146+
Objects.equals(token, that.token);
147+
}
148+
149+
@Override
150+
public int hashCode() {
151+
return Objects.hash(name, node, service, tag, queryParams, token);
152+
}
130153
}

‎src/main/java/com/ecwid/consul/v1/event/model/EventParams.java

+21
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.ArrayList;
44
import java.util.List;
5+
import java.util.Objects;
56

67
import com.ecwid.consul.UrlParameters;
78
import com.ecwid.consul.Utils;
@@ -70,4 +71,24 @@ public List<String> toUrlParameters() {
7071

7172
return result;
7273
}
74+
75+
@Override
76+
public boolean equals(Object o) {
77+
if (this == o) {
78+
return true;
79+
}
80+
if (!(o instanceof EventParams)) {
81+
return false;
82+
}
83+
EventParams that = (EventParams) o;
84+
return Objects.equals(name, that.name) &&
85+
Objects.equals(service, that.service) &&
86+
Objects.equals(tag, that.tag) &&
87+
Objects.equals(node, that.node);
88+
}
89+
90+
@Override
91+
public int hashCode() {
92+
return Objects.hash(name, service, tag, node);
93+
}
7394
}

‎src/main/java/com/ecwid/consul/v1/health/HealthChecksForServiceRequest.java

+21
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.Collections;
1111
import java.util.List;
1212
import java.util.Map;
13+
import java.util.Objects;
1314

1415
public final class HealthChecksForServiceRequest implements ConsulRequest {
1516

@@ -101,4 +102,24 @@ public List<UrlParameters> asUrlParameters() {
101102

102103
return params;
103104
}
105+
106+
@Override
107+
public boolean equals(Object o) {
108+
if (this == o) {
109+
return true;
110+
}
111+
if (!(o instanceof HealthChecksForServiceRequest)) {
112+
return false;
113+
}
114+
HealthChecksForServiceRequest that = (HealthChecksForServiceRequest) o;
115+
return Objects.equals(datacenter, that.datacenter) &&
116+
Objects.equals(near, that.near) &&
117+
Objects.equals(nodeMeta, that.nodeMeta) &&
118+
Objects.equals(queryParams, that.queryParams);
119+
}
120+
121+
@Override
122+
public int hashCode() {
123+
return Objects.hash(datacenter, near, nodeMeta, queryParams);
124+
}
104125
}

‎src/main/java/com/ecwid/consul/v1/health/HealthServicesRequest.java

+28-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import com.ecwid.consul.v1.QueryParams;
99

1010
import java.util.ArrayList;
11+
import java.util.Arrays;
1112
import java.util.Collections;
1213
import java.util.List;
1314
import java.util.Map;
15+
import java.util.Objects;
1416

1517
public final class HealthServicesRequest implements ConsulRequest {
1618

@@ -157,4 +159,29 @@ public List<UrlParameters> asUrlParameters() {
157159

158160
return params;
159161
}
160-
}
162+
163+
@Override
164+
public boolean equals(Object o) {
165+
if (this == o) {
166+
return true;
167+
}
168+
if (!(o instanceof HealthServicesRequest)) {
169+
return false;
170+
}
171+
HealthServicesRequest that = (HealthServicesRequest) o;
172+
return passing == that.passing &&
173+
Objects.equals(datacenter, that.datacenter) &&
174+
Objects.equals(near, that.near) &&
175+
Arrays.equals(tags, that.tags) &&
176+
Objects.equals(nodeMeta, that.nodeMeta) &&
177+
Objects.equals(queryParams, that.queryParams) &&
178+
Objects.equals(token, that.token);
179+
}
180+
181+
@Override
182+
public int hashCode() {
183+
int result = Objects.hash(datacenter, near, nodeMeta, passing, queryParams, token);
184+
result = 31 * result + Arrays.hashCode(tags);
185+
return result;
186+
}
187+
}

0 commit comments

Comments
 (0)
Please sign in to comment.