Fixing DoubleBuffer and FloatBuffer to be consistent with the RI's behaviour on equals(). Also adding precise doc on what that behaviour should be.

git-svn-id: https://svn.apache.org/repos/asf/harmony/enhanced/classlib/trunk@882364 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/modules/nio/src/main/java/common/java/nio/DoubleBuffer.java b/modules/nio/src/main/java/common/java/nio/DoubleBuffer.java
index 65ef9c8..8ad9947 100644
--- a/modules/nio/src/main/java/common/java/nio/DoubleBuffer.java
+++ b/modules/nio/src/main/java/common/java/nio/DoubleBuffer.java
@@ -212,11 +212,16 @@
     public abstract DoubleBuffer duplicate();
 
     /**
-     * Checks whether this double buffer is equal to another object.
-     * <p>
-     * If {@code other} is not a double buffer then {@code false} is returned.
-     * Two double buffers are equal if and only if their remaining doubles are
-     * exactly the same. Position, limit, capacity and mark are not considered.
+     * Checks whether this double buffer is equal to another object. If {@code
+     * other} is not a {@code DoubleBuffer} then {@code false} is returned.
+     *
+     * <p>Two double buffers are equal if their remaining doubles are equal.
+     * Position, limit, capacity and mark are not considered.
+     *
+     * <p>This method considers two doubles {@code a} and {@code b} to be equal
+     * if {@code a == b} or if {@code a} and {@code b} are both {@code NaN}.
+     * Unlike {@link Double#equals}, this method considers {@code -0.0} and
+     * {@code +0.0} to be equal.
      *
      * @param other
      *            the object to compare with this double buffer.
@@ -238,7 +243,9 @@
         int otherPosition = otherBuffer.position;
         boolean equalSoFar = true;
         while (equalSoFar && (myPosition < limit)) {
-            equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
+            double a = get(myPosition++);
+            double b = otherBuffer.get(otherPosition++);
+            equalSoFar = a == b || (a != a && b != b);
         }
 
         return equalSoFar;
diff --git a/modules/nio/src/main/java/common/java/nio/FloatBuffer.java b/modules/nio/src/main/java/common/java/nio/FloatBuffer.java
index c971a6a..575e632 100644
--- a/modules/nio/src/main/java/common/java/nio/FloatBuffer.java
+++ b/modules/nio/src/main/java/common/java/nio/FloatBuffer.java
@@ -214,11 +214,16 @@
     public abstract FloatBuffer duplicate();
 
     /**
-     * Checks whether this float buffer is equal to another object.
-     * <p>
-     * If {@code other} is not a float buffer then {@code false} is returned.
-     * Two float buffers are equal if and only if their remaining floats are
-     * exactly the same. Position, limit, capacity and mark are not considered.
+     * Checks whether this float buffer is equal to another object. If {@code
+     * other} is not a {@code FloatBuffer} then {@code false} is returned.
+     *
+     * <p>Two float buffers are equal if their remaining floats are equal.
+     * Position, limit, capacity and mark are not considered.
+     *
+     * <p>This method considers two floats {@code a} and {@code b} to be equal
+     * if {@code a == b} or if {@code a} and {@code b} are both {@code NaN}.
+     * Unlike {@link Float#equals}, this method considers {@code -0.0} and
+     * {@code +0.0} to be equal.
      *
      * @param other
      *            the object to compare with this float buffer.
@@ -240,7 +245,9 @@
         int otherPosition = otherBuffer.position;
         boolean equalSoFar = true;
         while (equalSoFar && (myPosition < limit)) {
-            equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
+            float a = get(myPosition++);
+            float b = otherBuffer.get(otherPosition++);
+            equalSoFar = a == b || (a != a && b != b);
         }
 
         return equalSoFar;