You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2007/09/22 23:25:00 UTC
svn commit: r578502 [6/10] - in /harmony/enhanced/classlib/branches/java6:
depends/files/ depends/jars/ depends/manifests/xerces_2.9.0/
depends/manifests/xerces_2.9.1/ depends/manifests/xerces_2.9.1/META-INF/
make/ modules/archive/src/main/native/archi...
Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/FloatBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/FloatBuffer.java?rev=578502&r1=578501&r2=578502&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/FloatBuffer.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/FloatBuffer.java Sat Sep 22 14:24:54 2007
@@ -30,516 +30,543 @@
* to create a float buffer based on a byte buffer.</li>
* </ul>
* </p>
- *
*/
-public abstract class FloatBuffer extends Buffer implements Comparable<FloatBuffer> {
+public abstract class FloatBuffer extends Buffer implements
+ Comparable<FloatBuffer> {
- /**
- * Creates a float buffer based on a new allocated float array.
- *
- * @param capacity The capacity of the new buffer
- * @return The created float buffer
- * @throws IllegalArgumentException If <code>capacity</code> is less than zero
- */
- public static FloatBuffer allocate(int capacity) {
- if (capacity < 0) {
- throw new IllegalArgumentException();
- }
- return BufferFactory.newFloatBuffer(capacity);
- }
-
- /**
- * Creates a new float buffer by wrapping the given float array.
- * <p>
- * Calling this method has the same effect as
- * <code>wrap(array, 0, array.length)</code>.</p>
- *
- * @param array The float array which the new buffer will be based on
- * @return The created float buffer
- */
- public static FloatBuffer wrap(float[] array) {
- return wrap(array, 0, array.length);
- }
-
- /**
- * Creates new a float buffer by wrapping the given float array.
- * <p>
- * The new buffer's position will be <code>start</code>, limit will be
- * <code>start + len</code>, capacity will be the length of the array.
- * </p>
- *
- * @param array
- * The float array which the new buffer will be based on
- * @param start
- * The start index, must be no less than zero and no greater than
- * <code>array.length</code>
- * @param len
- * The length, must be no less than zero and no greater than
- * <code>array.length - start</code>
- * @return The created float buffer
- * @exception IndexOutOfBoundsException
- * If either <code>start</code> or <code>len</code> is
- * invalid
- */
- public static FloatBuffer wrap(float[] array, int start, int len) {
- if (array == null) {
- throw new NullPointerException();
- }
- if (start < 0 || len < 0 || (long)start + (long)len > array.length) {
- throw new IndexOutOfBoundsException();
- }
-
- FloatBuffer buf = BufferFactory.newFloatBuffer(array);
- buf.position = start;
- buf.limit = start + len;
-
- return buf;
- }
-
- /**
- * Constructs a <code>FloatBuffer</code> with given capacity.
- *
- * @param capacity The capacity of the buffer
- */
- FloatBuffer(int capacity) {
- super(capacity);
- }
-
- /**
- * Returns the float array which this buffer is based on, if there's one.
- *
- * @return The float array which this buffer is based on
- * @exception ReadOnlyBufferException
- * If this buffer is based on an array, but it is readonly
- * @exception UnsupportedOperationException
- * If this buffer is not based on an array
- */
- public final float[] array() {
- return protectedArray();
- }
-
- /**
- * Returns the offset of the float array which this buffer is based on, if
- * there's one.
- * <p>
- * The offset is the index of the array corresponds to the zero position of
- * the buffer.
- * </p>
- *
- * @return The offset of the float array which this buffer is based on
- * @exception ReadOnlyBufferException
- * If this buffer is based on an array, but it is readonly
- * @exception UnsupportedOperationException
- * If this buffer is not based on an array
- */
- public final int arrayOffset() {
- return protectedArrayOffset();
- }
-
- /**
- * Returns a readonly buffer that shares content with this buffer.
- * <p>
- * The returned buffer is guaranteed to be a new instance, even this
- * buffer is readonly itself. The new buffer's position, limit, capacity
- * and mark are the same as this buffer.</p>
- * <p>
- * The new buffer shares content with this buffer, which means
- * this buffer's change of content will be visible to the new buffer.
- * The two buffer's position, limit and mark are independent.</p>
- *
- * @return A readonly version of this buffer.
- */
- public abstract FloatBuffer asReadOnlyBuffer();
-
- /**
- * Compacts this float buffer.
- * <p>
- * The remaining <code>float</code>s will be moved to the head of the
- * buffer, staring from position zero. Then the position is set to
- * <code>remaining()</code>; the limit is set to capacity; the mark is
- * cleared.
- * </p>
- *
- * @return This buffer
- * @exception ReadOnlyBufferException
- * If no changes may be made to the contents of this buffer
- */
- public abstract FloatBuffer compact();
-
- /**
- * Compare the remaining <code>float</code>s of this buffer to another
- * float buffer's remaining <code>float</code>s.
- *
- * @param otherBuffer
- * Another float buffer
- * @return a negative value if this is less than <code>other</code>; 0 if
- * this equals to <code>other</code>; a positive value if this is
- * greater than <code>other</code>
- * @exception ClassCastException
- * If <code>other</code> is not a float buffer
- */
- public int compareTo(FloatBuffer otherBuffer) {
- int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining()
- : otherBuffer.remaining();
- int thisPos = position;
- int otherPos = otherBuffer.position;
- float thisByte, otherByte;
- while (compareRemaining > 0) {
- thisByte = get(thisPos);
- otherByte = otherBuffer.get(otherPos);
- if (thisByte != otherByte) {
- return thisByte < otherByte ? -1 : 1;
- }
- thisPos++;
- otherPos++;
- compareRemaining--;
- }
- return remaining() - otherBuffer.remaining();
- }
-
- /**
- * Returns a duplicated buffer that shares content with this buffer.
- * <p>
- * The duplicated buffer's position, limit, capacity and mark are the
- * same as this buffer. The duplicated buffer's readonly property and
- * byte order are same as this buffer too.</p>
- * <p>
- * The new buffer shares content with this buffer, which means
- * either buffer's change of content will be visible to the other.
- * The two buffer's position, limit and mark are independent.</p>
- *
- * @return A duplicated buffer that shares content with this buffer.
- */
- public abstract FloatBuffer duplicate();
-
- /**
- * Tests whether this float buffer equals to another object.
- * <p>
- * If <code>other</code> is not a float buffer, then false is returned.</p>
- * <p>
- * Two float buffers are equals if, and only if, their remaining
- * <code>float</code>s are exactly the same. Position, limit, capacity and
- * mark are not considered.</p>
- *
- * @param other the object to be compared against
- * @return Whether this float buffer equals to another object.
- */
- public boolean equals(Object other) {
- if (!(other instanceof FloatBuffer)) {
- return false;
- }
- FloatBuffer otherBuffer = (FloatBuffer) other;
-
- if (remaining() != otherBuffer.remaining()) {
- return false;
- }
-
- int myPosition = position;
- int otherPosition = otherBuffer.position;
- boolean equalSoFar = true;
- while (equalSoFar && (myPosition < limit)) {
- equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
- }
-
- return equalSoFar;
- }
-
- /**
- * Returns the float at the current position and increase the position by 1.
- *
- * @return The float at the current position.
- * @exception BufferUnderflowException If the position is equal or greater than limit
- */
- public abstract float get();
-
- /**
- * Reads <code>float</code>s from the current position into the specified
- * float array and increase the position by the number of <code>float</code>s
- * read.
- * <p>
- * Calling this method has the same effect as
- * <code>get(dest, 0, dest.length)</code>.
- * </p>
- *
- * @param dest
- * The destination float array
- * @return This buffer
- * @exception BufferUnderflowException
- * if <code>dest.length</code> is greater than
- * <code>remaining()</code>
- */
- public FloatBuffer get(float[] dest) {
- return get(dest, 0, dest.length);
- }
-
- /**
- * Reads <code>float</code>s from the current position into the specified
- * float array, starting from the specified offset, and increase the
- * position by the number of <code>float</code>s read.
- *
- * @param dest
- * The target float array
- * @param off
- * The offset of the float array, must be no less than zero and
- * no greater than <code>dest.length</code>
- * @param len
- * The number of <code>float</code>s to read, must be no less
- * than zero and no greater than <code>dest.length - off</code>
- * @return This buffer
- * @exception IndexOutOfBoundsException
- * If either <code>off</code> or <code>len</code> is
- * invalid
- * @exception BufferUnderflowException
- * If <code>len</code> is greater than
- * <code>remaining()</code>
- */
- public FloatBuffer get(float[] dest, int off, int len) {
+ /**
+ * Creates a float buffer based on a new allocated float array.
+ *
+ * @param capacity
+ * The capacity of the new buffer
+ * @return The created float buffer
+ * @throws IllegalArgumentException
+ * If <code>capacity</code> is less than zero
+ */
+ public static FloatBuffer allocate(int capacity) {
+ if (capacity < 0) {
+ throw new IllegalArgumentException();
+ }
+ return BufferFactory.newFloatBuffer(capacity);
+ }
+
+ /**
+ * Creates a new float buffer by wrapping the given float array.
+ * <p>
+ * Calling this method has the same effect as
+ * <code>wrap(array, 0, array.length)</code>.
+ * </p>
+ *
+ * @param array
+ * The float array which the new buffer will be based on
+ * @return The created float buffer
+ */
+ public static FloatBuffer wrap(float[] array) {
+ return wrap(array, 0, array.length);
+ }
+
+ /**
+ * Creates new a float buffer by wrapping the given float array.
+ * <p>
+ * The new buffer's position will be <code>start</code>, limit will be
+ * <code>start + len</code>, capacity will be the length of the array.
+ * </p>
+ *
+ * @param array
+ * The float array which the new buffer will be based on
+ * @param start
+ * The start index, must be no less than zero and no greater than
+ * <code>array.length</code>
+ * @param len
+ * The length, must be no less than zero and no greater than
+ * <code>array.length - start</code>
+ * @return The created float buffer
+ * @exception IndexOutOfBoundsException
+ * If either <code>start</code> or <code>len</code> is
+ * invalid
+ */
+ public static FloatBuffer wrap(float[] array, int start, int len) {
+ if (array == null) {
+ throw new NullPointerException();
+ }
+ if (start < 0 || len < 0 || (long) start + (long) len > array.length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ FloatBuffer buf = BufferFactory.newFloatBuffer(array);
+ buf.position = start;
+ buf.limit = start + len;
+
+ return buf;
+ }
+
+ /**
+ * Constructs a <code>FloatBuffer</code> with given capacity.
+ *
+ * @param capacity
+ * The capacity of the buffer
+ */
+ FloatBuffer(int capacity) {
+ super(capacity);
+ }
+
+ /**
+ * Returns the float array which this buffer is based on, if there's one.
+ *
+ * @return The float array which this buffer is based on
+ * @exception ReadOnlyBufferException
+ * If this buffer is based on an array, but it is readonly
+ * @exception UnsupportedOperationException
+ * If this buffer is not based on an array
+ */
+ public final float[] array() {
+ return protectedArray();
+ }
+
+ /**
+ * Returns the offset of the float array which this buffer is based on, if
+ * there's one.
+ * <p>
+ * The offset is the index of the array corresponds to the zero position of
+ * the buffer.
+ * </p>
+ *
+ * @return The offset of the float array which this buffer is based on
+ * @exception ReadOnlyBufferException
+ * If this buffer is based on an array, but it is readonly
+ * @exception UnsupportedOperationException
+ * If this buffer is not based on an array
+ */
+ public final int arrayOffset() {
+ return protectedArrayOffset();
+ }
+
+ /**
+ * Returns a readonly buffer that shares content with this buffer.
+ * <p>
+ * The returned buffer is guaranteed to be a new instance, even this buffer
+ * is readonly itself. The new buffer's position, limit, capacity and mark
+ * are the same as this buffer.
+ * </p>
+ * <p>
+ * The new buffer shares content with this buffer, which means this buffer's
+ * change of content will be visible to the new buffer. The two buffer's
+ * position, limit and mark are independent.
+ * </p>
+ *
+ * @return A readonly version of this buffer.
+ */
+ public abstract FloatBuffer asReadOnlyBuffer();
+
+ /**
+ * Compacts this float buffer.
+ * <p>
+ * The remaining <code>float</code>s will be moved to the head of the
+ * buffer, staring from position zero. Then the position is set to
+ * <code>remaining()</code>; the limit is set to capacity; the mark is
+ * cleared.
+ * </p>
+ *
+ * @return This buffer
+ * @exception ReadOnlyBufferException
+ * If no changes may be made to the contents of this buffer
+ */
+ public abstract FloatBuffer compact();
+
+ /**
+ * Compare the remaining <code>float</code>s of this buffer to another
+ * float buffer's remaining <code>float</code>s.
+ *
+ * @param otherBuffer
+ * Another float buffer
+ * @return a negative value if this is less than <code>other</code>; 0 if
+ * this equals to <code>other</code>; a positive value if this is
+ * greater than <code>other</code>
+ * @exception ClassCastException
+ * If <code>other</code> is not a float buffer
+ */
+ public int compareTo(FloatBuffer otherBuffer) {
+ int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining()
+ : otherBuffer.remaining();
+ int thisPos = position;
+ int otherPos = otherBuffer.position;
+ float thisFloat, otherFloat;
+ while (compareRemaining > 0) {
+ thisFloat = get(thisPos);
+ otherFloat = otherBuffer.get(otherPos);
+ // checks for float and NaN inequality
+ if ((thisFloat != otherFloat)
+ && ((thisFloat == thisFloat) || (otherFloat == otherFloat))) {
+ return thisFloat < otherFloat ? -1 : 1;
+ }
+ thisPos++;
+ otherPos++;
+ compareRemaining--;
+ }
+ return remaining() - otherBuffer.remaining();
+ }
+
+ /**
+ * Returns a duplicated buffer that shares content with this buffer.
+ * <p>
+ * The duplicated buffer's position, limit, capacity and mark are the same
+ * as this buffer. The duplicated buffer's readonly property and byte order
+ * are same as this buffer too.
+ * </p>
+ * <p>
+ * The new buffer shares content with this buffer, which means either
+ * buffer's change of content will be visible to the other. The two buffer's
+ * position, limit and mark are independent.
+ * </p>
+ *
+ * @return A duplicated buffer that shares content with this buffer.
+ */
+ public abstract FloatBuffer duplicate();
+
+ /**
+ * Tests whether this float buffer equals to another object.
+ * <p>
+ * If <code>other</code> is not a float buffer, then false is returned.
+ * </p>
+ * <p>
+ * Two float buffers are equals if, and only if, their remaining
+ * <code>float</code>s are exactly the same. Position, limit, capacity
+ * and mark are not considered.
+ * </p>
+ *
+ * @param other
+ * the object to be compared against
+ * @return Whether this float buffer equals to another object.
+ */
+ @Override
+ public boolean equals(Object other) {
+ if (!(other instanceof FloatBuffer)) {
+ return false;
+ }
+ FloatBuffer otherBuffer = (FloatBuffer) other;
+
+ if (remaining() != otherBuffer.remaining()) {
+ return false;
+ }
+
+ int myPosition = position;
+ int otherPosition = otherBuffer.position;
+ boolean equalSoFar = true;
+ while (equalSoFar && (myPosition < limit)) {
+ equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
+ }
+
+ return equalSoFar;
+ }
+
+ /**
+ * Returns the float at the current position and increase the position by 1.
+ *
+ * @return The float at the current position.
+ * @exception BufferUnderflowException
+ * If the position is equal or greater than limit
+ */
+ public abstract float get();
+
+ /**
+ * Reads <code>float</code>s from the current position into the specified
+ * float array and increase the position by the number of <code>float</code>s
+ * read.
+ * <p>
+ * Calling this method has the same effect as
+ * <code>get(dest, 0, dest.length)</code>.
+ * </p>
+ *
+ * @param dest
+ * The destination float array
+ * @return This buffer
+ * @exception BufferUnderflowException
+ * if <code>dest.length</code> is greater than
+ * <code>remaining()</code>
+ */
+ public FloatBuffer get(float[] dest) {
+ return get(dest, 0, dest.length);
+ }
+
+ /**
+ * Reads <code>float</code>s from the current position into the specified
+ * float array, starting from the specified offset, and increase the
+ * position by the number of <code>float</code>s read.
+ *
+ * @param dest
+ * The target float array
+ * @param off
+ * The offset of the float array, must be no less than zero and
+ * no greater than <code>dest.length</code>
+ * @param len
+ * The number of <code>float</code>s to read, must be no less
+ * than zero and no greater than <code>dest.length - off</code>
+ * @return This buffer
+ * @exception IndexOutOfBoundsException
+ * If either <code>off</code> or <code>len</code> is
+ * invalid
+ * @exception BufferUnderflowException
+ * If <code>len</code> is greater than
+ * <code>remaining()</code>
+ */
+ public FloatBuffer get(float[] dest, int off, int len) {
int length = dest.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ if (off < 0 || len < 0 || (long) off + (long) len > length) {
throw new IndexOutOfBoundsException();
}
-
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- for (int i = off; i < off + len; i++) {
- dest[i] = get();
- }
- return this;
- }
-
- /**
- * Returns a float at the specified index, and the position is not changed.
- *
- * @param index The index, must be no less than zero and less than limit
- * @return A float at the specified index.
- * @exception IndexOutOfBoundsException If index is invalid
- */
- public abstract float get(int index);
-
- /**
- * Returns whether this buffer is based on a float array and is read/write.
- * <p>
- * If this buffer is readonly, then false is returned.</p>
- *
- * @return Whether this buffer is based on a float array and is read/write.
- */
- public final boolean hasArray() {
- return protectedHasArray();
- }
-
- /**
- * Hash code is calculated from the remaining <code>float</code>s.
- * <p>
- * Position, limit, capacity and mark don't affect the hash code.</p>
- *
- * @return The hash code calculated from the remaining <code>float</code>s.
- */
- public int hashCode() {
- int myPosition = position;
- int hash = 0;
- while (myPosition < limit) {
- hash = hash + Float.floatToIntBits(get(myPosition++));
- }
- return hash;
- }
-
- /**
- * Returns true if this buffer is direct.
- * <p>
- * A direct buffer will try its best to take advantage of native memory
- * APIs and it may not stay in java heap, thus not affected by GC.</p>
- * <p>
- * A float buffer is direct, if it is based on a byte buffer and the byte
- * buffer is direct.</p>
- *
- * @return True if this buffer is direct.
- */
- public abstract boolean isDirect();
-
- /**
- * Returns the byte order used by this buffer when converting
- * <code>float</code>s from/to <code>byte</code>s.
- * <p>
- * If this buffer is not based on a byte buffer, then always return the
- * platform's native byte order.</p>
- *
- * @return The byte order used by this buffer when converting
- * <code>float</code>s from/to <code>byte</code>s.
- */
- public abstract ByteOrder order();
-
- /**
- * Child class implements this method to realize <code>array()</code>.
- *
- * @return see <code>array()</code>
- */
- abstract float[] protectedArray();
-
- /**
- * Child class implements this method to realize <code>arrayOffset()</code>.
- *
- * @return see <code>arrayOffset()</code>
- */
- abstract int protectedArrayOffset();
-
- /**
- * Child class implements this method to realize <code>hasArray()</code>.
- *
- * @return see <code>hasArray()</code>
- */
- abstract boolean protectedHasArray();
-
- /**
- * Writes the given float to the current position and increase the position
- * by 1.
- *
- * @param f
- * The float to write
- * @return This buffer
- * @exception BufferOverflowException
- * If position is equal or greater than limit
- * @exception ReadOnlyBufferException
- * If no changes may be made to the contents of this buffer
- */
- public abstract FloatBuffer put(float f);
-
- /**
- * Writes <code>float</code>s in the given float array to the current
- * position and increase the position by the number of <code>float</code>s
- * written.
- * <p>
- * Calling this method has the same effect as
- * <code>put(src, 0, src.length)</code>.
- * </p>
- *
- * @param src
- * The source float array
- * @return This buffer
- * @exception BufferOverflowException
- * If <code>remaining()</code> is less than
- * <code>src.length</code>
- * @exception ReadOnlyBufferException
- * If no changes may be made to the contents of this buffer
- */
- public final FloatBuffer put(float[] src) {
- return put(src, 0, src.length);
- }
-
- /**
- * Writes <code>float</code>s in the given float array, starting from the
- * specified offset, to the current position and increase the position by
- * the number of <code>float</code>s written.
- *
- * @param src
- * The source float array
- * @param off
- * The offset of float array, must be no less than zero and no
- * greater than <code>src.length</code>
- * @param len
- * The number of <code>float</code>s to write, must be no less
- * than zero and no greater than <code>src.length - off</code>
- * @return This buffer
- * @exception BufferOverflowException
- * If <code>remaining()</code> is less than
- * <code>len</code>
- * @exception IndexOutOfBoundsException
- * If either <code>off</code> or <code>len</code> is
- * invalid
- * @exception ReadOnlyBufferException
- * If no changes may be made to the contents of this buffer
- */
- public FloatBuffer put(float[] src, int off, int len) {
+
+ if (len > remaining()) {
+ throw new BufferUnderflowException();
+ }
+ for (int i = off; i < off + len; i++) {
+ dest[i] = get();
+ }
+ return this;
+ }
+
+ /**
+ * Returns a float at the specified index, and the position is not changed.
+ *
+ * @param index
+ * The index, must be no less than zero and less than limit
+ * @return A float at the specified index.
+ * @exception IndexOutOfBoundsException
+ * If index is invalid
+ */
+ public abstract float get(int index);
+
+ /**
+ * Returns whether this buffer is based on a float array and is read/write.
+ * <p>
+ * If this buffer is readonly, then false is returned.
+ * </p>
+ *
+ * @return Whether this buffer is based on a float array and is read/write.
+ */
+ public final boolean hasArray() {
+ return protectedHasArray();
+ }
+
+ /**
+ * Hash code is calculated from the remaining <code>float</code>s.
+ * <p>
+ * Position, limit, capacity and mark don't affect the hash code.
+ * </p>
+ *
+ * @return The hash code calculated from the remaining <code>float</code>s.
+ */
+ @Override
+ public int hashCode() {
+ int myPosition = position;
+ int hash = 0;
+ while (myPosition < limit) {
+ hash = hash + Float.floatToIntBits(get(myPosition++));
+ }
+ return hash;
+ }
+
+ /**
+ * Returns true if this buffer is direct.
+ * <p>
+ * A direct buffer will try its best to take advantage of native memory APIs
+ * and it may not stay in java heap, thus not affected by GC.
+ * </p>
+ * <p>
+ * A float buffer is direct, if it is based on a byte buffer and the byte
+ * buffer is direct.
+ * </p>
+ *
+ * @return True if this buffer is direct.
+ */
+ public abstract boolean isDirect();
+
+ /**
+ * Returns the byte order used by this buffer when converting
+ * <code>float</code>s from/to <code>byte</code>s.
+ * <p>
+ * If this buffer is not based on a byte buffer, then always return the
+ * platform's native byte order.
+ * </p>
+ *
+ * @return The byte order used by this buffer when converting
+ * <code>float</code>s from/to <code>byte</code>s.
+ */
+ public abstract ByteOrder order();
+
+ /**
+ * Child class implements this method to realize <code>array()</code>.
+ *
+ * @return see <code>array()</code>
+ */
+ abstract float[] protectedArray();
+
+ /**
+ * Child class implements this method to realize <code>arrayOffset()</code>.
+ *
+ * @return see <code>arrayOffset()</code>
+ */
+ abstract int protectedArrayOffset();
+
+ /**
+ * Child class implements this method to realize <code>hasArray()</code>.
+ *
+ * @return see <code>hasArray()</code>
+ */
+ abstract boolean protectedHasArray();
+
+ /**
+ * Writes the given float to the current position and increase the position
+ * by 1.
+ *
+ * @param f
+ * The float to write
+ * @return This buffer
+ * @exception BufferOverflowException
+ * If position is equal or greater than limit
+ * @exception ReadOnlyBufferException
+ * If no changes may be made to the contents of this buffer
+ */
+ public abstract FloatBuffer put(float f);
+
+ /**
+ * Writes <code>float</code>s in the given float array to the current
+ * position and increase the position by the number of <code>float</code>s
+ * written.
+ * <p>
+ * Calling this method has the same effect as
+ * <code>put(src, 0, src.length)</code>.
+ * </p>
+ *
+ * @param src
+ * The source float array
+ * @return This buffer
+ * @exception BufferOverflowException
+ * If <code>remaining()</code> is less than
+ * <code>src.length</code>
+ * @exception ReadOnlyBufferException
+ * If no changes may be made to the contents of this buffer
+ */
+ public final FloatBuffer put(float[] src) {
+ return put(src, 0, src.length);
+ }
+
+ /**
+ * Writes <code>float</code>s in the given float array, starting from the
+ * specified offset, to the current position and increase the position by
+ * the number of <code>float</code>s written.
+ *
+ * @param src
+ * The source float array
+ * @param off
+ * The offset of float array, must be no less than zero and no
+ * greater than <code>src.length</code>
+ * @param len
+ * The number of <code>float</code>s to write, must be no less
+ * than zero and no greater than <code>src.length - off</code>
+ * @return This buffer
+ * @exception BufferOverflowException
+ * If <code>remaining()</code> is less than
+ * <code>len</code>
+ * @exception IndexOutOfBoundsException
+ * If either <code>off</code> or <code>len</code> is
+ * invalid
+ * @exception ReadOnlyBufferException
+ * If no changes may be made to the contents of this buffer
+ */
+ public FloatBuffer put(float[] src, int off, int len) {
int length = src.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ if (off < 0 || len < 0 || (long) off + (long) len > length) {
throw new IndexOutOfBoundsException();
}
-
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
- for (int i = off; i < off + len; i++) {
- put(src[i]);
- }
- return this;
- }
-
- /**
- * Writes all the remaining <code>float</code>s of the <code>src</code>
- * float buffer to this buffer's current position, and increase both
- * buffers' position by the number of <code>float</code>s copied.
- *
- * @param src
- * The source float buffer
- * @return This buffer
- * @exception BufferOverflowException
- * If <code>src.remaining()</code> is greater than this
- * buffer's <code>remaining()</code>
- * @exception IllegalArgumentException
- * If <code>src</code> is this buffer
- * @exception ReadOnlyBufferException
- * If no changes may be made to the contents of this buffer
- */
- public FloatBuffer put(FloatBuffer src) {
- if (src == this) {
- throw new IllegalArgumentException();
- }
- if (src.remaining() > remaining()) {
- throw new BufferOverflowException();
- }
+
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+ for (int i = off; i < off + len; i++) {
+ put(src[i]);
+ }
+ return this;
+ }
+
+ /**
+ * Writes all the remaining <code>float</code>s of the <code>src</code>
+ * float buffer to this buffer's current position, and increase both
+ * buffers' position by the number of <code>float</code>s copied.
+ *
+ * @param src
+ * The source float buffer
+ * @return This buffer
+ * @exception BufferOverflowException
+ * If <code>src.remaining()</code> is greater than this
+ * buffer's <code>remaining()</code>
+ * @exception IllegalArgumentException
+ * If <code>src</code> is this buffer
+ * @exception ReadOnlyBufferException
+ * If no changes may be made to the contents of this buffer
+ */
+ public FloatBuffer put(FloatBuffer src) {
+ if (src == this) {
+ throw new IllegalArgumentException();
+ }
+ if (src.remaining() > remaining()) {
+ throw new BufferOverflowException();
+ }
float[] contents = new float[src.remaining()];
src.get(contents);
put(contents);
- return this;
- }
+ return this;
+ }
- /**
- * Write a float to the specified index of this buffer and the position is
- * not changed.
- *
- * @param index
- * The index, must be no less than zero and less than the limit
- * @param f
- * The float to write
- * @return This buffer
- * @exception IndexOutOfBoundsException
- * If index is invalid
- * @exception ReadOnlyBufferException
- * If no changes may be made to the contents of this buffer
- */
- public abstract FloatBuffer put(int index, float f);
-
- /**
- * Returns a sliced buffer that shares content with this buffer.
- * <p>
- * The sliced buffer's capacity will be this buffer's
- * <code>remaining()</code>, and its zero position will correspond to
- * this buffer's current position. The new buffer's position will be
- * 0, limit will be its capacity, and its mark is unset. The new buffer's
- * readonly property and byte order are same as this buffer.</p>
- * <p>
- * The new buffer shares content with this buffer, which means
- * either buffer's change of content will be visible to the other.
- * The two buffer's position, limit and mark are independent.</p>
- *
- * @return A sliced buffer that shares content with this buffer.
- */
- public abstract FloatBuffer slice();
-
- /**
- * Returns a string represents the state of this float buffer.
- *
- * @return A string represents the state of this float buffer.
- */
- public String toString() {
- StringBuffer buf = new StringBuffer();
- buf.append(getClass().getName());
- buf.append(", status: capacity="); //$NON-NLS-1$
- buf.append(capacity());
- buf.append(" position="); //$NON-NLS-1$
- buf.append(position());
- buf.append(" limit="); //$NON-NLS-1$
- buf.append(limit());
- return buf.toString();
- }
+ /**
+ * Write a float to the specified index of this buffer and the position is
+ * not changed.
+ *
+ * @param index
+ * The index, must be no less than zero and less than the limit
+ * @param f
+ * The float to write
+ * @return This buffer
+ * @exception IndexOutOfBoundsException
+ * If index is invalid
+ * @exception ReadOnlyBufferException
+ * If no changes may be made to the contents of this buffer
+ */
+ public abstract FloatBuffer put(int index, float f);
+
+ /**
+ * Returns a sliced buffer that shares content with this buffer.
+ * <p>
+ * The sliced buffer's capacity will be this buffer's
+ * <code>remaining()</code>, and its zero position will correspond to
+ * this buffer's current position. The new buffer's position will be 0,
+ * limit will be its capacity, and its mark is unset. The new buffer's
+ * readonly property and byte order are same as this buffer.
+ * </p>
+ * <p>
+ * The new buffer shares content with this buffer, which means either
+ * buffer's change of content will be visible to the other. The two buffer's
+ * position, limit and mark are independent.
+ * </p>
+ *
+ * @return A sliced buffer that shares content with this buffer.
+ */
+ public abstract FloatBuffer slice();
+
+ /**
+ * Returns a string represents the state of this float buffer.
+ *
+ * @return A string represents the state of this float buffer.
+ */
+ @Override
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append(getClass().getName());
+ buf.append(", status: capacity="); //$NON-NLS-1$
+ buf.append(capacity());
+ buf.append(" position="); //$NON-NLS-1$
+ buf.append(position());
+ buf.append(" limit="); //$NON-NLS-1$
+ buf.append(limit());
+ return buf.toString();
+ }
}
Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/FloatToByteBufferAdapter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/FloatToByteBufferAdapter.java?rev=578502&r1=578501&r2=578502&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/FloatToByteBufferAdapter.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/FloatToByteBufferAdapter.java Sat Sep 22 14:24:54 2007
@@ -19,7 +19,6 @@
import org.apache.harmony.nio.internal.DirectBuffer;
import org.apache.harmony.luni.platform.PlatformAddress;
-
/**
* This class wraps a byte buffer to be a float buffer.
* <p>
@@ -33,164 +32,175 @@
* </p>
*
*/
-final class FloatToByteBufferAdapter extends FloatBuffer implements DirectBuffer {
+final class FloatToByteBufferAdapter extends FloatBuffer implements
+ DirectBuffer {
- static FloatBuffer wrap(ByteBuffer byteBuffer) {
- return new FloatToByteBufferAdapter(byteBuffer.slice());
- }
-
- private final ByteBuffer byteBuffer;
-
- FloatToByteBufferAdapter(ByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 2));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- }
-
- public int getByteCapacity() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer)byteBuffer).getByteCapacity();
- } else {
- assert false : byteBuffer;
- return -1;
- }
- }
-
- public PlatformAddress getEffectiveAddress() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer)byteBuffer).getEffectiveAddress();
- } else {
- assert false : byteBuffer;
- return null;
- }
- }
-
- public PlatformAddress getBaseAddress() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer)byteBuffer).getBaseAddress();
- } else {
- assert false : byteBuffer;
- return null;
- }
- }
-
- public boolean isAddressValid() {
- if (byteBuffer instanceof DirectBuffer) {
- return ((DirectBuffer)byteBuffer).isAddressValid();
- } else {
- assert false : byteBuffer;
- return false;
- }
- }
-
- public void addressValidityCheck() {
- if (byteBuffer instanceof DirectBuffer) {
- ((DirectBuffer)byteBuffer).addressValidityCheck();
- } else {
- assert false : byteBuffer;
- }
- }
-
- public void free() {
- if (byteBuffer instanceof DirectBuffer) {
- ((DirectBuffer)byteBuffer).free();
- } else {
- assert false : byteBuffer;
- }
- }
-
- public FloatBuffer asReadOnlyBuffer() {
- FloatToByteBufferAdapter buf = new FloatToByteBufferAdapter(byteBuffer
- .asReadOnlyBuffer());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- public FloatBuffer compact() {
- if (byteBuffer.isReadOnly()) {
- throw new ReadOnlyBufferException();
- }
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
- byteBuffer.compact();
- byteBuffer.clear();
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- public FloatBuffer duplicate() {
- FloatToByteBufferAdapter buf = new FloatToByteBufferAdapter(byteBuffer
- .duplicate());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- public float get() {
- if (position == limit) {
- throw new BufferUnderflowException();
- }
- return byteBuffer.getFloat(position++ << 2);
- }
-
- public float get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return byteBuffer.getFloat(index << 2);
- }
-
- public boolean isDirect() {
- return byteBuffer.isDirect();
- }
-
- public boolean isReadOnly() {
- return byteBuffer.isReadOnly();
- }
-
- public ByteOrder order() {
- return byteBuffer.order();
- }
-
- protected float[] protectedArray() {
- throw new UnsupportedOperationException();
- }
-
- protected int protectedArrayOffset() {
- throw new UnsupportedOperationException();
- }
-
- protected boolean protectedHasArray() {
- return false;
- }
-
- public FloatBuffer put(float c) {
- if (position == limit) {
- throw new BufferOverflowException();
- }
- byteBuffer.putFloat(position++ << 2, c);
- return this;
- }
-
- public FloatBuffer put(int index, float c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- byteBuffer.putFloat(index << 2, c);
- return this;
- }
-
- public FloatBuffer slice() {
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
- FloatBuffer result = new FloatToByteBufferAdapter(byteBuffer.slice());
- byteBuffer.clear();
- return result;
- }
+ static FloatBuffer wrap(ByteBuffer byteBuffer) {
+ return new FloatToByteBufferAdapter(byteBuffer.slice());
+ }
+
+ private final ByteBuffer byteBuffer;
+
+ FloatToByteBufferAdapter(ByteBuffer byteBuffer) {
+ super((byteBuffer.capacity() >> 2));
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ }
+
+ public int getByteCapacity() {
+ if (byteBuffer instanceof DirectBuffer) {
+ return ((DirectBuffer) byteBuffer).getByteCapacity();
+ }
+ assert false : byteBuffer;
+ return -1;
+ }
+
+ public PlatformAddress getEffectiveAddress() {
+ if (byteBuffer instanceof DirectBuffer) {
+ return ((DirectBuffer) byteBuffer).getEffectiveAddress();
+ }
+ assert false : byteBuffer;
+ return null;
+ }
+
+ public PlatformAddress getBaseAddress() {
+ if (byteBuffer instanceof DirectBuffer) {
+ return ((DirectBuffer) byteBuffer).getBaseAddress();
+ }
+ assert false : byteBuffer;
+ return null;
+ }
+
+ public boolean isAddressValid() {
+ if (byteBuffer instanceof DirectBuffer) {
+ return ((DirectBuffer) byteBuffer).isAddressValid();
+ }
+ assert false : byteBuffer;
+ return false;
+ }
+
+ public void addressValidityCheck() {
+ if (byteBuffer instanceof DirectBuffer) {
+ ((DirectBuffer) byteBuffer).addressValidityCheck();
+ } else {
+ assert false : byteBuffer;
+ }
+ }
+
+ public void free() {
+ if (byteBuffer instanceof DirectBuffer) {
+ ((DirectBuffer) byteBuffer).free();
+ } else {
+ assert false : byteBuffer;
+ }
+ }
+
+ @Override
+ public FloatBuffer asReadOnlyBuffer() {
+ FloatToByteBufferAdapter buf = new FloatToByteBufferAdapter(byteBuffer
+ .asReadOnlyBuffer());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public FloatBuffer compact() {
+ if (byteBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ byteBuffer.limit(limit << 2);
+ byteBuffer.position(position << 2);
+ byteBuffer.compact();
+ byteBuffer.clear();
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ @Override
+ public FloatBuffer duplicate() {
+ FloatToByteBufferAdapter buf = new FloatToByteBufferAdapter(byteBuffer
+ .duplicate());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public float get() {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return byteBuffer.getFloat(position++ << 2);
+ }
+
+ @Override
+ public float get(int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return byteBuffer.getFloat(index << 2);
+ }
+
+ @Override
+ public boolean isDirect() {
+ return byteBuffer.isDirect();
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ return byteBuffer.isReadOnly();
+ }
+
+ @Override
+ public ByteOrder order() {
+ return byteBuffer.order();
+ }
+
+ @Override
+ protected float[] protectedArray() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected int protectedArrayOffset() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected boolean protectedHasArray() {
+ return false;
+ }
+
+ @Override
+ public FloatBuffer put(float c) {
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ byteBuffer.putFloat(position++ << 2, c);
+ return this;
+ }
+
+ @Override
+ public FloatBuffer put(int index, float c) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ byteBuffer.putFloat(index << 2, c);
+ return this;
+ }
+
+ @Override
+ public FloatBuffer slice() {
+ byteBuffer.limit(limit << 2);
+ byteBuffer.position(position << 2);
+ FloatBuffer result = new FloatToByteBufferAdapter(byteBuffer.slice());
+ byteBuffer.clear();
+ return result;
+ }
}
Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/HeapByteBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/HeapByteBuffer.java?rev=578502&r1=578501&r2=578502&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/HeapByteBuffer.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/HeapByteBuffer.java Sat Sep 22 14:24:54 2007
@@ -33,27 +33,27 @@
*/
abstract class HeapByteBuffer extends BaseByteBuffer {
- protected final byte[] backingArray;
+ protected final byte[] backingArray;
- protected final int offset;
+ protected final int offset;
- HeapByteBuffer(byte[] backingArray) {
- this(backingArray, backingArray.length, 0);
- }
-
- HeapByteBuffer(int capacity) {
- this(new byte[capacity], capacity, 0);
- }
-
- HeapByteBuffer(byte[] backingArray, int capacity, int offset) {
- super(capacity);
- this.backingArray = backingArray;
- this.offset = offset;
-
- if (offset + capacity > backingArray.length) {
- throw new IndexOutOfBoundsException();
- }
- }
+ HeapByteBuffer(byte[] backingArray) {
+ this(backingArray, backingArray.length, 0);
+ }
+
+ HeapByteBuffer(int capacity) {
+ this(new byte[capacity], capacity, 0);
+ }
+
+ HeapByteBuffer(byte[] backingArray, int capacity, int offset) {
+ super(capacity);
+ this.backingArray = backingArray;
+ this.offset = offset;
+
+ if (offset + capacity > backingArray.length) {
+ throw new IndexOutOfBoundsException();
+ }
+ }
/*
* Override ByteBuffer.get(byte[], int, int) to improve performance.
@@ -62,9 +62,10 @@
*
* @see java.nio.ByteBuffer#get(byte[], int, int)
*/
+ @Override
public final ByteBuffer get(byte[] dest, int off, int len) {
int length = dest.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ if (off < 0 || len < 0 || (long) off + (long) len > length) {
throw new IndexOutOfBoundsException();
}
if (len > remaining()) {
@@ -74,141 +75,154 @@
position += len;
return this;
}
-
- public final byte get() {
- if (position == limit) {
- throw new BufferUnderflowException();
- }
- return backingArray[offset + position++];
- }
-
- public final byte get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return backingArray[offset + index];
- }
-
- public final double getDouble() {
- return Double.longBitsToDouble(getLong());
- }
-
- public final double getDouble(int index) {
- return Double.longBitsToDouble(getLong(index));
- }
-
- public final float getFloat() {
- return Float.intBitsToFloat(getInt());
- }
-
- public final float getFloat(int index) {
- return Float.intBitsToFloat(getInt(index));
- }
-
- public final int getInt() {
- int newPosition = position + 4;
- if (newPosition > limit) {
- throw new BufferUnderflowException();
- }
- int result = loadInt(position);
- position = newPosition;
- return result;
- }
-
- public final int getInt(int index) {
- if (index < 0 || index + 4 > limit) {
- throw new IndexOutOfBoundsException();
- }
- return loadInt(index);
- }
-
- public final long getLong() {
- int newPosition = position + 8;
- if (newPosition > limit) {
- throw new BufferUnderflowException();
- }
- long result = loadLong(position);
- position = newPosition;
- return result;
- }
-
- public final long getLong(int index) {
- if (index < 0 || index + 8 > limit) {
- throw new IndexOutOfBoundsException();
- }
- return loadLong(index);
- }
-
- public final short getShort() {
- int newPosition = position + 2;
- if (newPosition > limit) {
- throw new BufferUnderflowException();
- }
- short result = loadShort(position);
- position = newPosition;
- return result;
- }
-
- public final short getShort(int index) {
- if (index < 0 || index + 2 > limit) {
- throw new IndexOutOfBoundsException();
- }
- return loadShort(index);
- }
-
- public final boolean isDirect() {
- return false;
- }
-
- protected final int loadInt(int index) {
- int baseOffset = offset + index;
- int bytes = 0;
- if(order == Endianness.BIG_ENDIAN){
+
+ @Override
+ public final byte get() {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return backingArray[offset + position++];
+ }
+
+ @Override
+ public final byte get(int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return backingArray[offset + index];
+ }
+
+ @Override
+ public final double getDouble() {
+ return Double.longBitsToDouble(getLong());
+ }
+
+ @Override
+ public final double getDouble(int index) {
+ return Double.longBitsToDouble(getLong(index));
+ }
+
+ @Override
+ public final float getFloat() {
+ return Float.intBitsToFloat(getInt());
+ }
+
+ @Override
+ public final float getFloat(int index) {
+ return Float.intBitsToFloat(getInt(index));
+ }
+
+ @Override
+ public final int getInt() {
+ int newPosition = position + 4;
+ if (newPosition > limit) {
+ throw new BufferUnderflowException();
+ }
+ int result = loadInt(position);
+ position = newPosition;
+ return result;
+ }
+
+ @Override
+ public final int getInt(int index) {
+ if (index < 0 || index + 4 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return loadInt(index);
+ }
+
+ @Override
+ public final long getLong() {
+ int newPosition = position + 8;
+ if (newPosition > limit) {
+ throw new BufferUnderflowException();
+ }
+ long result = loadLong(position);
+ position = newPosition;
+ return result;
+ }
+
+ @Override
+ public final long getLong(int index) {
+ if (index < 0 || index + 8 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return loadLong(index);
+ }
+
+ @Override
+ public final short getShort() {
+ int newPosition = position + 2;
+ if (newPosition > limit) {
+ throw new BufferUnderflowException();
+ }
+ short result = loadShort(position);
+ position = newPosition;
+ return result;
+ }
+
+ @Override
+ public final short getShort(int index) {
+ if (index < 0 || index + 2 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return loadShort(index);
+ }
+
+ @Override
+ public final boolean isDirect() {
+ return false;
+ }
+
+ protected final int loadInt(int index) {
+ int baseOffset = offset + index;
+ int bytes = 0;
+ if (order == Endianness.BIG_ENDIAN) {
for (int i = 0; i < 4; i++) {
bytes = bytes << 8;
bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
- }
- }else{
+ }
+ } else {
for (int i = 3; i >= 0; i--) {
bytes = bytes << 8;
bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
}
}
return bytes;
- }
+ }
- protected final long loadLong(int index) {
- int baseOffset = offset + index;
- long bytes = 0;
- if(order == Endianness.BIG_ENDIAN){
+ protected final long loadLong(int index) {
+ int baseOffset = offset + index;
+ long bytes = 0;
+ if (order == Endianness.BIG_ENDIAN) {
for (int i = 0; i < 8; i++) {
bytes = bytes << 8;
bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
- }
- }else{
+ }
+ } else {
for (int i = 7; i >= 0; i--) {
bytes = bytes << 8;
bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
}
}
return bytes;
- }
+ }
- protected final short loadShort(int index) {
- int baseOffset = offset + index;
- short bytes = 0;
- if(order == Endianness.BIG_ENDIAN){
+ protected final short loadShort(int index) {
+ int baseOffset = offset + index;
+ short bytes = 0;
+ if (order == Endianness.BIG_ENDIAN) {
bytes = (short) (backingArray[baseOffset] << 8);
- bytes |= (backingArray[baseOffset + 1] & 0xFF);
- }else{
- bytes = (short) (backingArray[baseOffset+1] << 8);
+ bytes |= (backingArray[baseOffset + 1] & 0xFF);
+ } else {
+ bytes = (short) (backingArray[baseOffset + 1] << 8);
bytes |= (backingArray[baseOffset] & 0xFF);
}
return bytes;
- }
+ }
- protected final void store(int index, int value) {
- int baseOffset = offset + index;
+ protected final void store(int index, int value) {
+ int baseOffset = offset + index;
if (order == Endianness.BIG_ENDIAN) {
for (int i = 3; i >= 0; i--) {
backingArray[baseOffset + i] = (byte) (value & 0xFF);
@@ -220,10 +234,10 @@
value = value >> 8;
}
}
- }
+ }
- protected final void store(int index, long value) {
- int baseOffset = offset + index;
+ protected final void store(int index, long value) {
+ int baseOffset = offset + index;
if (order == Endianness.BIG_ENDIAN) {
for (int i = 7; i >= 0; i--) {
backingArray[baseOffset + i] = (byte) (value & 0xFF);
@@ -235,16 +249,16 @@
value = value >> 8;
}
}
- }
+ }
- protected final void store(int index, short value) {
- int baseOffset = offset + index;
+ protected final void store(int index, short value) {
+ int baseOffset = offset + index;
if (order == Endianness.BIG_ENDIAN) {
backingArray[baseOffset] = (byte) ((value >> 8) & 0xFF);
backingArray[baseOffset + 1] = (byte) (value & 0xFF);
} else {
- backingArray[baseOffset+1] = (byte) ((value >> 8) & 0xFF);
+ backingArray[baseOffset + 1] = (byte) ((value >> 8) & 0xFF);
backingArray[baseOffset] = (byte) (value & 0xFF);
}
- }
+ }
}
Modified: harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/IntArrayBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/IntArrayBuffer.java?rev=578502&r1=578501&r2=578502&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/IntArrayBuffer.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/nio/src/main/java/java/nio/IntArrayBuffer.java Sat Sep 22 14:24:54 2007
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package java.nio;
+package java.nio;
/**
* IntArrayBuffer, ReadWriteIntArrayBuffer and ReadOnlyIntArrayBuffer compose
@@ -31,57 +31,62 @@
*/
abstract class IntArrayBuffer extends IntBuffer {
- protected final int[] backingArray;
+ protected final int[] backingArray;
- protected final int offset;
+ protected final int offset;
- IntArrayBuffer(int[] array) {
- this(array.length, array, 0);
- }
-
- IntArrayBuffer(int capacity) {
- this(capacity, new int[capacity], 0);
- }
-
- IntArrayBuffer(int capacity, int[] backingArray, int offset) {
- super(capacity);
- this.backingArray = backingArray;
- this.offset = offset;
- }
-
- public final int get() {
- if (position == limit) {
- throw new BufferUnderflowException();
- }
- return backingArray[offset + position++];
- }
-
- public final int get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return backingArray[offset + index];
- }
+ IntArrayBuffer(int[] array) {
+ this(array.length, array, 0);
+ }
+
+ IntArrayBuffer(int capacity) {
+ this(capacity, new int[capacity], 0);
+ }
+
+ IntArrayBuffer(int capacity, int[] backingArray, int offset) {
+ super(capacity);
+ this.backingArray = backingArray;
+ this.offset = offset;
+ }
+
+ @Override
+ public final int get() {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return backingArray[offset + position++];
+ }
+ @Override
+ public final int get(int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return backingArray[offset + index];
+ }
+
+ @Override
public final IntBuffer get(int[] dest, int off, int len) {
int length = dest.length;
- if (off < 0 || len < 0 || (long)len + (long)off > length) {
+ if (off < 0 || len < 0 || (long) len + (long) off > length) {
throw new IndexOutOfBoundsException();
- }
+ }
if (len > remaining()) {
throw new BufferUnderflowException();
}
- System.arraycopy(backingArray, offset+position, dest, off, len);
+ System.arraycopy(backingArray, offset + position, dest, off, len);
position += len;
return this;
}
-
- public final boolean isDirect() {
- return false;
- }
-
- public final ByteOrder order() {
- return ByteOrder.nativeOrder();
- }
+
+ @Override
+ public final boolean isDirect() {
+ return false;
+ }
+
+ @Override
+ public final ByteOrder order() {
+ return ByteOrder.nativeOrder();
+ }
}