Skip to content

Commit 2fbc56c

Browse files
committed
Regenerate equals/hashCode methods for Java 8
1 parent daeb9df commit 2fbc56c

30 files changed

+271
-334
lines changed

src/main/java/ezvcard/io/json/JCardValue.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Arrays;
55
import java.util.Collections;
66
import java.util.List;
7+
import java.util.Objects;
78
import java.util.stream.Collectors;
89

910
import ezvcard.property.Categories;
@@ -299,25 +300,16 @@ public List<String> asMulti() {
299300
}
300301

301302
@Override
302-
public boolean equals(Object o) {
303-
if (this == o) {
304-
return true;
305-
}
306-
if (o == null || getClass() != o.getClass()) {
307-
return false;
308-
}
309-
310-
JCardValue that = (JCardValue) o;
311-
312-
if (values != null ? !values.equals(that.values) : that.values != null) {
313-
return false;
314-
}
315-
316-
return true;
303+
public boolean equals(Object obj) {
304+
if (this == obj) return true;
305+
if (obj == null) return false;
306+
if (getClass() != obj.getClass()) return false;
307+
JCardValue other = (JCardValue) obj;
308+
return Objects.equals(values, other.values);
317309
}
318310

319311
@Override
320312
public int hashCode() {
321-
return values != null ? values.hashCode() : 0;
313+
return Objects.hash(values);
322314
}
323315
}

src/main/java/ezvcard/io/json/JsonValue.java

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

67
/*
78
Copyright (c) 2012-2023, Michael Angstadt
@@ -105,42 +106,16 @@ public boolean isNull() {
105106

106107
@Override
107108
public int hashCode() {
108-
final int prime = 31;
109-
int result = 1;
110-
result = prime * result + ((array == null) ? 0 : array.hashCode());
111-
result = prime * result + (isNull ? 1231 : 1237);
112-
result = prime * result + ((object == null) ? 0 : object.hashCode());
113-
result = prime * result + ((value == null) ? 0 : value.hashCode());
114-
return result;
109+
return Objects.hash(array, isNull, object, value);
115110
}
116111

117112
@Override
118113
public boolean equals(Object obj) {
119-
if (this == obj)
120-
return true;
121-
if (obj == null)
122-
return false;
123-
if (getClass() != obj.getClass())
124-
return false;
114+
if (this == obj) return true;
115+
if (obj == null) return false;
116+
if (getClass() != obj.getClass()) return false;
125117
JsonValue other = (JsonValue) obj;
126-
if (array == null) {
127-
if (other.array != null)
128-
return false;
129-
} else if (!array.equals(other.array))
130-
return false;
131-
if (isNull != other.isNull)
132-
return false;
133-
if (object == null) {
134-
if (other.object != null)
135-
return false;
136-
} else if (!object.equals(other.object))
137-
return false;
138-
if (value == null) {
139-
if (other.value != null)
140-
return false;
141-
} else if (!value.equals(other.value))
142-
return false;
143-
return true;
118+
return Objects.equals(array, other.array) && isNull == other.isNull && Objects.equals(object, other.object) && Objects.equals(value, other.value);
144119
}
145120

146121
@Override

src/main/java/ezvcard/parameter/MediaTypeParameter.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package ezvcard.parameter;
22

3+
import java.util.Objects;
4+
35
/*
46
Copyright (c) 2012-2023, Michael Angstadt
57
All rights reserved.
@@ -70,30 +72,16 @@ public String getExtension() {
7072
public int hashCode() {
7173
final int prime = 31;
7274
int result = super.hashCode();
73-
result = prime * result + ((extension == null) ? 0 : extension.hashCode());
74-
result = prime * result + ((mediaType == null) ? 0 : mediaType.hashCode());
75+
result = prime * result + Objects.hash(extension, mediaType);
7576
return result;
7677
}
7778

7879
@Override
7980
public boolean equals(Object obj) {
80-
if (this == obj)
81-
return true;
82-
if (!super.equals(obj))
83-
return false;
84-
if (getClass() != obj.getClass())
85-
return false;
81+
if (this == obj) return true;
82+
if (!super.equals(obj)) return false;
83+
if (getClass() != obj.getClass()) return false;
8684
MediaTypeParameter other = (MediaTypeParameter) obj;
87-
if (extension == null) {
88-
if (other.extension != null)
89-
return false;
90-
} else if (!extension.equals(other.extension))
91-
return false;
92-
if (mediaType == null) {
93-
if (other.mediaType != null)
94-
return false;
95-
} else if (!mediaType.equals(other.mediaType))
96-
return false;
97-
return true;
85+
return Objects.equals(extension, other.extension) && Objects.equals(mediaType, other.mediaType);
9886
}
9987
}

src/main/java/ezvcard/parameter/Pid.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package ezvcard.parameter;
22

3+
import java.util.Objects;
4+
35
import ezvcard.property.ClientPidMap;
46

57
/*
@@ -115,11 +117,7 @@ public String toString() {
115117

116118
@Override
117119
public int hashCode() {
118-
final int prime = 31;
119-
int result = 1;
120-
result = prime * result + ((clientPidMapReference == null) ? 0 : clientPidMapReference.hashCode());
121-
result = prime * result + localId.hashCode();
122-
return result;
120+
return Objects.hash(clientPidMapReference, localId);
123121
}
124122

125123
@Override
@@ -128,10 +126,6 @@ public boolean equals(Object obj) {
128126
if (obj == null) return false;
129127
if (getClass() != obj.getClass()) return false;
130128
Pid other = (Pid) obj;
131-
if (clientPidMapReference == null) {
132-
if (other.clientPidMapReference != null) return false;
133-
} else if (!clientPidMapReference.equals(other.clientPidMapReference)) return false;
134-
if (!localId.equals(other.localId)) return false;
135-
return true;
129+
return Objects.equals(clientPidMapReference, other.clientPidMapReference) && Objects.equals(localId, other.localId);
136130
}
137131
}

src/main/java/ezvcard/parameter/VCardParameter.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package ezvcard.parameter;
22

3+
import java.util.Objects;
4+
35
import ezvcard.SupportedVersions;
46
import ezvcard.VCardVersion;
57
import ezvcard.util.SupportedVersionsHelper;
@@ -112,10 +114,7 @@ public String toString() {
112114

113115
@Override
114116
public int hashCode() {
115-
final int prime = 31;
116-
int result = 1;
117-
result = prime * result + ((value == null) ? 0 : value.hashCode());
118-
return result;
117+
return Objects.hash(value);
119118
}
120119

121120
@Override
@@ -124,9 +123,6 @@ public boolean equals(Object obj) {
124123
if (obj == null) return false;
125124
if (getClass() != obj.getClass()) return false;
126125
VCardParameter other = (VCardParameter) obj;
127-
if (value == null) {
128-
if (other.value != null) return false;
129-
} else if (!value.equals(other.value)) return false;
130-
return true;
126+
return Objects.equals(value, other.value);
131127
}
132128
}

src/main/java/ezvcard/parameter/VCardParameters.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.util.Map;
1414
import java.util.Objects;
1515
import java.util.Set;
16-
import java.util.stream.Collectors;
1716

1817
import com.github.mangstadt.vinnie.SyntaxStyle;
1918
import com.github.mangstadt.vinnie.validate.AllowedCharacters;
@@ -35,6 +34,7 @@
3534
import ezvcard.util.CharIterator;
3635
import ezvcard.util.GeoUri;
3736
import ezvcard.util.ListMultimap;
37+
import ezvcard.util.StringUtils;
3838

3939
/*
4040
Copyright (c) 2012-2023, Michael Angstadt
@@ -1615,30 +1615,14 @@ public boolean equals(Object obj) {
16151615
String key = entry.getKey();
16161616
List<String> value = entry.getValue();
16171617
List<String> otherValue = other.get(key);
1618-
1619-
if (value.size() != otherValue.size()) {
1620-
return false;
1621-
}
1622-
1623-
List<String> valueLower = toLowerCaseAndSort(value);
1624-
List<String> otherValueLower = toLowerCaseAndSort(otherValue);
1625-
if (!valueLower.equals(otherValueLower)) {
1618+
if (!StringUtils.equalsIgnoreCaseIgnoreOrder(value, otherValue)) {
16261619
return false;
16271620
}
16281621
}
16291622

16301623
return true;
16311624
}
16321625

1633-
private List<String> toLowerCaseAndSort(List<String> values) {
1634-
//@formatter:off
1635-
return values.stream()
1636-
.map(String::toLowerCase)
1637-
.sorted()
1638-
.collect(Collectors.toList());
1639-
//@formatter:on
1640-
}
1641-
16421626
/**
16431627
* <p>
16441628
* A list that converts the raw string values of a TYPE parameter to the

src/main/java/ezvcard/property/Address.java

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.LinkedHashMap;
55
import java.util.List;
66
import java.util.Map;
7+
import java.util.Objects;
78

89
import ezvcard.VCard;
910
import ezvcard.VCardVersion;
@@ -505,29 +506,17 @@ public Address copy() {
505506
public int hashCode() {
506507
final int prime = 31;
507508
int result = super.hashCode();
508-
result = prime * result + countries.hashCode();
509-
result = prime * result + extendedAddresses.hashCode();
510-
result = prime * result + localities.hashCode();
511-
result = prime * result + poBoxes.hashCode();
512-
result = prime * result + postalCodes.hashCode();
513-
result = prime * result + regions.hashCode();
514-
result = prime * result + streetAddresses.hashCode();
509+
result = prime * result + Objects.hash(countries, extendedAddresses, localities, poBoxes, postalCodes, regions, streetAddresses);
515510
return result;
516511
}
517512

518513
@Override
519514
public boolean equals(Object obj) {
520515
if (this == obj) return true;
521516
if (!super.equals(obj)) return false;
517+
if (getClass() != obj.getClass()) return false;
522518
Address other = (Address) obj;
523-
if (!countries.equals(other.countries)) return false;
524-
if (!extendedAddresses.equals(other.extendedAddresses)) return false;
525-
if (!localities.equals(other.localities)) return false;
526-
if (!poBoxes.equals(other.poBoxes)) return false;
527-
if (!postalCodes.equals(other.postalCodes)) return false;
528-
if (!regions.equals(other.regions)) return false;
529-
if (!streetAddresses.equals(other.streetAddresses)) return false;
530-
return true;
519+
return Objects.equals(countries, other.countries) && Objects.equals(extendedAddresses, other.extendedAddresses) && Objects.equals(localities, other.localities) && Objects.equals(poBoxes, other.poBoxes) && Objects.equals(postalCodes, other.postalCodes) && Objects.equals(regions, other.regions) && Objects.equals(streetAddresses, other.streetAddresses);
531520
}
532521

533522
private static String first(List<String> list) {

src/main/java/ezvcard/property/Agent.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.List;
66
import java.util.Locale;
77
import java.util.Map;
8+
import java.util.Objects;
89

910
import ezvcard.SupportedVersions;
1011
import ezvcard.VCard;
@@ -217,22 +218,16 @@ public Agent copy() {
217218
public int hashCode() {
218219
final int prime = 31;
219220
int result = super.hashCode();
220-
result = prime * result + ((url == null) ? 0 : url.hashCode());
221-
result = prime * result + ((vcard == null) ? 0 : vcard.hashCode());
221+
result = prime * result + Objects.hash(url, vcard);
222222
return result;
223223
}
224224

225225
@Override
226226
public boolean equals(Object obj) {
227227
if (this == obj) return true;
228228
if (!super.equals(obj)) return false;
229+
if (getClass() != obj.getClass()) return false;
229230
Agent other = (Agent) obj;
230-
if (url == null) {
231-
if (other.url != null) return false;
232-
} else if (!url.equals(other.url)) return false;
233-
if (vcard == null) {
234-
if (other.vcard != null) return false;
235-
} else if (!vcard.equals(other.vcard)) return false;
236-
return true;
231+
return Objects.equals(url, other.url) && Objects.equals(vcard, other.vcard);
237232
}
238233
}

src/main/java/ezvcard/property/BinaryProperty.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.LinkedHashMap;
1010
import java.util.List;
1111
import java.util.Map;
12+
import java.util.Objects;
1213

1314
import ezvcard.VCard;
1415
import ezvcard.VCardVersion;
@@ -245,24 +246,17 @@ protected Map<String, Object> toStringValues() {
245246
public int hashCode() {
246247
final int prime = 31;
247248
int result = super.hashCode();
248-
result = prime * result + ((contentType == null) ? 0 : contentType.hashCode());
249249
result = prime * result + Arrays.hashCode(data);
250-
result = prime * result + ((url == null) ? 0 : url.hashCode());
250+
result = prime * result + Objects.hash(contentType, url);
251251
return result;
252252
}
253253

254254
@Override
255255
public boolean equals(Object obj) {
256256
if (this == obj) return true;
257257
if (!super.equals(obj)) return false;
258+
if (getClass() != obj.getClass()) return false;
258259
BinaryProperty<?> other = (BinaryProperty<?>) obj;
259-
if (contentType == null) {
260-
if (other.contentType != null) return false;
261-
} else if (!contentType.equals(other.contentType)) return false;
262-
if (!Arrays.equals(data, other.data)) return false;
263-
if (url == null) {
264-
if (other.url != null) return false;
265-
} else if (!url.equals(other.url)) return false;
266-
return true;
260+
return Objects.equals(contentType, other.contentType) && Arrays.equals(data, other.data) && Objects.equals(url, other.url);
267261
}
268262
}

src/main/java/ezvcard/property/ClientPidMap.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.LinkedHashMap;
44
import java.util.List;
55
import java.util.Map;
6+
import java.util.Objects;
67
import java.util.UUID;
78

89
import ezvcard.SupportedVersions;
@@ -184,22 +185,16 @@ public ClientPidMap copy() {
184185
public int hashCode() {
185186
final int prime = 31;
186187
int result = super.hashCode();
187-
result = prime * result + ((pid == null) ? 0 : pid.hashCode());
188-
result = prime * result + ((uri == null) ? 0 : uri.hashCode());
188+
result = prime * result + Objects.hash(pid, uri);
189189
return result;
190190
}
191191

192192
@Override
193193
public boolean equals(Object obj) {
194194
if (this == obj) return true;
195195
if (!super.equals(obj)) return false;
196+
if (getClass() != obj.getClass()) return false;
196197
ClientPidMap other = (ClientPidMap) obj;
197-
if (pid == null) {
198-
if (other.pid != null) return false;
199-
} else if (!pid.equals(other.pid)) return false;
200-
if (uri == null) {
201-
if (other.uri != null) return false;
202-
} else if (!uri.equals(other.uri)) return false;
203-
return true;
198+
return Objects.equals(pid, other.pid) && Objects.equals(uri, other.uri);
204199
}
205200
}

0 commit comments

Comments
 (0)