/[classpath]/classpath/java/nio/CharBuffer.java
ViewVC logotype

Diff of /classpath/java/nio/CharBuffer.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12 by mkoch, Tue Mar 11 11:48:51 2003 UTC revision 1.13 by mkoch, Sun May 18 11:42:19 2003 UTC
# Line 1  Line 1 
1  /* CharBuffer.java --  /* CharBuffer.java --
2     Copyright (C) 2002 Free Software Foundation, Inc.     Copyright (C) 2002, 2003 Free Software Foundation, Inc.
3    
4  This file is part of GNU Classpath.  This file is part of GNU Classpath.
5    
# Line 55  public abstract class CharBuffer extends Line 55  public abstract class CharBuffer extends
55    {    {
56      return new CharBufferImpl (capacity, 0, capacity);      return new CharBufferImpl (capacity, 0, capacity);
57    }    }
58      
59    /**    /**
60     * Wraps a character array into a <code>CharBuffer</code> object.     * Wraps a <code>char</code> array into a <code>CharBuffer</code>
61     *     * object.
62       *
63     * @exception IndexOutOfBoundsException If the preconditions on the offset     * @exception IndexOutOfBoundsException If the preconditions on the offset
64     * and length parameters do not hold     * and length parameters do not hold
65     */     */
# Line 103  public abstract class CharBuffer extends Line 104  public abstract class CharBuffer extends
104      //return wrap (buffer, offset, length);      //return wrap (buffer, offset, length);
105      return wrap (buffer, offset, length).asReadOnlyBuffer ();      return wrap (buffer, offset, length).asReadOnlyBuffer ();
106    }    }
107      
108    /**    /**
109     * Wraps a character array into a <code>CharBuffer</code> object.     * Wraps a <code>char</code> array into a <code>CharBuffer</code>
110       * object.
111     */     */
112    final public static CharBuffer wrap (char[] array)    final public static CharBuffer wrap (char[] array)
113    {    {
# Line 118  public abstract class CharBuffer extends Line 120  public abstract class CharBuffer extends
120    }    }
121        
122    /**    /**
123     * Relative get method.     * This method transfers <code>chars<code> from this buffer into the given
124     *     * destination array.
125     * @exception BufferUnderflowException If the buffer's current position is     *
126     * not smaller than its limit.     * @param dst The destination array
127       * @param offset The offset within the array of the first <code>char</code>
128       * to be written; must be non-negative and no larger than dst.length.
129       * @param length The maximum number of bytes to be written to the given array;
130       * must be non-negative and no larger than dst.length - offset.
131       *
132       * @exception BufferUnderflowException If there are fewer than length
133       * <code>chars</code> remaining in this buffer.
134     * @exception IndexOutOfBoundsException If the preconditions on the offset     * @exception IndexOutOfBoundsException If the preconditions on the offset
135     * and length parameters do not hold     * and length parameters do not hold.
136     */     */
137    public CharBuffer get (char[] dst, int offset, int length)    public CharBuffer get (char[] dst, int offset, int length)
138    {    {
# Line 131  public abstract class CharBuffer extends Line 140  public abstract class CharBuffer extends
140        {        {
141          dst [i] = get ();          dst [i] = get ();
142        }        }
143        
144      return this;      return this;
145    }    }
146      
147    /**    /**
148     * Relative get method.     * This method transfers <code>chars<code> from this buffer into the given
149     *     * destination array.
150     * @exception BufferUnderflowException If there are fewer than length     *
151     * characters remaining in this buffer.     * @param dst The byte array to write into.
152       *
153       * @exception BufferUnderflowException If there are fewer than dst.length
154       * <code>chars</code> remaining in this buffer.
155     */     */
156    public CharBuffer get (char[] dst)    public CharBuffer get (char[] dst)
157    {    {
158      return get (dst, 0, dst.length);      return get (dst, 0, dst.length);
159    }    }
160      
161    /**    /**
162     * @exception BufferOverflowException If there are fewer than length of     * Writes the content of the the <code>CharBUFFER</code> src
163     * source buffer characters remaining in this buffer.     * into the buffer.
164       *
165       * @param src The source data.
166       *
167       * @exception BufferOverflowException If there is insufficient space in this
168       * buffer for the remaining <code>chars<code> in the source buffer.
169     * @exception IllegalArgumentException If the source buffer is this buffer.     * @exception IllegalArgumentException If the source buffer is this buffer.
170     * @exception ReadOnlyBufferException If this buffer is read-only.     * @exception ReadOnlyBufferException If this buffer is read-only.
171     */     */
# Line 166  public abstract class CharBuffer extends Line 183  public abstract class CharBuffer extends
183    
184      return this;      return this;
185    }    }
186    
187    /**    /**
188     * @exception BufferOverflowException If there are fewer then length     * Writes the content of the the <code>char array</code> src
189     * characters remaining in this buffer.     * into the buffer.
190       *
191       * @param src The array to copy into the buffer.
192       * @param offset The offset within the array of the first byte to be read;
193       * must be non-negative and no larger than src.length.
194       * @param length The number of bytes to be read from the given array;
195       * must be non-negative and no larger than src.length - offset.
196       *
197       * @exception BufferOverflowException If there is insufficient space in this
198       * buffer for the remaining <code>chars<code> in the source array.
199     * @exception IndexOutOfBoundsException If the preconditions on the offset     * @exception IndexOutOfBoundsException If the preconditions on the offset
200     * and length parameters do not hold     * and length parameters do not hold
201     * @exception ReadOnlyBufferException If this buffer is read-only.     * @exception ReadOnlyBufferException If this buffer is read-only.
# Line 187  public abstract class CharBuffer extends Line 213  public abstract class CharBuffer extends
213        throw new BufferOverflowException ();        throw new BufferOverflowException ();
214                                            
215      for (int i = offset; i < offset + length; i++)      for (int i = offset; i < offset + length; i++)
216        {        put (src [i]);
         put (src [i]);  
       }  
217    
218      return this;      return this;
219    }    }
220    
221    /**    /**
222     * Relative put method.     * Writes the content of the the <code>char array</code> src
223       * into the buffer.
224       *
225       * @param src The array to copy into the buffer.
226     *     *
227     * @exception BufferOverflowException If there are fewer then length of the     * @exception BufferOverflowException If there is insufficient space in this
228     * array characters remaining in this buffer.     * buffer for the remaining <code>chars<code> in the source array.
229     * @exception ReadOnlyBufferException If this buffer is read-only.     * @exception ReadOnlyBufferException If this buffer is read-only.
230     */     */
231    public final CharBuffer put (char[] src)    public final CharBuffer put (char[] src)
# Line 207  public abstract class CharBuffer extends Line 234  public abstract class CharBuffer extends
234    }    }
235    
236    /**    /**
237     * Tells wether this is buffer is backed by an accessible array or not.     * Tells whether ot not this buffer is backed by an accessible
238       * <code>char</code> array.
239     */     */
240    public final boolean hasArray ()    public final boolean hasArray ()
241    {    {
242      return (backing_buffer != null      return (backing_buffer != null
243              && ! isReadOnly ());              && !isReadOnly ());
244    }    }
245    
246    /**    /**
247     * Returns the array that backs this buffer.     * Returns the <code>char</code> array that backs this buffer.
248     *     *
249     * @exception ReadOnlyBufferException If this buffer is read-only.     * @exception ReadOnlyBufferException If this buffer is read-only.
250     * @exception UnsupportedOperationException If this buffer is not backed     * @exception UnsupportedOperationException If this buffer is not backed
251     * by an accessible array.     * by an accessible array.
# Line 232  public abstract class CharBuffer extends Line 260  public abstract class CharBuffer extends
260            
261      return backing_buffer;      return backing_buffer;
262    }    }
263      
264    /**    /**
265     * 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.
266     *     *
267     * @exception ReadOnlyBufferException If this buffer is read-only.     * @exception ReadOnlyBufferException If this buffer is read-only.
268     * @exception UnsupportedOperationException If this buffer is not backed     * @exception UnsupportedOperationException If this buffer is not backed
269     * by an accessible array.     * by an accessible array.
# Line 250  public abstract class CharBuffer extends Line 278  public abstract class CharBuffer extends
278            
279      return array_offset;      return array_offset;
280    }    }
281      
282    /**    /**
283     * Calculates a hash code for this buffer-     * Calculates a hash code for this buffer.
284     */     */
285    public int hashCode ()    public int hashCode ()
286    {    {
287      // FIXME: Check what SUN calculates here.      // FIXME: Check what SUN calculates here.
288      return super.hashCode ();      return super.hashCode ();
289    }    }
290      
291    /**    /**
292     * Checks if this buffer is equal to obj.     * Checks if this buffer is equal to obj.
293     */     */
294    public boolean equals (Object obj)    public boolean equals (Object obj)
295    {    {
296      if (obj instanceof CharBuffer)      if (obj instanceof CharBuffer)
297        return compareTo (obj) == 0;        {
298                return compareTo (obj) == 0;
299          }
300    
301      return false;      return false;
302    }    }
303    
304    /**    /**
305     * Compares two character buffer objects.     * Compares two <code>CharBuffer</code> objects.
306     *     *
307     * @exception ClassCastException If obj is not an object derived from     * @exception ClassCastException If obj is not an object derived from
308     * <code>CharBuffer</code>.     * <code>CharBuffer</code>.
309     */     */
310    public int compareTo(Object obj)    public int compareTo (Object obj)
311    {    {
312      CharBuffer a = (CharBuffer) obj;      CharBuffer a = (CharBuffer) obj;
313        
314      if (a.remaining () != remaining ())      if (a.remaining () != remaining ())
315        return 1;        return 1;
316        
317      if (! hasArray () || ! a.hasArray ())      if (! hasArray () ||
318        return 1;          ! a.hasArray ())
319              {
320            return 1;
321          }
322    
323      int r = remaining ();      int r = remaining ();
324      int i1 = position ();      int i1 = position ();
325      int i2 = a.position ();      int i2 = a.position ();
326        
327      for (int i = 0; i < r; i++)      for (int i = 0; i < r; i++)
328        {        {
329          int t = (int) (get (i1)- a.get (i2));          int t = (int) (get (i1) - a.get (i2));
330            
331          if (t != 0)          if (t != 0)
332            return (int) t;            {
333                return (int) t;
334              }
335        }        }
336        
337      return 0;      return 0;
338    }    }
339    
340    /**    /**
341     * Relative get method.     * Reads the <code>char</code> at this buffer's current position,
342     *     * and then increments the position.
343     * @exception BufferUnderflowException If there are no remaining characters     *
344     * in this buffer.     * @exception BufferUnderflowException If there are no remaining
345       * <code>chars</code> in this buffer.
346     */     */
347    public abstract char get ();    public abstract char get ();
348      
349    /**    /**
350     * Relative put method.     * Writes the <code>char</code> at this buffer's current position,
351     *     * and then increments the position.
352     * @exception BufferOverflowException If there no remaining characters in     *
353     * this buffer.     * @exception BufferOverflowException If there no remaining
354       * <code>chars</code> in this buffer.
355     * @exception ReadOnlyBufferException If this buffer is read-only.     * @exception ReadOnlyBufferException If this buffer is read-only.
356     */     */
357    public abstract CharBuffer put (char b);    public abstract CharBuffer put (char b);
358      
359    /**    /**
360     * Absolute get method.     * Absolute get method.
361     *     *
362     * @exception IndexOutOfBoundsException If index is negative or not smaller     * @exception IndexOutOfBoundsException If index is negative or not smaller
363     * than the buffer's limit.     * than the buffer's limit.
364     */     */
# Line 329  public abstract class CharBuffer extends Line 366  public abstract class CharBuffer extends
366        
367    /**    /**
368     * Absolute put method.     * Absolute put method.
369     *     *
370     * @exception IndexOutOfBoundsException If index is negative or not smaller     * @exception IndexOutOfBoundsException If index is negative or not smaller
371     * than the buffer's limit.     * than the buffer's limit.
372     * @exception ReadOnlyBufferException If this buffer is read-only.     * @exception ReadOnlyBufferException If this buffer is read-only.
373     */     */
374    public abstract CharBuffer put (int index, char b);    public abstract CharBuffer put (int index, char b);
375    
376    /**    /**
377       * Compacts this buffer.
378       *
379     * @exception ReadOnlyBufferException If this buffer is read-only.     * @exception ReadOnlyBufferException If this buffer is read-only.
380     */     */
381    public abstract CharBuffer compact ();    public abstract CharBuffer compact ();
382      
383    /**    /**
384     * Tells wether this buffer is direct or not.     * Tells wether or not this buffer is direct.
385     */     */
386    public abstract boolean isDirect ();    public abstract boolean isDirect ();
387      
388      /**
389       * Creates a new <code>CharBuffer</code> whose content is a shared
390       * subsequence of this buffer's content.
391       */
392    public abstract CharBuffer slice ();    public abstract CharBuffer slice ();
393      
394    /**    /**
395     * Duplicates this buffer.     * Creates a new <code>CharBuffer</code> that shares this buffer's
396       * content.
397     */     */
398    public abstract CharBuffer duplicate ();    public abstract CharBuffer duplicate ();
399      
400    /**    /**
401     * Returns this buffer made read-only.     * Creates a new read-only <code>CharBuffer</code> that shares this
402       * buffer's content.
403     */     */
404    public abstract CharBuffer asReadOnlyBuffer ();    public abstract CharBuffer asReadOnlyBuffer ();
405        

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26