aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/nio/FloatBuffer.java
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2003-05-12 20:45:20 +0000
committerMichael Koch <mkoch@gcc.gnu.org>2003-05-12 20:45:20 +0000
commit36d4669b735c0e6f665e9a83bdd0848e23fc6662 (patch)
treeeba2e2a8271971b25fa39af84cbebe056dd27e91 /libjava/java/nio/FloatBuffer.java
parentd3e0dffb76fd85d777f5c5de71f47816121bc5e3 (diff)
downloadgcc-36d4669b735c0e6f665e9a83bdd0848e23fc6662.zip
gcc-36d4669b735c0e6f665e9a83bdd0848e23fc6662.tar.gz
gcc-36d4669b735c0e6f665e9a83bdd0848e23fc6662.tar.bz2
ByteBufferImpl.java: Reformatted.
2003-05-12 Michael Koch <konqueror@gmx.de> * gnu/java/nio/ByteBufferImpl.java: Reformatted. (nio_get_*): Removed. (nio_put_*): Removed. (as*Buffer): Implemented. (compact): Implemented. (get): Documentation added. (put): Documentation added. (get*): Newly implemented. (put*): Newly implemented. * gnu/java/nio/CharBufferImpl.java: Reformatted. (CharBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * gnu/java/nio/DirectByteBufferImpl.java (allocateDirect): objects can be null not 0. * gnu/java/nio/DoubleBufferImpl.java: Reformatted. (DoubleBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * gnu/java/nio/FloatBufferImpl.java: Reformatted. (FloatBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * gnu/java/nio/IntBufferImpl.java: Reformatted. (IntBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * gnu/java/nio/LongBufferImpl.java: Reformatted. (LongBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * gnu/java/nio/ShortBufferImpl.java: Reformatted. (ShortBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * java/nio/CharBuffer.java: Reformatted, much documentation rewritten. (CharBuffer): Revised. (order): Removed. * java/nio/DoubleBuffer.java: Reformatted, much documentation rewritten. (DoubleBuffer): Revised. (allocateDirect): Removed. (order): Removed. * java/nio/FloatBuffer.java: Reformatted, much documentation rewritten. (FloatBuffer): Revised. (allocateDirect): Removed. (order): Removed. * java/nio/IntBuffer.java: Reformatted, much documentation rewritten. (IntBuffer): Revised. (allocateDirect): Removed. (order): Removed. * java/nio/LongBuffer.java: Reformatted, much documentation rewritten. (LongBuffer): Revised. (allocateDirect): Removed. (order): Removed. * java/nio/ShortBuffer.java: Reformatted, much documentation rewritten. (ShortBuffer): Revised. (allocateDirect): Removed. (order): Removed. * gnu/java/nio/natByteBufferImpl.cc: Removed. * gnu/java/nio/natCharBufferImpl.cc: Removed. * Makefile.am (ordinary_java_source_files): Added the following files: gnu/java/nio/CharViewBufferImpl.java, gnu/java/nio/DoubleViewBufferImpl.java, gnu/java/nio/FloatViewBufferImpl.java, gnu/java/nio/IntViewBufferImpl.java, gnu/java/nio/LongViewBufferImpl.java, gnu/java/nio/ShortViewBufferImpl.java (nat_source_files): Removed the following files: gnu/java/nio/natByteBufferImpl.cc, gnu/java/nio/natCharBufferImpl.cc * Makefile.in: Regenerated. From-SVN: r66733
Diffstat (limited to 'libjava/java/nio/FloatBuffer.java')
-rw-r--r--libjava/java/nio/FloatBuffer.java284
1 files changed, 227 insertions, 57 deletions
diff --git a/libjava/java/nio/FloatBuffer.java b/libjava/java/nio/FloatBuffer.java
index 81feb45..65d680b 100644
--- a/libjava/java/nio/FloatBuffer.java
+++ b/libjava/java/nio/FloatBuffer.java
@@ -1,5 +1,5 @@
/* FloatBuffer.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -39,93 +39,182 @@ package java.nio;
import gnu.java.nio.FloatBufferImpl;
-public abstract class FloatBuffer extends Buffer implements Comparable
+/**
+ * @since 1.4
+ */
+public abstract class FloatBuffer extends Buffer
+ implements Comparable
{
int array_offset;
float[] backing_buffer;
- public static FloatBuffer allocateDirect(int capacity)
+ FloatBuffer (int capacity, int limit, int position, int mark)
{
- throw new Error ("direct buffers not implemented");
+ super (capacity, limit, position, mark);
+ array_offset = 0;
}
- public static FloatBuffer allocate(int capacity)
+ FloatBuffer (float[] buffer, int offset, int capacity, int limit, int position, int mark)
{
- return new FloatBufferImpl (capacity, 0, capacity);
+ super (capacity, limit, position, mark);
+ this.backing_buffer = buffer;
+ this.array_offset = offset;
}
- final public static FloatBuffer wrap(float[] array, int offset, int length)
+ /**
+ * Allocates a new <code>FloatBuffer</code> object with a given capacity.
+ */
+ public static FloatBuffer allocate (int capacity)
{
- return new FloatBufferImpl(array, offset, length);
+ return new FloatBufferImpl (capacity);
}
- final public static FloatBuffer wrap(String a)
+ /**
+ * Wraps a <code>float</code> array into a <code>FloatBuffer</code>
+ * object.
+ *
+ * @exception IndexOutOfBoundsException If the preconditions on the offset
+ * and length parameters do not hold
+ */
+ final public static FloatBuffer wrap (float[] array, int offset, int length)
{
- int len = a.length();
- float[] buffer = new float[len];
-
- for (int i=0;i<len;i++)
- {
- buffer[i] = (float) a.charAt(i);
- }
-
- return wrap(buffer, 0, len);
+ return new FloatBufferImpl (array, 0, array.length, offset + length, offset, -1, false);
}
- final public static FloatBuffer wrap(float[] array)
+ /**
+ * Wraps a <code>float</code> array into a <code>FloatBuffer</code>
+ * object.
+ */
+ final public static FloatBuffer wrap (float[] array)
{
- return wrap(array, 0, array.length);
- }
-
- FloatBuffer (int capacity, int limit, int position, int mark)
- {
- super (capacity, limit, position, mark);
- array_offset = 0;
+ return wrap (array, 0, array.length);
}
+ /**
+ * This method transfers <code>floats<code> from this buffer into the given
+ * destination array.
+ *
+ * @param dst The destination array
+ * @param offset The offset within the array of the first <code>float</code>
+ * to be written; must be non-negative and no larger than dst.length.
+ * @param length The maximum number of bytes to be written to the given array;
+ * must be non-negative and no larger than dst.length - offset.
+ *
+ * @exception BufferUnderflowException If there are fewer than length
+ * <code>floats</code> remaining in this buffer.
+ * @exception IndexOutOfBoundsException If the preconditions on the offset
+ * and length parameters do not hold.
+ */
public FloatBuffer get (float[] dst, int offset, int length)
{
for (int i = offset; i < offset + length; i++)
{
- dst[i] = get();
+ dst [i] = get ();
}
return this;
}
+ /**
+ * This method transfers <code>floats<code> from this buffer into the given
+ * destination array.
+ *
+ * @param dst The byte array to write into.
+ *
+ * @exception BufferUnderflowException If there are fewer than dst.length
+ * <code>floats</code> remaining in this buffer.
+ */
public FloatBuffer get (float[] dst)
{
- return get(dst, 0, dst.length);
+ return get (dst, 0, dst.length);
}
+ /**
+ * Writes the content of the the <code>FloatBUFFER</code> src
+ * into the buffer.
+ *
+ * @param src The source data.
+ *
+ * @exception BufferOverflowException If there is insufficient space in this
+ * buffer for the remaining <code>floats<code> in the source buffer.
+ * @exception IllegalArgumentException If the source buffer is this buffer.
+ * @exception ReadOnlyBufferException If this buffer is read-only.
+ */
public FloatBuffer put (FloatBuffer src)
{
- while (src.hasRemaining())
- put(src.get());
+ if (src == this)
+ throw new IllegalArgumentException ();
+
+ if (src.remaining () > remaining ())
+ throw new BufferOverflowException ();
+
+ if (src.remaining () > 0)
+ {
+ float[] toPut = new float [src.remaining ()];
+ src.get (toPut);
+ src.put (toPut);
+ }
return this;
}
+ /**
+ * Writes the content of the the <code>float array</code> src
+ * into the buffer.
+ *
+ * @param src The array to copy into the buffer.
+ * @param offset The offset within the array of the first byte to be read;
+ * must be non-negative and no larger than src.length.
+ * @param length The number of bytes to be read from the given array;
+ * must be non-negative and no larger than src.length - offset.
+ *
+ * @exception BufferOverflowException If there is insufficient space in this
+ * buffer for the remaining <code>floats<code> in the source array.
+ * @exception IndexOutOfBoundsException If the preconditions on the offset
+ * and length parameters do not hold
+ * @exception ReadOnlyBufferException If this buffer is read-only.
+ */
public FloatBuffer put (float[] src, int offset, int length)
{
for (int i = offset; i < offset + length; i++)
- put(src[i]);
+ put (src [i]);
return this;
}
- public final FloatBuffer put(float[] src)
+ /**
+ * Writes the content of the the <code>float array</code> src
+ * into the buffer.
+ *
+ * @param src The array to copy into the buffer.
+ *
+ * @exception BufferOverflowException If there is insufficient space in this
+ * buffer for the remaining <code>floats<code> in the source array.
+ * @exception ReadOnlyBufferException If this buffer is read-only.
+ */
+ public final FloatBuffer put (float[] src)
{
- return put(src, 0, src.length);
+ return put (src, 0, src.length);
}
- public final boolean hasArray()
+ /**
+ * Tells whether ot not this buffer is backed by an accessible
+ * <code>float</code> array.
+ */
+ public final boolean hasArray ()
{
return (backing_buffer != null
&& !isReadOnly ());
}
- public final float[] array()
+ /**
+ * Returns the <code>float</code> array that backs this buffer.
+ *
+ * @exception ReadOnlyBufferException If this buffer is read-only.
+ * @exception UnsupportedOperationException If this buffer is not backed
+ * by an accessible array.
+ */
+ public final float[] array ()
{
if (backing_buffer == null)
throw new UnsupportedOperationException ();
@@ -136,7 +225,14 @@ public abstract class FloatBuffer extends Buffer implements Comparable
return backing_buffer;
}
- public final int arrayOffset()
+ /**
+ * Returns the offset within this buffer's backing array of the first element.
+ *
+ * @exception ReadOnlyBufferException If this buffer is read-only.
+ * @exception UnsupportedOperationException If this buffer is not backed
+ * by an accessible array.
+ */
+ public final int arrayOffset ()
{
if (backing_buffer == null)
throw new UnsupportedOperationException ();
@@ -147,41 +243,55 @@ public abstract class FloatBuffer extends Buffer implements Comparable
return array_offset;
}
- public int hashCode()
+ /**
+ * Calculates a hash code for this buffer.
+ */
+ public int hashCode ()
{
- return super.hashCode();
+ // FIXME: Check what SUN calculates here.
+ return super.hashCode ();
}
- public boolean equals(Object obj)
+ /**
+ * Checks if this buffer is equal to obj.
+ */
+ public boolean equals (Object obj)
{
if (obj instanceof FloatBuffer)
{
- return compareTo(obj) == 0;
+ return compareTo (obj) == 0;
}
return false;
}
- public int compareTo(Object ob)
+ /**
+ * Compares two <code>FloatBuffer</code> objects.
+ *
+ * @exception ClassCastException If obj is not an object derived from
+ * <code>FloatBuffer</code>.
+ */
+ public int compareTo (Object obj)
{
- FloatBuffer a = (FloatBuffer) ob;
+ FloatBuffer a = (FloatBuffer) obj;
- if (a.remaining() != remaining())
+ if (a.remaining () != remaining ())
return 1;
- if (! hasArray() ||
- ! a.hasArray())
+ if (! hasArray () ||
+ ! a.hasArray ())
{
return 1;
}
- int r = remaining();
+ int r = remaining ();
int i1 = position ();
int i2 = a.position ();
- for (int i=0;i<r;i++)
+ for (int i = 0; i < r; i++)
{
- int t = (int) (get(i1)- a.get(i2));
+ int t = (int) (get (i1) - a.get (i2));
+
if (t != 0)
{
return (int) t;
@@ -191,14 +301,74 @@ public abstract class FloatBuffer extends Buffer implements Comparable
return 0;
}
+ /**
+ * Returns the byte order of this buffer.
+ */
public abstract ByteOrder order ();
- public abstract float get();
- public abstract java.nio. FloatBuffer put(float b);
- public abstract float get(int index);
- public abstract java.nio. FloatBuffer put(int index, float b);
- public abstract FloatBuffer compact();
- public abstract boolean isDirect();
- public abstract FloatBuffer slice();
- public abstract FloatBuffer duplicate();
- public abstract FloatBuffer asReadOnlyBuffer();
+
+ /**
+ * Reads the <code>float</code> at this buffer's current position,
+ * and then increments the position.
+ *
+ * @exception BufferUnderflowException If there are no remaining
+ * <code>floats</code> in this buffer.
+ */
+ public abstract float get ();
+
+ /**
+ * Writes the <code>float</code> at this buffer's current position,
+ * and then increments the position.
+ *
+ * @exception BufferOverflowException If there no remaining
+ * <code>floats</code> in this buffer.
+ * @exception ReadOnlyBufferException If this buffer is read-only.
+ */
+ public abstract FloatBuffer put (float b);
+
+ /**
+ * Absolute get method.
+ *
+ * @exception IndexOutOfBoundsException If index is negative or not smaller
+ * than the buffer's limit.
+ */
+ public abstract float get (int index);
+
+ /**
+ * Absolute put method.
+ *
+ * @exception IndexOutOfBoundsException If index is negative or not smaller
+ * than the buffer's limit.
+ * @exception ReadOnlyBufferException If this buffer is read-only.
+ */
+ public abstract FloatBuffer put (int index, float b);
+
+ /**
+ * Compacts this buffer.
+ *
+ * @exception ReadOnlyBufferException If this buffer is read-only.
+ */
+ public abstract FloatBuffer compact ();
+
+ /**
+ * Tells wether or not this buffer is direct.
+ */
+ public abstract boolean isDirect ();
+
+ /**
+ * Creates a new <code>FloatBuffer</code> whose content is a shared
+ * subsequence of this buffer's content.
+ */
+ public abstract FloatBuffer slice ();
+
+ /**
+ * Creates a new <code>FloatBuffer</code> that shares this buffer's
+ * content.
+ */
+ public abstract FloatBuffer duplicate ();
+
+ /**
+ * Creates a new read-only <code>FloatBuffer</code> that shares this
+ * buffer's content.
+ */
+ public abstract FloatBuffer asReadOnlyBuffer ();
}