diff options
author | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-05-12 20:45:20 +0000 |
---|---|---|
committer | mkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-05-12 20:45:20 +0000 |
commit | 696924f928ac3e5b2620dc30be71863ea3ae7374 (patch) | |
tree | eba2e2a8271971b25fa39af84cbebe056dd27e91 /libjava/java/nio/CharBuffer.java | |
parent | c62e29e138d1d7dfc7915ab1eeb5e864499aa071 (diff) | |
download | gcc-696924f928ac3e5b2620dc30be71863ea3ae7374.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@66733 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/nio/CharBuffer.java')
-rw-r--r-- | libjava/java/nio/CharBuffer.java | 240 |
1 files changed, 148 insertions, 92 deletions
diff --git a/libjava/java/nio/CharBuffer.java b/libjava/java/nio/CharBuffer.java index 2158af0160f..fbee6dfb9dd 100644 --- a/libjava/java/nio/CharBuffer.java +++ b/libjava/java/nio/CharBuffer.java @@ -1,5 +1,5 @@ /* CharBuffer.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -45,26 +45,40 @@ import gnu.java.nio.CharBufferImpl; public abstract class CharBuffer extends Buffer implements Comparable, CharSequence { - int array_offset = 0; + int array_offset; char[] backing_buffer; - + + CharBuffer (int capacity, int limit, int position, int mark) + { + super (capacity, limit, position, mark); + array_offset = 0; + } + + CharBuffer (char[] 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>CharBuffer</code> object with a given capacity. */ public static CharBuffer allocate (int capacity) { - return new CharBufferImpl (capacity, 0, capacity); + return new CharBufferImpl (capacity); } - + /** - * Wraps a character array into a <code>CharBuffer</code> object. - * + * Wraps a <code>char</code> array into a <code>CharBuffer</code> + * object. + * * @exception IndexOutOfBoundsException If the preconditions on the offset * and length parameters do not hold */ final public static CharBuffer wrap (char[] array, int offset, int length) { - return new CharBufferImpl (array, offset, length); + return new CharBufferImpl (array, 0, array.length, offset + length, offset, -1, false); } /** @@ -101,27 +115,30 @@ public abstract class CharBuffer extends Buffer return wrap (buffer, offset, length); } - + /** - * Wraps a character array into a <code>CharBuffer</code> object. + * Wraps a <code>char</code> array into a <code>CharBuffer</code> + * object. */ final public static CharBuffer wrap (char[] array) { return wrap (array, 0, array.length); } - - CharBuffer (int cap, int lim, int pos, int mark) - { - super (cap, lim, pos, mark); - } /** - * Relative get method. - * - * @exception BufferUnderflowException If the buffer's current position is - * not smaller than its limit. + * This method transfers <code>chars<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>char</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>chars</code> remaining in this buffer. * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold + * and length parameters do not hold. */ public CharBuffer get (char[] dst, int offset, int length) { @@ -129,24 +146,32 @@ public abstract class CharBuffer extends Buffer { dst [i] = get (); } - + return this; } - + /** - * Relative get method. - * - * @exception BufferUnderflowException If there are fewer than length - * characters remaining in this buffer. + * This method transfers <code>chars<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>chars</code> remaining in this buffer. */ public CharBuffer get (char[] dst) { return get (dst, 0, dst.length); } - + /** - * @exception BufferOverflowException If there are fewer than length of - * source buffer characters remaining in this buffer. + * Writes the content of the the <code>CharBUFFER</code> src + * into the buffer. + * + * @param src The source data. + * + * @exception BufferOverflowException If there is insufficient space in this + * buffer for the remaining <code>chars<code> in the source buffer. * @exception IllegalArgumentException If the source buffer is this buffer. * @exception ReadOnlyBufferException If this buffer is read-only. */ @@ -155,19 +180,31 @@ public abstract class CharBuffer extends Buffer if (src == this) throw new IllegalArgumentException (); - if (src.length () > 0) + if (src.remaining () > remaining ()) + throw new BufferOverflowException (); + + if (src.remaining () > 0) { - char [] toPut = new char [src.length ()]; + char[] toPut = new char [src.remaining ()]; src.get (toPut); src.put (toPut); } return this; } - + /** - * @exception BufferOverflowException If there are fewer then length - * characters remaining in this buffer. + * Writes the content of the the <code>char 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>chars<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. @@ -185,18 +222,19 @@ public abstract class CharBuffer extends Buffer throw new BufferOverflowException (); for (int i = offset; i < offset + length; i++) - { - put (src [i]); - } + put (src [i]); return this; } /** - * Relative put method. + * Writes the content of the the <code>char array</code> src + * into the buffer. + * + * @param src The array to copy into the buffer. * - * @exception BufferOverflowException If there are fewer then length of the - * array characters remaining in this buffer. + * @exception BufferOverflowException If there is insufficient space in this + * buffer for the remaining <code>chars<code> in the source array. * @exception ReadOnlyBufferException If this buffer is read-only. */ public final CharBuffer put (char[] src) @@ -205,17 +243,18 @@ public abstract class CharBuffer extends Buffer } /** - * Tells wether this is buffer is backed by an accessible array or not. + * Tells whether ot not this buffer is backed by an accessible + * <code>char</code> array. */ public final boolean hasArray () { return (backing_buffer != null - && ! isReadOnly ()); + && !isReadOnly ()); } /** - * Returns the array that backs this buffer. - * + * Returns the <code>char</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. @@ -230,10 +269,10 @@ public abstract class CharBuffer extends Buffer return backing_buffer; } - + /** - * Returns the offset to the position of a character in this buffer. - * + * 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. @@ -248,78 +287,92 @@ public abstract class CharBuffer extends Buffer return array_offset; } - + /** - * Calculates a hash code for this buffer- + * Calculates a hash code for this buffer. */ public int hashCode () { // FIXME: Check what SUN calculates here. return super.hashCode (); } - + /** * Checks if this buffer is equal to obj. */ public boolean equals (Object obj) { if (obj instanceof CharBuffer) - return compareTo (obj) == 0; - + { + return compareTo (obj) == 0; + } + return false; } - + /** - * Compares two character buffer objects. - * + * Compares two <code>CharBuffer</code> objects. + * * @exception ClassCastException If obj is not an object derived from * <code>CharBuffer</code>. */ - public int compareTo(Object obj) + public int compareTo (Object obj) { CharBuffer a = (CharBuffer) obj; - + if (a.remaining () != remaining ()) return 1; - - if (! hasArray () || ! a.hasArray ()) - return 1; - + + if (! hasArray () || + ! a.hasArray ()) + { + return 1; + } + int r = remaining (); int i1 = position (); int i2 = a.position (); - + 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; + { + return (int) t; + } } - + return 0; } - + /** - * Relative get method. - * - * @exception BufferUnderflowException If there are no remaining characters - * in this buffer. + * Returns the byte order of this buffer. + */ + public abstract ByteOrder order (); + + /** + * Reads the <code>char</code> at this buffer's current position, + * and then increments the position. + * + * @exception BufferUnderflowException If there are no remaining + * <code>chars</code> in this buffer. */ public abstract char get (); - + /** - * Relative put method. - * - * @exception BufferOverflowException If there no remaining characters in - * this buffer. + * Writes the <code>char</code> at this buffer's current position, + * and then increments the position. + * + * @exception BufferOverflowException If there no remaining + * <code>chars</code> in this buffer. * @exception ReadOnlyBufferException If this buffer is read-only. */ public abstract CharBuffer put (char b); - + /** * Absolute get method. - * + * * @exception IndexOutOfBoundsException If index is negative or not smaller * than the buffer's limit. */ @@ -327,32 +380,40 @@ public abstract class CharBuffer extends Buffer /** * 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 CharBuffer put (int index, char b); - + /** + * Compacts this buffer. + * * @exception ReadOnlyBufferException If this buffer is read-only. */ public abstract CharBuffer compact (); - + /** - * Tells wether this buffer is direct or not. + * Tells wether or not this buffer is direct. */ public abstract boolean isDirect (); - + + /** + * Creates a new <code>CharBuffer</code> whose content is a shared + * subsequence of this buffer's content. + */ public abstract CharBuffer slice (); - + /** - * Duplicates this buffer. + * Creates a new <code>CharBuffer</code> that shares this buffer's + * content. */ public abstract CharBuffer duplicate (); - + /** - * Returns this buffer made read-only. + * Creates a new read-only <code>CharBuffer</code> that shares this + * buffer's content. */ public abstract CharBuffer asReadOnlyBuffer (); @@ -378,11 +439,6 @@ public abstract class CharBuffer extends Buffer } /** - * Returns the byte order of this buffer. - */ - public abstract ByteOrder order (); - - /** * Creates a new character buffer that represents the specified subsequence * of this buffer, relative to the current position. * |