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
This commit is contained in:
Michael Koch 2003-05-12 20:45:20 +00:00 committed by Michael Koch
parent d3e0dffb76
commit 36d4669b73
19 changed files with 2056 additions and 976 deletions

View file

@ -1,5 +1,5 @@
/* IntBuffer.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.IntBufferImpl;
public abstract class IntBuffer extends Buffer implements Comparable
/**
* @since 1.4
*/
public abstract class IntBuffer extends Buffer
implements Comparable
{
int array_offset;
int[] backing_buffer;
public static IntBuffer allocateDirect(int capacity)
{
throw new Error ("direct buffers not implemented");
}
public static IntBuffer allocate(int capacity)
{
return new IntBufferImpl (capacity, 0, capacity);
}
final public static IntBuffer wrap(int[] array, int offset, int length)
{
return new IntBufferImpl(array, offset, length);
}
final public static IntBuffer wrap(String a)
{
int len = a.length();
int[] buffer = new int[len];
for (int i=0;i<len;i++)
{
buffer[i] = (int) a.charAt(i);
}
return wrap(buffer, 0, len);
}
final public static IntBuffer wrap(int[] array)
{
return wrap(array, 0, array.length);
}
IntBuffer (int capacity, int limit, int position, int mark)
{
super (capacity, limit, position, mark);
array_offset = 0;
}
IntBuffer (int[] buffer, int offset, int capacity, int limit, int position, int mark)
{
super (capacity, limit, position, mark);
this.backing_buffer = buffer;
this.array_offset = offset;
}
/**
* Allocates a new <code>IntBuffer</code> object with a given capacity.
*/
public static IntBuffer allocate (int capacity)
{
return new IntBufferImpl (capacity);
}
/**
* Wraps a <code>int</code> array into a <code>IntBuffer</code>
* object.
*
* @exception IndexOutOfBoundsException If the preconditions on the offset
* and length parameters do not hold
*/
final public static IntBuffer wrap (int[] array, int offset, int length)
{
return new IntBufferImpl (array, 0, array.length, offset + length, offset, -1, false);
}
/**
* Wraps a <code>int</code> array into a <code>IntBuffer</code>
* object.
*/
final public static IntBuffer wrap (int[] array)
{
return wrap (array, 0, array.length);
}
public IntBuffer get(int[] dst, int offset, int length)
/**
* This method transfers <code>ints<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>int</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>ints</code> remaining in this buffer.
* @exception IndexOutOfBoundsException If the preconditions on the offset
* and length parameters do not hold.
*/
public IntBuffer get (int[] 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>ints<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>ints</code> remaining in this buffer.
*/
public IntBuffer get (int[] dst)
{
return get(dst, 0, dst.length);
return get (dst, 0, dst.length);
}
/**
* Writes the content of the the <code>IntBUFFER</code> src
* into the buffer.
*
* @param src The source data.
*
* @exception BufferOverflowException If there is insufficient space in this
* buffer for the remaining <code>ints<code> in the source buffer.
* @exception IllegalArgumentException If the source buffer is this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public IntBuffer put (IntBuffer src)
{
while (src.hasRemaining())
put(src.get());
if (src == this)
throw new IllegalArgumentException ();
if (src.remaining () > remaining ())
throw new BufferOverflowException ();
if (src.remaining () > 0)
{
int[] toPut = new int [src.remaining ()];
src.get (toPut);
src.put (toPut);
}
return this;
}
/**
* Writes the content of the the <code>int 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>ints<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 IntBuffer put (int[] src, int offset, int length)
{
for (int i = offset; i < offset + length; i++)
put(src[i]);
put (src [i]);
return this;
}
public final IntBuffer put(int[] src)
/**
* Writes the content of the the <code>int 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>ints<code> in the source array.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public final IntBuffer put (int[] 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>int</code> array.
*/
public final boolean hasArray ()
{
return (backing_buffer != null
&& !isReadOnly ());
}
public final int[] array()
/**
* Returns the <code>int</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 int[] array ()
{
if (backing_buffer == null)
throw new UnsupportedOperationException ();
@ -136,7 +225,14 @@ public abstract class IntBuffer 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 IntBuffer 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 IntBuffer)
{
return compareTo(obj) == 0;
return compareTo (obj) == 0;
}
return false;
}
public int compareTo(Object ob)
/**
* Compares two <code>IntBuffer</code> objects.
*
* @exception ClassCastException If obj is not an object derived from
* <code>IntBuffer</code>.
*/
public int compareTo (Object obj)
{
IntBuffer a = (IntBuffer) ob;
IntBuffer a = (IntBuffer) 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 IntBuffer extends Buffer implements Comparable
return 0;
}
public abstract ByteOrder order();
public abstract int get();
public abstract IntBuffer put(int b);
public abstract int get(int index);
public abstract IntBuffer put(int index, int b);
public abstract IntBuffer compact();
public abstract boolean isDirect();
public abstract IntBuffer slice();
public abstract IntBuffer duplicate();
public abstract IntBuffer asReadOnlyBuffer();
/**
* Returns the byte order of this buffer.
*/
public abstract ByteOrder order ();
/**
* Reads the <code>int</code> at this buffer's current position,
* and then increments the position.
*
* @exception BufferUnderflowException If there are no remaining
* <code>ints</code> in this buffer.
*/
public abstract int get ();
/**
* Writes the <code>int</code> at this buffer's current position,
* and then increments the position.
*
* @exception BufferOverflowException If there no remaining
* <code>ints</code> in this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public abstract IntBuffer put (int b);
/**
* Absolute get method.
*
* @exception IndexOutOfBoundsException If index is negative or not smaller
* than the buffer's limit.
*/
public abstract int 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 IntBuffer put (int index, int b);
/**
* Compacts this buffer.
*
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public abstract IntBuffer compact ();
/**
* Tells wether or not this buffer is direct.
*/
public abstract boolean isDirect ();
/**
* Creates a new <code>IntBuffer</code> whose content is a shared
* subsequence of this buffer's content.
*/
public abstract IntBuffer slice ();
/**
* Creates a new <code>IntBuffer</code> that shares this buffer's
* content.
*/
public abstract IntBuffer duplicate ();
/**
* Creates a new read-only <code>IntBuffer</code> that shares this
* buffer's content.
*/
public abstract IntBuffer asReadOnlyBuffer ();
}