Author: desruisseaux
Date: Mon Oct 17 16:09:24 2016
New Revision: 1765326

URL: http://svn.apache.org/viewvc?rev=1765326&view=rev
Log:
Add missing hashCode() and equals(Object) methods.

Modified:
    
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConventionalUnit.java
    
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SystemUnit.java

Modified: 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConventionalUnit.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConventionalUnit.java?rev=1765326&r1=1765325&r2=1765326&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConventionalUnit.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/ConventionalUnit.java
 [UTF-8] Mon Oct 17 16:09:24 2016
@@ -270,4 +270,30 @@ final class ConventionalUnit<Q extends Q
         ArgumentChecks.ensureNonNull("operation", operation);
         return create(target, toTarget.concatenate(operation));
     }
+
+    /**
+     * Compares this unit with the given object for equality.
+     *
+     * @param  other  the other object to compares with this unit, or {@code 
null}.
+     * @return {@code true} if the given object is equals to this unit.
+     */
+    @Override
+    public boolean equals(final Object other) {
+        if (other == this) {
+            return true;
+        }
+        if (super.equals(other)) {
+            final ConventionalUnit<?> that = (ConventionalUnit<?>) other;
+            return target.equals(that.target) && 
toTarget.equals(that.toTarget);
+        }
+        return false;
+    }
+
+    /**
+     * Returns a hash code value for this unit.
+     */
+    @Override
+    public int hashCode() {
+        return super.hashCode() + 37 * (target.hashCode() + 31 * 
toTarget.hashCode());
+    }
 }

Modified: 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SystemUnit.java
URL: 
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SystemUnit.java?rev=1765326&r1=1765325&r2=1765326&view=diff
==============================================================================
--- 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SystemUnit.java
 [UTF-8] (original)
+++ 
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/measure/SystemUnit.java
 [UTF-8] Mon Oct 17 16:09:24 2016
@@ -17,6 +17,7 @@
 package org.apache.sis.measure;
 
 import java.util.Map;
+import java.util.Objects;
 import java.io.Serializable;
 import java.io.ObjectStreamException;
 import javax.measure.Unit;
@@ -56,7 +57,7 @@ final class SystemUnit<Q extends Quantit
     final Class<Quantity<Q>> quantity;
 
     /**
-     * The dimension of this unit of measurement.
+     * The dimension of this unit of measurement. Can not be null.
      */
     final UnitDimension dimension;
 
@@ -394,4 +395,30 @@ final class SystemUnit<Q extends Quantit
         ArgumentChecks.ensureNonNull("operation", operation);
         return ConventionalUnit.create(this, operation);
     }
+
+    /**
+     * Compares this unit with the given object for equality.
+     *
+     * @param  other  the other object to compares with this unit, or {@code 
null}.
+     * @return {@code true} if the given object is equals to this unit.
+     */
+    @Override
+    public boolean equals(final Object other) {
+        if (other == this) {
+            return true;
+        }
+        if (super.equals(other)) {
+            final SystemUnit<?> that = (SystemUnit<?>) other;
+            return Objects.equals(quantity, that.quantity) && 
dimension.equals(that.dimension);
+        }
+        return false;
+    }
+
+    /**
+     * Returns a hash code value for this unit.
+     */
+    @Override
+    public int hashCode() {
+        return super.hashCode() + 37 * dimension.hashCode();
+    }
 }


Reply via email to