Skip to content

Commit

Permalink
46 broken hashcode implementation in icon (#47)
Browse files Browse the repository at this point in the history
* Issue 46
 - fix broken Icon hashCode
 - move to non-deprecated junit methods

* Issue 46
 - release 3.0.9

---------

Co-authored-by: Mark Wickens <[email protected]>
  • Loading branch information
urbancamo and Mark Wickens committed Apr 26, 2024
1 parent 1a9788f commit edb1135
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>uk.m0nom</groupId>
<artifactId>javaapiforkml</artifactId>
<version>3.0.9-SNAPSHOT</version>
<version>3.0.9</version>
<packaging>jar</packaging>
<name>Java Api for Kml</name>
<description>This is JavaApiForKml, Micromata's library for use with applications that want to parse, generate and
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/de/micromata/opengis/kml/v_2_2_0/Icon.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,19 @@ public int hashCode() {
int result = super.hashCode();
long temp;
result = ((prime*result)+((refreshMode == null)? 0 :refreshMode.hashCode()));
temp = Double.doubleToLongBits(refreshInterval);
result = ((prime*result)+((int)(temp^(temp >>>(32)))));
if (refreshInterval != null) {
temp = Double.doubleToLongBits(refreshInterval);
result = ((prime * result) + ((int) (temp ^ (temp >>> (32)))));
}
result = ((prime*result)+((viewRefreshMode == null)? 0 :viewRefreshMode.hashCode()));
temp = Double.doubleToLongBits(viewRefreshTime);
result = ((prime*result)+((int)(temp^(temp >>>(32)))));
temp = Double.doubleToLongBits(viewBoundScale);
result = ((prime*result)+((int)(temp^(temp >>>(32)))));
if (viewRefreshTime != null) {
temp = Double.doubleToLongBits(viewRefreshTime);
result = ((prime * result) + ((int) (temp ^ (temp >>> (32)))));
}
if (viewBoundScale != null) {
temp = Double.doubleToLongBits(viewBoundScale);
result = ((prime * result) + ((int) (temp ^ (temp >>> (32)))));
}
result = ((prime*result)+((viewFormat == null)? 0 :viewFormat.hashCode()));
result = ((prime*result)+((httpQuery == null)? 0 :httpQuery.hashCode()));
result = ((prime*result)+((linkSimpleExtension == null)? 0 :linkSimpleExtension.hashCode()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import jakarta.xml.bind.annotation.XmlRootElement;

import junit.framework.Assert;
import org.junit.Assert;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import junit.framework.Assert;
import org.junit.Assert;

import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import java.lang.reflect.Field;

import junit.framework.Assert;
import org.junit.Assert;

import org.junit.Test;

Expand Down
2 changes: 2 additions & 0 deletions src/test/java/de/micromata/jak/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
public final class Utils {
private static final Logger LOG = LoggerFactory.getLogger(Utils.class.getName());

public static final double DOUBLE_CHECK_DELTA = 0.0001d;

/**
* java.util.List<de.micromata.opengis.kml.v_2_2_0.Coordinate> --> de.micromata.opengis.kml.v_2_2_0.Coordinate
*
Expand Down
28 changes: 15 additions & 13 deletions src/test/java/de/micromata/jak/examples/CloneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.io.File;
import java.util.List;

import junit.framework.Assert;
import org.junit.Assert;

import org.junit.Test;

Expand All @@ -16,6 +16,8 @@
import de.micromata.opengis.kml.v_2_2_0.Placemark;
import de.micromata.opengis.kml.v_2_2_0.Polygon;

import static de.micromata.jak.Utils.DOUBLE_CHECK_DELTA;

public class CloneTest {

@Test
Expand Down Expand Up @@ -54,15 +56,15 @@ public void testClonePlacemark() {
double longitude = c.getLongitude();
double latitude = c.getLatitude();
double altitude = c.getAltitude();
Assert.assertEquals(c.getLongitude(), coordinates.get(j).getLongitude());
Assert.assertEquals(c.getLatitude(), coordinates.get(j).getLatitude());
Assert.assertEquals(c.getAltitude(), coordinates.get(j).getAltitude());
Assert.assertEquals(c.getLongitude(), coordinates.get(j).getLongitude(), DOUBLE_CHECK_DELTA);
Assert.assertEquals(c.getLatitude(), coordinates.get(j).getLatitude(), DOUBLE_CHECK_DELTA);
Assert.assertEquals(c.getAltitude(), coordinates.get(j).getAltitude(), DOUBLE_CHECK_DELTA);
c.setLongitude(0);
c.setLatitude(0);
c.setAltitude(0);
Assert.assertEquals(longitude, coordinates.get(j).getLongitude());
Assert.assertEquals(latitude, coordinates.get(j).getLatitude());
Assert.assertEquals(altitude, coordinates.get(j).getAltitude());
Assert.assertEquals(longitude, coordinates.get(j).getLongitude(), DOUBLE_CHECK_DELTA);
Assert.assertEquals(latitude, coordinates.get(j).getLatitude(), DOUBLE_CHECK_DELTA);
Assert.assertEquals(altitude, coordinates.get(j).getAltitude(), DOUBLE_CHECK_DELTA);

}
if (!p.getInnerBoundaryIs().isEmpty()) {
Expand All @@ -75,15 +77,15 @@ public void testClonePlacemark() {
double longitude = c.getLongitude();
double latitude = c.getLatitude();
double altitude = c.getAltitude();
Assert.assertEquals(c.getLongitude(), coordinatesInner.get(k).getLongitude());
Assert.assertEquals(c.getLatitude(), coordinatesInner.get(k).getLatitude());
Assert.assertEquals(c.getAltitude(), coordinatesInner.get(k).getAltitude());
Assert.assertEquals(c.getLongitude(), coordinatesInner.get(k).getLongitude(), DOUBLE_CHECK_DELTA);
Assert.assertEquals(c.getLatitude(), coordinatesInner.get(k).getLatitude(), DOUBLE_CHECK_DELTA);
Assert.assertEquals(c.getAltitude(), coordinatesInner.get(k).getAltitude(), DOUBLE_CHECK_DELTA);
c.setLongitude(0);
c.setLatitude(0);
c.setAltitude(0);
Assert.assertEquals(longitude, coordinatesInner.get(k).getLongitude());
Assert.assertEquals(latitude, coordinatesInner.get(k).getLatitude());
Assert.assertEquals(altitude, coordinatesInner.get(k).getAltitude());
Assert.assertEquals(longitude, coordinatesInner.get(k).getLongitude(), DOUBLE_CHECK_DELTA);
Assert.assertEquals(latitude, coordinatesInner.get(k).getLatitude(), DOUBLE_CHECK_DELTA);
Assert.assertEquals(altitude, coordinatesInner.get(k).getAltitude(), DOUBLE_CHECK_DELTA);
}
polygon.addToInnerBoundaryIs(innerBoundary);
}
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/de/micromata/opengis/kml/v_2_2_0/IconTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package de.micromata.opengis.kml.v_2_2_0;

import org.junit.Test;

public class IconTest {
@Test
public void hashCodeTest() {
Icon icon1 = new Icon();
Icon icon2 = new Icon();

// Ensure we don't get an NPE
assert(icon1.hashCode() == icon2.hashCode());
}
}

0 comments on commit edb1135

Please sign in to comment.