/** * Tells whether or not this buffer is equal to another object. * * <p>Two float buffers are equal if, and only if, * * <p> * * <ol> * <li> * <p>They have the same element type, * <li> * <p>They have the same number of remaining elements, and * <li> * <p>The two sequences of remaining elements, considered independently of their starting * positions, are pointwise equal. * <p>This method considers two float elements {@code a} and {@code b} to be equal if {@code * (a == b) || (Float.isNaN(a) && Float.isNaN(b))}. The values {@code -0.0} and {@code +0.0} * are considered to be equal, unlike {@link Float#equals(Object)}. * </ol> * * <p>A float buffer is not equal to any other type of object. * * @param ob The object to which this buffer is to be compared * @return <tt>true</tt> if, and only if, this buffer is equal to the given object */ public boolean equals(Object ob) { if (this == ob) return true; if (!(ob instanceof FloatBuffer)) return false; FloatBuffer that = (FloatBuffer) ob; if (this.remaining() != that.remaining()) return false; int p = this.position(); for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--) if (!equals(this.get(i), that.get(j))) return false; return true; }