sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/02: Bug fix in Vector.hashCode(): to be compliant with List.hashCode() contract, the hash shall be initialized to 1 instead than 0.
Date Wed, 06 Feb 2019 09:17:24 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 38bb29eae631eae50e658189e413aa74788fcc4b
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Feb 6 10:11:55 2019 +0100

    Bug fix in Vector.hashCode(): to be compliant with List.hashCode() contract, the hash
shall be initialized to 1 instead than 0.
---
 core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java | 2 +-
 core/sis-utility/src/main/java/org/apache/sis/math/Vector.java      | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java b/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java
index 499e01b..8b0796d 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/math/ArrayVector.java
@@ -454,7 +454,7 @@ abstract class ArrayVector<E extends Number> extends Vector implements
CheckedCo
 
         /** Applies hash code contract specified {@link Vector#hashCode()}. */
         @Override public int hashCode() {
-            int hash = 0;
+            int hash = 1;
             final int size = size();
             for (int i=0; i<size; i++) {
                 hash = PRIME * hash + Double.hashCode(doubleValue(i));
diff --git a/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java b/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java
index 9a31652..7331c30 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/math/Vector.java
@@ -1459,6 +1459,7 @@ search:     for (;;) {
     /**
      * Returns a hash code for the values in this vector. The hash code is computed as if
this vector was converted
      * to an array of {@link Number}s, then the {@link Arrays#hashCode(Object[])} method
invoked for that array.
+     * This contract is defined for compatibility with {@link java.util.List#hashCode()}
contract.
      *
      * @return a hash code value for the values in this vector.
      *
@@ -1466,7 +1467,7 @@ search:     for (;;) {
      */
     @Override
     public int hashCode() {
-        int hash = 0;
+        int hash = 1;
         final int size = size();
         for (int i=0; i<size; i++) {
             hash = PRIME * hash + get(i).hashCode();


Mime
View raw message