sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 02/03: Override equals(Object) in GeneralDirectPosition with a more efficient implementation.
Date Tue, 11 Jun 2019 15:13:29 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 78c8c1ae74ef33ac7bd3883b05bbb565e16d28b3
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Jun 11 17:02:39 2019 +0200

    Override equals(Object) in GeneralDirectPosition with a more efficient implementation.
---
 .../org/apache/sis/geometry/AbstractDirectPosition.java   |  4 ++--
 .../org/apache/sis/geometry/GeneralDirectPosition.java    | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
b/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
index 6d62407..2a3b779 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
@@ -381,7 +381,7 @@ parse:  while (i < length) {
     }
 
     /**
-     * Returns a hash value for this coordinate. This method returns a value compliant
+     * Returns a hash value for this coordinate tuple. This method returns a value compliant
      * with the contract documented in the {@link DirectPosition#hashCode()} javadoc.
      * Consequently, it should be possible to mix different {@code DirectPosition}
      * implementations in the same hash map.
@@ -400,7 +400,7 @@ parse:  while (i < length) {
 
     /**
      * Returns {@code true} if the specified object is also a {@code DirectPosition}
-     * with equal coordinate and equal CRS.
+     * with equal coordinates and equal CRS.
      *
      * This method performs the comparison as documented in the {@link DirectPosition#equals(Object)}
      * javadoc. In particular, the given object is not required to be of the same implementation
class.
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
b/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
index b88cb7b..6a43ae4 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
@@ -351,4 +351,19 @@ public class GeneralDirectPosition extends AbstractDirectPosition implements
Ser
         assert code == super.hashCode();
         return code;
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean equals(final Object object) {
+        if (object == this) {
+            return true;
+        }
+        if (object instanceof GeneralDirectPosition) {
+            final GeneralDirectPosition that = (GeneralDirectPosition) object;
+            return Arrays.equals(coordinates, that.coordinates) && Objects.equals(crs,
that.crs);
+        }
+        return super.equals(object);                // Comparison of other implementation
classes.
+    }
 }


Mime
View raw message