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

Diff of /classpath/java/nio/ShortBuffer.java

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

revision 1.8 by mkoch, Tue Mar 11 11:48:51 2003 UTC revision 1.9 by mkoch, Sun May 18 11:42:19 2003 UTC
# Line 1  Line 1 
1  /* ShortBuffer.java --  /* ShortBuffer.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 39  package java.nio; Line 39  package java.nio;
39    
40  import gnu.java.nio.ShortBufferImpl;  import gnu.java.nio.ShortBufferImpl;
41    
42  public abstract class ShortBuffer extends Buffer implements Comparable  /**
43     * @since 1.4
44     */
45    public abstract class ShortBuffer extends Buffer
46      implements Comparable
47  {  {
48    protected short [] backing_buffer;    protected short [] backing_buffer;
49    protected int array_offset;    protected int array_offset;
# Line 72  public abstract class ShortBuffer extend Line 76  public abstract class ShortBuffer extend
76      return wrap(buffer, 0, len);      return wrap(buffer, 0, len);
77    }    }
78    
79    final public static ShortBuffer wrap(short[] array)    /**
80       * Wraps a <code>short</code> array into a <code>ShortBuffer</code>
81       * object.
82       */
83      final public static ShortBuffer wrap (short[] array)
84    {    {
85      return wrap(array, 0, array.length);      return wrap (array, 0, array.length);
86    }    }
87    
88    protected ShortBuffer (int capacity, int limit, int position, int mark)    protected ShortBuffer (int capacity, int limit, int position, int mark)
# Line 83  public abstract class ShortBuffer extend Line 91  public abstract class ShortBuffer extend
91      array_offset = 0;      array_offset = 0;
92    }    }
93        
94      /**
95       * This method transfers <code>shorts<code> from this buffer into the given
96       * destination array.
97       *
98       * @param dst The destination array
99       * @param offset The offset within the array of the first <code>short</code>
100       * to be written; must be non-negative and no larger than dst.length.
101       * @param length The maximum number of bytes to be written to the given array;
102       * must be non-negative and no larger than dst.length - offset.
103       *
104       * @exception BufferUnderflowException If there are fewer than length
105       * <code>shorts</code> remaining in this buffer.
106       * @exception IndexOutOfBoundsException If the preconditions on the offset
107       * and length parameters do not hold.
108       */
109    public ShortBuffer get (short[] dst, int offset, int length)    public ShortBuffer get (short[] dst, int offset, int length)
110    {    {
111      for (int i = offset; i < offset + length; i++)      for (int i = offset; i < offset + length; i++)
112        {        {
113          dst[i] = get();          dst [i] = get ();
114        }        }
115    
116      return this;      return this;
117    }    }
118    
119      /**
120       * This method transfers <code>shorts<code> from this buffer into the given
121       * destination array.
122       *
123       * @param dst The byte array to write into.
124       *
125       * @exception BufferUnderflowException If there are fewer than dst.length
126       * <code>shorts</code> remaining in this buffer.
127       */
128    public ShortBuffer get (short[] dst)    public ShortBuffer get (short[] dst)
129    {    {
130      return get(dst, 0, dst.length);      return get (dst, 0, dst.length);
131    }    }
132    
133      /**
134       * Writes the content of the the <code>ShortBUFFER</code> src
135       * into the buffer.
136       *
137       * @param src The source data.
138       *
139       * @exception BufferOverflowException If there is insufficient space in this
140       * buffer for the remaining <code>shorts<code> in the source buffer.
141       * @exception IllegalArgumentException If the source buffer is this buffer.
142       * @exception ReadOnlyBufferException If this buffer is read-only.
143       */
144    public ShortBuffer put (ShortBuffer src)    public ShortBuffer put (ShortBuffer src)
145    {    {
146      while (src.hasRemaining())      while (src.hasRemaining())
# Line 106  public abstract class ShortBuffer extend Line 149  public abstract class ShortBuffer extend
149      return this;      return this;
150    }    }
151    
152      /**
153       * Writes the content of the the <code>short array</code> src
154       * into the buffer.
155       *
156       * @param src The array to copy into the buffer.
157       * @param offset The offset within the array of the first byte to be read;
158       * must be non-negative and no larger than src.length.
159       * @param length The number of bytes to be read from the given array;
160       * must be non-negative and no larger than src.length - offset.
161       *
162       * @exception BufferOverflowException If there is insufficient space in this
163       * buffer for the remaining <code>shorts<code> in the source array.
164       * @exception IndexOutOfBoundsException If the preconditions on the offset
165       * and length parameters do not hold
166       * @exception ReadOnlyBufferException If this buffer is read-only.
167       */
168    public ShortBuffer put (short[] src, int offset, int length)    public ShortBuffer put (short[] src, int offset, int length)
169    {    {
170      for (int i = offset; i < offset + length; i++)      for (int i = offset; i < offset + length; i++)
171        put(src[i]);        put (src [i]);
172    
173      return this;      return this;
174    }    }
175    
176    public final ShortBuffer put(short[] src)    /**
177    {     * Writes the content of the the <code>short array</code> src
178      return put(src, 0, src.length);     * into the buffer.
179    }     *
180       * @param src The array to copy into the buffer.
181    public final boolean hasArray()     *
182       * @exception BufferOverflowException If there is insufficient space in this
183       * buffer for the remaining <code>shorts<code> in the source array.
184       * @exception ReadOnlyBufferException If this buffer is read-only.
185       */
186      public final ShortBuffer put (short[] src)
187      {
188        return put (src, 0, src.length);
189      }
190    
191      /**
192       * Tells whether ot not this buffer is backed by an accessible
193       * <code>short</code> array.
194       */
195      public final boolean hasArray ()
196    {    {
197      return (backing_buffer != null      return (backing_buffer != null
198              && !isReadOnly ());              && !isReadOnly ());
199    }    }
200    
201    public final short[] array()    /**
202       * Returns the <code>short</code> array that backs this buffer.
203       *
204       * @exception ReadOnlyBufferException If this buffer is read-only.
205       * @exception UnsupportedOperationException If this buffer is not backed
206       * by an accessible array.
207       */
208      public final short[] array ()
209    {    {
210      if (backing_buffer == null)      if (backing_buffer == null)
211        throw new UnsupportedOperationException ();        throw new UnsupportedOperationException ();
# Line 136  public abstract class ShortBuffer extend Line 216  public abstract class ShortBuffer extend
216      return backing_buffer;      return backing_buffer;
217    }    }
218    
219    public final int arrayOffset()    /**
220       * Returns the offset within this buffer's backing array of the first element.
221       *
222       * @exception ReadOnlyBufferException If this buffer is read-only.
223       * @exception UnsupportedOperationException If this buffer is not backed
224       * by an accessible array.
225       */
226      public final int arrayOffset ()
227    {    {
228      if (backing_buffer == null)      if (backing_buffer == null)
229        throw new UnsupportedOperationException ();        throw new UnsupportedOperationException ();
# Line 147  public abstract class ShortBuffer extend Line 234  public abstract class ShortBuffer extend
234      return array_offset;      return array_offset;
235    }    }
236    
237    public int hashCode()    /**
238    {     * Calculates a hash code for this buffer.
239      return super.hashCode();     */
240      public int hashCode ()
241      {
242        // FIXME: Check what SUN calculates here.
243        return super.hashCode ();
244    }    }
245    
246    public boolean equals(Object obj)    /**
247       * Checks if this buffer is equal to obj.
248       */
249      public boolean equals (Object obj)
250    {    {
251      if (obj instanceof ShortBuffer)      if (obj instanceof ShortBuffer)
252        {        {
253          return compareTo(obj) == 0;          return compareTo (obj) == 0;
254        }        }
255    
256      return false;      return false;
257    }    }
258    
259    public int compareTo(Object ob)    /**
260       * Compares two <code>ShortBuffer</code> objects.
261       *
262       * @exception ClassCastException If obj is not an object derived from
263       * <code>ShortBuffer</code>.
264       */
265      public int compareTo (Object obj)
266    {    {
267      ShortBuffer a = (ShortBuffer) ob;      ShortBuffer a = (ShortBuffer) obj;
268    
269      if (a.remaining() != remaining())      if (a.remaining () != remaining ())
270        return 1;        return 1;
271    
272      if (! hasArray() ||      if (! hasArray () ||
273          ! a.hasArray())          ! a.hasArray ())
274        {        {
275          return 1;          return 1;
276        }        }
277    
278      int r = remaining();      int r = remaining ();
279      int i1 = position ();      int i1 = position ();
280      int i2 = a.position ();      int i2 = a.position ();
281    
282      for (int i=0;i<r;i++)      for (int i = 0; i < r; i++)
283        {        {
284          int t = (int) (get(i1)- a.get(i2));          int t = (int) (get (i1) - a.get (i2));
285    
286          if (t != 0)          if (t != 0)
287            {            {
# Line 192  public abstract class ShortBuffer extend Line 292  public abstract class ShortBuffer extend
292      return 0;      return 0;
293    }    }
294    
295      /**
296       * Returns the byte order of this buffer.
297       */
298    public abstract ByteOrder order ();    public abstract ByteOrder order ();
299    public abstract short get();    public abstract short get();
300    public abstract java.nio. ShortBuffer put(short b);    public abstract java.nio. ShortBuffer put(short b);

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

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