Merge "Verify java.nio.{Char,Double,Float,Int,Long,Short}Buffer."
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/DoubleBufferTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/DoubleBufferTest.java
index 3c634f3..6ae5eb4 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/DoubleBufferTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/nio/DoubleBufferTest.java
@@ -208,6 +208,17 @@
.compareTo(dbuffer3));
}
+ public void testCompareTo_positiveAndNegativeZero() {
+ double negativeZero = Double.parseDouble("-0");
+ double positiveZero = Double.parseDouble("+0");
+ DoubleBuffer negativeZeroBuffer = DoubleBuffer.wrap(new double[] { negativeZero });
+ DoubleBuffer positiveZeroBuffer = DoubleBuffer.wrap(new double[] { positiveZero });
+ assertTrue(Double.compare(negativeZero, positiveZero) < 0); // sanity check
+
+ // Unlike Double.compare(), DoubleBuffer.compareTo() considers -0 == +0
+ assertEquals(0, negativeZeroBuffer.compareTo(positiveZeroBuffer));
+ }
+
public void testDuplicate() {
buf.clear();
buf.mark();
diff --git a/ojluni/src/main/java/java/nio/CharBuffer.java b/ojluni/src/main/java/java/nio/CharBuffer.java
index 2cc4796..fa7423e 100644
--- a/ojluni/src/main/java/java/nio/CharBuffer.java
+++ b/ojluni/src/main/java/java/nio/CharBuffer.java
@@ -533,9 +533,14 @@
* <pre>
* src.get(a, 0, a.length) </pre>
*
- * @return This buffer
- * @throws BufferUnderflowException If there are fewer than <tt>length</tt> chars
- * remaining in this buffer
+ * @param dst
+ * The destination array
+ *
+ * @return This buffer
+ *
+ * @throws BufferUnderflowException
+ * If there are fewer than <tt>length</tt> chars
+ * remaining in this buffer
*/
public CharBuffer get(char[] dst) {
return get(dst, 0, dst.length);
@@ -588,6 +593,8 @@
public CharBuffer put(CharBuffer src) {
if (src == this)
throw new IllegalArgumentException();
+ if (isReadOnly())
+ throw new ReadOnlyBufferException();
int n = src.remaining();
if (n > remaining())
throw new BufferOverflowException();
@@ -740,22 +747,17 @@
public CharBuffer put(String src, int start, int end) {
checkBounds(start, end - start, src.length());
- // Android-changed: Don't bother making changes to the buffer if there's nothing
- // to write. This is questionable behaviour but code expects it.
+ // BEGIN Android-added: Don't check readonly/overflow if there's nothing to write.
+ // This is questionable behaviour but code expects it.
if (start == end) {
return this;
}
+ // END Android-added: Don't check readonly/overflow if there's nothing to write.
- // Android-changed: Throw ReadOnlyBufferException as soon as possible.
- if (isReadOnly()) {
+ if (isReadOnly())
throw new ReadOnlyBufferException();
- }
-
- // Android-changed: Throw as early as we can if there isn't enough space.
- if ((end - start) > remaining()) {
+ if (end - start > remaining())
throw new BufferOverflowException();
- }
-
for (int i = start; i < end; i++)
this.put(src.charAt(i));
return this;
@@ -1220,8 +1222,7 @@
@Override
public IntStream chars() {
- CharBuffer self = this;
- return StreamSupport.intStream(() -> new CharBufferSpliterator(self),
+ return StreamSupport.intStream(() -> new CharBufferSpliterator(this),
Buffer.SPLITERATOR_CHARACTERISTICS, false);
}
}
diff --git a/ojluni/src/main/java/java/nio/DoubleBuffer.java b/ojluni/src/main/java/java/nio/DoubleBuffer.java
index a960a2a..9c3ff87 100644
--- a/ojluni/src/main/java/java/nio/DoubleBuffer.java
+++ b/ojluni/src/main/java/java/nio/DoubleBuffer.java
@@ -465,6 +465,8 @@
public DoubleBuffer put(DoubleBuffer src) {
if (src == this)
throw new IllegalArgumentException();
+ if (isReadOnly())
+ throw new ReadOnlyBufferException();
int n = src.remaining();
if (n > remaining())
throw new BufferOverflowException();
@@ -785,9 +787,7 @@
public int compareTo(DoubleBuffer that) {
int n = this.position() + Math.min(this.remaining(), that.remaining());
for (int i = this.position(), j = that.position(); i < n; i++, j++) {
- // Android-changed: Call through to Double.compare() instead of
- // duplicating code pointlessly.
- int cmp = Double.compare(this.get(i), that.get(j));
+ int cmp = compare(this.get(i), that.get(j));
if (cmp != 0)
return cmp;
}
diff --git a/ojluni/src/main/java/java/nio/FloatBuffer.java b/ojluni/src/main/java/java/nio/FloatBuffer.java
index ab1c6a9..04eac35 100644
--- a/ojluni/src/main/java/java/nio/FloatBuffer.java
+++ b/ojluni/src/main/java/java/nio/FloatBuffer.java
@@ -465,6 +465,8 @@
public FloatBuffer put(FloatBuffer src) {
if (src == this)
throw new IllegalArgumentException();
+ if (isReadOnly())
+ throw new ReadOnlyBufferException();
int n = src.remaining();
if (n > remaining())
throw new BufferOverflowException();
diff --git a/ojluni/src/main/java/java/nio/IntBuffer.java b/ojluni/src/main/java/java/nio/IntBuffer.java
index 3e61ff6..a8cfff8 100644
--- a/ojluni/src/main/java/java/nio/IntBuffer.java
+++ b/ojluni/src/main/java/java/nio/IntBuffer.java
@@ -466,6 +466,8 @@
public IntBuffer put(IntBuffer src) {
if (src == this)
throw new IllegalArgumentException();
+ if (isReadOnly())
+ throw new ReadOnlyBufferException();
int n = src.remaining();
if (n > remaining())
throw new BufferOverflowException();
diff --git a/ojluni/src/main/java/java/nio/LongBuffer.java b/ojluni/src/main/java/java/nio/LongBuffer.java
index aed86e2..c64b8f5 100644
--- a/ojluni/src/main/java/java/nio/LongBuffer.java
+++ b/ojluni/src/main/java/java/nio/LongBuffer.java
@@ -465,6 +465,8 @@
public LongBuffer put(LongBuffer src) {
if (src == this)
throw new IllegalArgumentException();
+ if (isReadOnly())
+ throw new ReadOnlyBufferException();
int n = src.remaining();
if (n > remaining())
throw new BufferOverflowException();
diff --git a/ojluni/src/main/java/java/nio/ShortBuffer.java b/ojluni/src/main/java/java/nio/ShortBuffer.java
index 144348e..13a689f 100644
--- a/ojluni/src/main/java/java/nio/ShortBuffer.java
+++ b/ojluni/src/main/java/java/nio/ShortBuffer.java
@@ -465,6 +465,8 @@
public ShortBuffer put(ShortBuffer src) {
if (src == this)
throw new IllegalArgumentException();
+ if (isReadOnly())
+ throw new ReadOnlyBufferException();
int n = src.remaining();
if (n > remaining())
throw new BufferOverflowException();