Skip to content

Commit 6edc722

Browse files
author
taylor.smock
committed
Fix #22625: SOE in ImageViewer
This was fallout from reworking #21605 -- originally the code did not use equals. Since it now uses equals, RemoteEntry either needed to be the same (for object equality) or have an implemented equals method. git-svn-id: https://josm.openstreetmap.de/svn/trunk@18622 0c6e7542-c601-0410-84e7-c038aed88b3b
1 parent 12581f9 commit 6edc722

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

src/org/openstreetmap/josm/gui/layer/geoimage/RemoteEntry.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,42 @@ public void setProjectionType(Projections newProjection) {
330330
public void setDisplayName(String text) {
331331
this.title = text;
332332
}
333+
334+
@Override
335+
public int hashCode() {
336+
return Objects.hash(this.uri, this.width, this.height, this.pos,
337+
this.exifOrientation, this.elevation, this.speed, this.exifImgDir,
338+
this.exifCoor, this.exifTime, this.exifGpsTime, this.gpsTime,
339+
this.iptcObjectName, this.iptcCaption, this.iptcHeadline, this.iptcKeywords,
340+
this.projection, this.title);
341+
}
342+
343+
@Override
344+
public boolean equals(Object obj) {
345+
if (super.equals(obj)) {
346+
return true;
347+
}
348+
if (obj != null && obj.getClass() == this.getClass()) {
349+
RemoteEntry other = this.getClass().cast(obj);
350+
return Objects.equals(this.uri, other.uri)
351+
&& this.height == other.height
352+
&& this.width == other.width
353+
&& Objects.equals(this.elevation, other.elevation)
354+
&& Objects.equals(this.exifCoor, other.exifCoor)
355+
&& Objects.equals(this.exifGpsTime, other.exifGpsTime)
356+
&& Objects.equals(this.exifImgDir, other.exifImgDir)
357+
&& Objects.equals(this.exifOrientation, other.exifOrientation)
358+
&& Objects.equals(this.exifTime, other.exifTime)
359+
&& Objects.equals(this.gpsTime, other.gpsTime)
360+
&& Objects.equals(this.iptcCaption, other.iptcCaption)
361+
&& Objects.equals(this.iptcHeadline, other.iptcHeadline)
362+
&& Objects.equals(this.iptcKeywords, other.iptcKeywords)
363+
&& Objects.equals(this.iptcObjectName, other.iptcObjectName)
364+
&& Objects.equals(this.pos, other.pos)
365+
&& Objects.equals(this.projection, other.projection)
366+
&& Objects.equals(this.speed, other.speed)
367+
&& Objects.equals(this.title, other.title);
368+
}
369+
return false;
370+
}
333371
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// License: GPL. For details, see LICENSE file.
2+
package org.openstreetmap.josm.gui.layer.geoimage;
3+
4+
import java.net.URI;
5+
import java.util.Objects;
6+
import java.util.function.Supplier;
7+
8+
import nl.jqno.equalsverifier.EqualsVerifier;
9+
import org.junit.jupiter.api.Test;
10+
11+
/**
12+
* Test class for {@link RemoteEntry}
13+
*/
14+
class RemoteEntryTest {
15+
@Test
16+
void testHashCodeEquals() {
17+
RemoteEntry remoteEntryA = new RemoteEntry(URI.create("https://somewhere.com/image.png?hash=a"),
18+
() -> null, () -> null, () -> null, () -> null);
19+
RemoteEntry remoteEntryB = new RemoteEntry(URI.create("https://somewhere.com/image.png?hash=b"),
20+
() -> null, () -> null, () -> null, () -> null);
21+
EqualsVerifier.simple().forClass(RemoteEntry.class).usingGetClass()
22+
.withIgnoredFields("firstImage", "lastImage", "nextImage", "previousImage")
23+
.withNonnullFields("uri")
24+
.withPrefabValues(RemoteEntry.class, remoteEntryA, remoteEntryB)
25+
.withGenericPrefabValues(Supplier.class,
26+
a -> () -> new RemoteEntry(URI.create("https://somewhere.com/image.png?hash=" + Objects.hash(a)),
27+
() -> null, () -> null, () -> null, () -> null)).verify();
28+
}
29+
}

0 commit comments

Comments
 (0)