diff --git a/src/main/java/java/nio/Buffer.java b/src/main/java/java/nio/Buffer.java index aa7925e0..9889625c 100644 --- a/src/main/java/java/nio/Buffer.java +++ b/src/main/java/java/nio/Buffer.java @@ -223,4 +223,34 @@ public final Buffer rewind () { mark = UNSET_MARK; return this; } + + /** + * Tells whether or not this buffer is backed by an accessible array. + * + * @return Always returns false. + */ + public boolean hasArray() { + return false; + } + + /** + * Always throws UnsupportedOperationException. + */ + public int arrayOffset() { + throw new UnsupportedOperationException(); + } + /** + * Always throws UnsupportedOperationException. + */ + public Object array() { + throw new UnsupportedOperationException(); + } + + /** + * Tells whether or not this buffer is direct. + * @return Always returns true. + */ + public boolean isDirect() { + return true; + } } diff --git a/src/main/java/java/nio/ByteBuffer.java b/src/main/java/java/nio/ByteBuffer.java index b069eec9..7068fe19 100644 --- a/src/main/java/java/nio/ByteBuffer.java +++ b/src/main/java/java/nio/ByteBuffer.java @@ -19,7 +19,6 @@ import elemental2.core.ArrayBuffer; import elemental2.core.ArrayBufferView; -import elemental2.core.Float64Array; import elemental2.core.Int8Array; import org.gwtproject.nio.HasArrayBufferView; import org.gwtproject.nio.TypedArrayHelper; @@ -541,15 +540,6 @@ public final short getShort (int baseOffset) { return bytes; } - /** Indicates whether this buffer is based on a byte array and provides read/write access. - * - * @return {@code true} if this buffer is based on a byte array and provides read/write access, - * {@code false} otherwise. - */ - public final boolean hasArray () { - return false; - } - /** Calculates this buffer's hash code from the remaining chars. The position, limit, capacity * and mark don't affect the hash code. * @@ -564,14 +554,6 @@ public int hashCode () { return hash; } - /** Indicates whether this buffer is direct. - * - * @return {@code true} if this buffer is direct, {@code false} otherwise. - */ - public final boolean isDirect () { - return true; - } - /** Returns the byte order used by this buffer when converting bytes from/to other primitive * types. *

The default byte order of byte buffer is always {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN} diff --git a/src/main/java/java/nio/CharBuffer.java b/src/main/java/java/nio/CharBuffer.java index e3be4630..4314e7e1 100644 --- a/src/main/java/java/nio/CharBuffer.java +++ b/src/main/java/java/nio/CharBuffer.java @@ -55,29 +55,6 @@ public abstract class CharBuffer extends Buffer super(capacity); } - /** Returns the char array which this buffer is based on, if there is one. - * - * @return the char array which this buffer is based on. - * @exception ReadOnlyBufferException if this buffer is based on an array, but it is read-only. - * @exception UnsupportedOperationException if this buffer is not based on an array. - */ - public final char[] array () { - return protectedArray(); - } - - /** Returns the offset of the char array which this buffer is based on, if there is one. - *

- * The offset is the index of the array corresponds to the zero position of the buffer. - *

- * - * @return the offset of the char array which this buffer is based on. - * @exception ReadOnlyBufferException if this buffer is based on an array but it is read-only. - * @exception UnsupportedOperationException if this buffer is not based on an array. - */ - public final int arrayOffset () { - return protectedArrayOffset(); - } - /** Returns a read-only buffer that shares its content with this buffer. *

The returned buffer is guaranteed to be a new instance, even if this buffer is read-only * itself. The new buffer's position, limit, capacity and mark are the same as this buffer's. @@ -236,15 +213,6 @@ public CharBuffer get (char[] dest, int off, int len) { */ public abstract char get (int index); - /** Indicates whether this buffer is based on a char array and is read/write. - * - * @return {@code true} if this buffer is based on a byte array and provides read/write access, - * {@code false} otherwise. - */ - public final boolean hasArray () { - return protectedHasArray(); - } - /** Calculates this buffer's hash code from the remaining chars. The position, limit, capacity * and mark don't affect the hash code. * @@ -259,16 +227,6 @@ public int hashCode () { return hash; } - /** Indicates whether this buffer is direct. A direct buffer will try its best to take - * advantage of native memory APIs and it may not stay in the Java heap, so it is not affected - * by garbage collection. - *

A char buffer is direct if it is based on a byte buffer and the byte buffer is direct. - *

- * - * @return {@code true} if this buffer is direct, {@code false} otherwise. - */ - public abstract boolean isDirect (); - /** Returns the number of remaining chars. * * @return the number of remaining chars. @@ -285,21 +243,6 @@ public final int length () { */ public abstract ByteOrder order (); - /** Child class implements this method to realize {@code array()}. - * - * @see #array() */ - abstract char[] protectedArray (); - - /** Child class implements this method to realize {@code arrayOffset()}. - * - * @see #arrayOffset() */ - abstract int protectedArrayOffset (); - - /** Child class implements this method to realize {@code hasArray()}. - * - * @see #hasArray() */ - abstract boolean protectedHasArray (); - /** Writes the given char to the current position and increases the position by 1. * * @param c the char to write. diff --git a/src/main/java/java/nio/DoubleBuffer.java b/src/main/java/java/nio/DoubleBuffer.java index 231f3ae8..89c6618e 100644 --- a/src/main/java/java/nio/DoubleBuffer.java +++ b/src/main/java/java/nio/DoubleBuffer.java @@ -50,29 +50,6 @@ public abstract class DoubleBuffer extends Buffer implements Comparable - * The offset is the index of the array corresponding to the zero position of the buffer. - *

- * - * @return the offset of the double array which this buffer is based on. - * @exception ReadOnlyBufferException if this buffer is based on an array, but it is read-only. - * @exception UnsupportedOperationException if this buffer is not based on an array. - */ - public final int arrayOffset () { - return protectedArrayOffset(); - } - /** Returns a read-only buffer that shares its content with this buffer. *

The returned buffer is guaranteed to be a new instance, even if this buffer is read-only * itself. The new buffer's position, limit, capacity and mark are the same as this buffer's. @@ -219,15 +196,6 @@ public DoubleBuffer get (double[] dest, int off, int len) { */ public abstract double get (int index); - /** Indicates whether this buffer is based on a double array and is read/write. - * - * @return {@code true} if this buffer is based on a double array and provides read/write - * access, {@code false} otherwise. - */ - public final boolean hasArray () { - return protectedHasArray(); - } - // /** // * Calculates this buffer's hash code from the remaining chars. The // * position, limit, capacity and mark don't affect the hash code. @@ -245,16 +213,6 @@ public final boolean hasArray () { // return hash; // } - /** Indicates whether this buffer is direct. A direct buffer will try its best to take advantage - * of native memory APIs and it may not stay in the Java heap, so it is not affected by garbage - * collection. - *

A double buffer is direct if it is based on a byte buffer and the byte buffer is direct. - *

- * - * @return {@code true} if this buffer is direct, {@code false} otherwise. - */ - public abstract boolean isDirect (); - /** Returns the byte order used by this buffer when converting doubles from/to bytes. *

If this buffer is not based on a byte buffer, then this always returns the platform's * native byte order.

@@ -263,21 +221,6 @@ public final boolean hasArray () { */ public abstract ByteOrder order (); - /** Child class implements this method to realize {@code array()}. - * - * @see #array() */ - abstract double[] protectedArray (); - - /** Child class implements this method to realize {@code arrayOffset()}. - * - * @see #arrayOffset() */ - abstract int protectedArrayOffset (); - - /** Child class implements this method to realize {@code hasArray()}. - * - * @see #hasArray() */ - abstract boolean protectedHasArray (); - /** Writes the given double to the current position and increases the position by 1. * * @param d the double to write. diff --git a/src/main/java/java/nio/FloatBuffer.java b/src/main/java/java/nio/FloatBuffer.java index 78d8c993..16340935 100644 --- a/src/main/java/java/nio/FloatBuffer.java +++ b/src/main/java/java/nio/FloatBuffer.java @@ -221,15 +221,6 @@ public float get (int index) { return (float)(double)floatArray.getAt(index); } - /** Indicates whether this buffer is based on a float array and is read/write. - * - * @return {@code true} if this buffer is based on a float array and provides read/write - * access, {@code false} otherwise. - */ - public final boolean hasArray () { - return false; - } - // /** // * Calculates this buffer's hash code from the remaining chars. The // * position, limit, capacity and mark don't affect the hash code. @@ -246,18 +237,6 @@ public final boolean hasArray () { // return hash; // } - /** Indicates whether this buffer is direct. A direct buffer will try its best to take - * advantage of native memory APIs and it may not stay in the Java heap, so it is not affected - * by garbage collection. - *

A float buffer is direct if it is based on a byte buffer and the byte buffer is direct. - *

- * - * @return {@code true} if this buffer is direct, {@code false} otherwise. - */ - public boolean isDirect () { - return true; - } - /** Returns the byte order used by this buffer when converting floats from/to bytes. *

If this buffer is not based on a byte buffer, then always return the platform's native * byte order.

diff --git a/src/main/java/java/nio/IntBuffer.java b/src/main/java/java/nio/IntBuffer.java index 2c47a274..20f04ad7 100644 --- a/src/main/java/java/nio/IntBuffer.java +++ b/src/main/java/java/nio/IntBuffer.java @@ -224,15 +224,6 @@ public int get (int index) { return (int)(double)intArray.getAt(index); } - /** Indicates whether this buffer is based on a int array and is read/write. - * - * @return {@code true} if this buffer is based on a int array and provides read/write access, - * {@code false} otherwise. - */ - public final boolean hasArray () { - return false; - } - /** Calculates this buffer's hash code from the remaining chars. The position, limit, capacity * and mark don't affect the hash code. * @@ -247,19 +238,6 @@ public int hashCode () { return hash; } - /** Indicates whether this buffer is direct. A direct buffer will try its best to take - * advantage of native memory APIs and it may not stay in the Java heap, so it is not affected - * by garbage collection. - *

- * An int buffer is direct if it is based on a byte buffer and the byte buffer is direct. - *

- * - * @return {@code true} if this buffer is direct, {@code false} otherwise. - */ - public boolean isDirect () { - return true; - } - /** Returns the byte order used by this buffer when converting ints from/to bytes. *

If this buffer is not based on a byte buffer, then always return the platform's native * byte order.

diff --git a/src/main/java/java/nio/LongBuffer.java b/src/main/java/java/nio/LongBuffer.java index 7aac116f..728e8172 100644 --- a/src/main/java/java/nio/LongBuffer.java +++ b/src/main/java/java/nio/LongBuffer.java @@ -52,29 +52,6 @@ public abstract class LongBuffer extends Buffer implements Comparable - * The offset is the index of the array and corresponds to the zero position of the buffer. - *

- * - * @return the offset of the long array which this buffer is based on. - * @exception ReadOnlyBufferException if this buffer is based on an array, but it is read-only. - * @exception UnsupportedOperationException if this buffer is not based on an array. - */ - public final int arrayOffset () { - return protectedArrayOffset(); - } - /** Returns a read-only buffer that shares its content with this buffer. *

The returned buffer is guaranteed to be a new instance, even if this buffer is read-only * itself. The new buffer's position, limit, capacity and mark are the same as this buffer's. @@ -219,15 +196,6 @@ public LongBuffer get (long[] dest, int off, int len) { */ public abstract long get (int index); - /** Indicates whether this buffer is based on a long array and is read/write. - * - * @return {@code true} if this buffer is based on a long array and provides read/write access, - * {@code false} otherwise. - */ - public final boolean hasArray () { - return protectedHasArray(); - } - /** Calculates this buffer's hash code from the remaining chars. The position, limit, capacity * and mark don't affect the hash code. * @@ -244,17 +212,6 @@ public int hashCode () { return hash; } - /** Indicates whether this buffer is direct. A direct buffer will try its best to take - * advantage of native memory APIs and it may not stay in the Java heap, so it is not affected - * by garbage collection. - *

- * A long buffer is direct if it is based on a byte buffer and the byte buffer is direct. - *

- * - * @return {@code true} if this buffer is direct, {@code false} otherwise. - */ - public abstract boolean isDirect (); - /** Returns the byte order used by this buffer when converting longs from/to bytes. *

If this buffer is not based on a byte buffer, then always return the platform's native * byte order.

@@ -263,21 +220,6 @@ public int hashCode () { */ public abstract ByteOrder order (); - /** Child class implements this method to realize {@code array()}. - * - * @return see {@code array()} */ - abstract long[] protectedArray (); - - /** Child class implements this method to realize {@code arrayOffset()}. - * - * @return see {@code arrayOffset()} */ - abstract int protectedArrayOffset (); - - /** Child class implements this method to realize {@code hasArray()}. - * - * @return see {@code hasArray()} */ - abstract boolean protectedHasArray (); - /** Writes the given long to the current position and increases the position by 1. * * @param l the long to write. diff --git a/src/main/java/java/nio/ShortBuffer.java b/src/main/java/java/nio/ShortBuffer.java index b11415d2..da17e3da 100644 --- a/src/main/java/java/nio/ShortBuffer.java +++ b/src/main/java/java/nio/ShortBuffer.java @@ -222,10 +222,21 @@ public short get (int index) { * @return {@code true} if this buffer is based on a short array and provides read/write * access, {@code false} otherwise. */ + @Override public final boolean hasArray () { return false; } + @Override + public final int arrayOffset() { + throw new UnsupportedOperationException("arrayOffset"); + } + + @Override + public final short[] array() { + throw new UnsupportedOperationException("array"); + } + /** Calculates this buffer's hash code from the remaining chars. The position, limit, capacity * and mark don't affect the hash code. * @@ -240,18 +251,6 @@ public int hashCode () { return hash; } - /** Indicates whether this buffer is direct. A direct buffer will try its best to take - * advantage of native memory APIs and it may not stay in the Java heap, so it is not affected - * by garbage collection. - *

A short buffer is direct if it is based on a byte buffer and the byte buffer is direct. - *

- * - * @return {@code true} if this buffer is direct, {@code false} otherwise. - */ - public boolean isDirect () { - return true; - } - /** Returns the byte order used by this buffer when converting shorts from/to bytes. *

If this buffer is not based on a byte buffer, then always return the platform's native * byte order.