From aa6f20e742cdc96f8d1370ebe80e8f38aa1032b5 Mon Sep 17 00:00:00 2001 From: Martin Davis Date: Tue, 24 Aug 2021 09:42:50 -0700 Subject: [PATCH] Add missing hashcode functions Signed-off-by: Martin Davis --- .../geomfunction/BaseGeometryFunction.java | 16 +++++++++++++ .../locationtech/jts/geom/PrecisionModel.java | 15 ++++++++++++ .../jts/geom/util/AffineTransformation.java | 23 +++++++++++++++++++ .../org/locationtech/jts/geomgraph/Edge.java | 21 +++++++++++++++++ .../jts/index/strtree/Interval.java | 16 +++++++++++++ 5 files changed, 91 insertions(+) diff --git a/modules/app/src/main/java/org/locationtech/jtstest/geomfunction/BaseGeometryFunction.java b/modules/app/src/main/java/org/locationtech/jtstest/geomfunction/BaseGeometryFunction.java index d4c08076b7..f9055816ce 100644 --- a/modules/app/src/main/java/org/locationtech/jtstest/geomfunction/BaseGeometryFunction.java +++ b/modules/app/src/main/java/org/locationtech/jtstest/geomfunction/BaseGeometryFunction.java @@ -12,6 +12,8 @@ package org.locationtech.jtstest.geomfunction; +import java.util.Arrays; + import org.locationtech.jts.geom.Geometry; import org.locationtech.jtstest.util.*; @@ -177,6 +179,20 @@ public boolean equals(Object obj) return true; } + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + Arrays.hashCode(parameterNames); + result = prime * result + Arrays.hashCode(parameterTypes); + result = prime * result + ((returnType == null) ? 0 : returnType.hashCode()); + return result; + } + public int compareTo(Object o) { GeometryFunction func = (GeometryFunction) o; diff --git a/modules/core/src/main/java/org/locationtech/jts/geom/PrecisionModel.java b/modules/core/src/main/java/org/locationtech/jts/geom/PrecisionModel.java index 03ef2bbe13..534aac4be3 100644 --- a/modules/core/src/main/java/org/locationtech/jts/geom/PrecisionModel.java +++ b/modules/core/src/main/java/org/locationtech/jts/geom/PrecisionModel.java @@ -426,6 +426,21 @@ public boolean equals(Object other) { return modelType == otherPrecisionModel.modelType && scale == otherPrecisionModel.scale; } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((modelType == null) ? 0 : modelType.hashCode()); + long temp; + temp = Double.doubleToLongBits(scale); + result = prime * result + (int) (temp ^ (temp >>> 32)); + return result; + } + /** * Compares this {@link PrecisionModel} object with the specified object for order. * A PrecisionModel is greater than another if it provides greater precision. diff --git a/modules/core/src/main/java/org/locationtech/jts/geom/util/AffineTransformation.java b/modules/core/src/main/java/org/locationtech/jts/geom/util/AffineTransformation.java index ee9b079f00..2f7b0c699a 100644 --- a/modules/core/src/main/java/org/locationtech/jts/geom/util/AffineTransformation.java +++ b/modules/core/src/main/java/org/locationtech/jts/geom/util/AffineTransformation.java @@ -1063,6 +1063,29 @@ public boolean equals(Object obj) && m12 == trans.m12; } + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + long temp; + temp = Double.doubleToLongBits(m00); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(m01); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(m02); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(m10); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(m11); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(m12); + result = prime * result + (int) (temp ^ (temp >>> 32)); + return result; + } + /** * Gets a text representation of this transformation. * The string is of the form: diff --git a/modules/core/src/main/java/org/locationtech/jts/geomgraph/Edge.java b/modules/core/src/main/java/org/locationtech/jts/geomgraph/Edge.java index 1ad1c1a409..8d5fd3a1a8 100644 --- a/modules/core/src/main/java/org/locationtech/jts/geomgraph/Edge.java +++ b/modules/core/src/main/java/org/locationtech/jts/geomgraph/Edge.java @@ -231,6 +231,27 @@ public boolean equals(Object o) return true; } + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + pts.length; + if (pts.length > 0) { + Coordinate p0 = pts[0]; + Coordinate p1 = pts[pts.length - 1]; + if (1 == p0.compareTo(p1)) { + p0 = pts[pts.length - 1]; + p1 = pts[0]; + } + result = prime * result + p0.hashCode(); + result = prime * result + p1.hashCode(); + } + return result; + } + /** * Check if coordinate sequences of the Edges are identical. * diff --git a/modules/core/src/main/java/org/locationtech/jts/index/strtree/Interval.java b/modules/core/src/main/java/org/locationtech/jts/index/strtree/Interval.java index 0d1d683f5b..01dc2d45b2 100644 --- a/modules/core/src/main/java/org/locationtech/jts/index/strtree/Interval.java +++ b/modules/core/src/main/java/org/locationtech/jts/index/strtree/Interval.java @@ -48,9 +48,25 @@ public Interval expandToInclude(Interval other) { public boolean intersects(Interval other) { return !(other.min > max || other.max < min); } + public boolean equals(Object o) { if (! (o instanceof Interval)) { return false; } Interval other = (Interval) o; return min == other.min && max == other.max; } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + long temp; + temp = Double.doubleToLongBits(max); + result = prime * result + (int) (temp ^ (temp >>> 32)); + temp = Double.doubleToLongBits(min); + result = prime * result + (int) (temp ^ (temp >>> 32)); + return result; + } }