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

Diff of /classpath/java/nio/DoubleBuffer.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  /* DoubleBuffer.java --  /* DoubleBuffer.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.DoubleBufferImpl;  import gnu.java.nio.DoubleBufferImpl;
41    
42  public abstract class DoubleBuffer extends Buffer implements Comparable  /**
43     * @since 1.4
44     */
45    public abstract class DoubleBuffer extends Buffer
46      implements Comparable
47  {  {
48    protected double [] backing_buffer;    protected double [] backing_buffer;
49    protected int array_offset;    protected int array_offset;
# Line 72  public abstract class DoubleBuffer exten Line 76  public abstract class DoubleBuffer exten
76      return wrap(buffer, 0, len);      return wrap(buffer, 0, len);
77    }    }
78    
79    final public static DoubleBuffer wrap(double[] array)    /**
80       * Wraps a <code>double</code> array into a <code>DoubleBuffer</code>
81       * object.
82       */
83      final public static DoubleBuffer wrap (double[] array)
84    {    {
85      return wrap(array, 0, array.length);      return wrap (array, 0, array.length);
86    }    }
87    
88    protected DoubleBuffer (int capacity, int limit, int position, int mark)    protected DoubleBuffer (int capacity, int limit, int position, int mark)
# Line 82  public abstract class DoubleBuffer exten Line 90  public abstract class DoubleBuffer exten
90      super (capacity, limit, position, mark);      super (capacity, limit, position, mark);
91    }    }
92        
93      /**
94       * This method transfers <code>doubles<code> from this buffer into the given
95       * destination array.
96       *
97       * @param dst The destination array
98       * @param offset The offset within the array of the first <code>double</code>
99       * to be written; must be non-negative and no larger than dst.length.
100       * @param length The maximum number of bytes to be written to the given array;
101       * must be non-negative and no larger than dst.length - offset.
102       *
103       * @exception BufferUnderflowException If there are fewer than length
104       * <code>doubles</code> remaining in this buffer.
105       * @exception IndexOutOfBoundsException If the preconditions on the offset
106       * and length parameters do not hold.
107       */
108    public DoubleBuffer get (double[] dst, int offset, int length)    public DoubleBuffer get (double[] dst, int offset, int length)
109    {    {
110      for (int i = offset; i < offset + length; i++)      for (int i = offset; i < offset + length; i++)
111        {        {
112          dst[i] = get();          dst [i] = get ();
113        }        }
114    
115      return this;      return this;
116    }    }
117    
118      /**
119       * This method transfers <code>doubles<code> from this buffer into the given
120       * destination array.
121       *
122       * @param dst The byte array to write into.
123       *
124       * @exception BufferUnderflowException If there are fewer than dst.length
125       * <code>doubles</code> remaining in this buffer.
126       */
127    public DoubleBuffer get (double[] dst)    public DoubleBuffer get (double[] dst)
128    {    {
129      return get(dst, 0, dst.length);      return get (dst, 0, dst.length);
130    }    }
131    
132      /**
133       * Writes the content of the the <code>DoubleBUFFER</code> src
134       * into the buffer.
135       *
136       * @param src The source data.
137       *
138       * @exception BufferOverflowException If there is insufficient space in this
139       * buffer for the remaining <code>doubles<code> in the source buffer.
140       * @exception IllegalArgumentException If the source buffer is this buffer.
141       * @exception ReadOnlyBufferException If this buffer is read-only.
142       */
143    public DoubleBuffer put (DoubleBuffer src)    public DoubleBuffer put (DoubleBuffer src)
144    {    {
145      while (src.hasRemaining())      while (src.hasRemaining())
# Line 105  public abstract class DoubleBuffer exten Line 148  public abstract class DoubleBuffer exten
148      return this;      return this;
149    }    }
150    
151      /**
152       * Writes the content of the the <code>double array</code> src
153       * into the buffer.
154       *
155       * @param src The array to copy into the buffer.
156       * @param offset The offset within the array of the first byte to be read;
157       * must be non-negative and no larger than src.length.
158       * @param length The number of bytes to be read from the given array;
159       * must be non-negative and no larger than src.length - offset.
160       *
161       * @exception BufferOverflowException If there is insufficient space in this
162       * buffer for the remaining <code>doubles<code> in the source array.
163       * @exception IndexOutOfBoundsException If the preconditions on the offset
164       * and length parameters do not hold
165       * @exception ReadOnlyBufferException If this buffer is read-only.
166       */
167    public DoubleBuffer put (double[] src, int offset, int length)    public DoubleBuffer put (double[] src, int offset, int length)
168    {    {
169      for (int i = offset; i < offset + length; i++)      for (int i = offset; i < offset + length; i++)
170        put(src[i]);        put (src [i]);
171    
172      return this;      return this;
173    }    }
174    
175    public final DoubleBuffer put(double[] src)    /**
176    {     * Writes the content of the the <code>double array</code> src
177      return put(src, 0, src.length);     * into the buffer.
178    }     *
179       * @param src The array to copy into the buffer.
180    public final boolean hasArray()     *
181       * @exception BufferOverflowException If there is insufficient space in this
182       * buffer for the remaining <code>doubles<code> in the source array.
183       * @exception ReadOnlyBufferException If this buffer is read-only.
184       */
185      public final DoubleBuffer put (double[] src)
186      {
187        return put (src, 0, src.length);
188      }
189    
190      /**
191       * Tells whether ot not this buffer is backed by an accessible
192       * <code>double</code> array.
193       */
194      public final boolean hasArray ()
195    {    {
196      return (backing_buffer != null      return (backing_buffer != null
197              && !isReadOnly ());              && !isReadOnly ());
198    }    }
199    
200    public final double[] array()    /**
201       * Returns the <code>double</code> array that backs this buffer.
202       *
203       * @exception ReadOnlyBufferException If this buffer is read-only.
204       * @exception UnsupportedOperationException If this buffer is not backed
205       * by an accessible array.
206       */
207      public final double[] array ()
208    {    {
209      if (backing_buffer == null)      if (backing_buffer == null)
210        throw new UnsupportedOperationException ();        throw new UnsupportedOperationException ();
# Line 135  public abstract class DoubleBuffer exten Line 215  public abstract class DoubleBuffer exten
215      return backing_buffer;      return backing_buffer;
216    }    }
217    
218    public final int arrayOffset()    /**
219       * Returns the offset within this buffer's backing array of the first element.
220       *
221       * @exception ReadOnlyBufferException If this buffer is read-only.
222       * @exception UnsupportedOperationException If this buffer is not backed
223       * by an accessible array.
224       */
225      public final int arrayOffset ()
226    {    {
227      if (backing_buffer == null)      if (backing_buffer == null)
228        throw new UnsupportedOperationException ();        throw new UnsupportedOperationException ();
# Line 146  public abstract class DoubleBuffer exten Line 233  public abstract class DoubleBuffer exten
233      return array_offset;      return array_offset;
234    }    }
235    
236    public int hashCode()    /**
237    {     * Calculates a hash code for this buffer.
238      return super.hashCode();     */
239      public int hashCode ()
240      {
241        // FIXME: Check what SUN calculates here.
242        return super.hashCode ();
243    }    }
244    
245    public boolean equals(Object obj)    /**
246       * Checks if this buffer is equal to obj.
247       */
248      public boolean equals (Object obj)
249    {    {
250      if (obj instanceof DoubleBuffer)      if (obj instanceof DoubleBuffer)
251        {        {
252          return compareTo(obj) == 0;          return compareTo (obj) == 0;
253        }        }
254    
255      return false;      return false;
256    }    }
257    
258    public int compareTo(Object ob)    /**
259       * Compares two <code>DoubleBuffer</code> objects.
260       *
261       * @exception ClassCastException If obj is not an object derived from
262       * <code>DoubleBuffer</code>.
263       */
264      public int compareTo (Object obj)
265    {    {
266      DoubleBuffer a = (DoubleBuffer) ob;      DoubleBuffer a = (DoubleBuffer) obj;
267    
268      if (a.remaining() != remaining())      if (a.remaining () != remaining ())
269        return 1;        return 1;
270    
271      if (! hasArray() ||      if (! hasArray () ||
272          ! a.hasArray())          ! a.hasArray ())
273        {        {
274          return 1;          return 1;
275        }        }
276    
277      int r = remaining();      int r = remaining ();
278      int i1 = position ();      int i1 = position ();
279      int i2 = a.position ();      int i2 = a.position ();
280    
281      for (int i=0;i<r;i++)      for (int i = 0; i < r; i++)
282        {        {
283          int t = (int) (get(i1)- a.get(i2));          int t = (int) (get (i1) - a.get (i2));
284    
285          if (t != 0)          if (t != 0)
286            {            {
287              return (int) t;              return (int) t;
# Line 190  public abstract class DoubleBuffer exten Line 291  public abstract class DoubleBuffer exten
291      return 0;      return 0;
292    }    }
293    
294      /**
295       * Returns the byte order of this buffer.
296       */
297    public abstract ByteOrder order ();    public abstract ByteOrder order ();
298    public abstract double get();  
299      /**
300       * Reads the <code>double</code> at this buffer's current position,
301       * and then increments the position.
302       *
303       * @exception BufferUnderflowException If there are no remaining
304       * <code>doubles</code> in this buffer.
305       */
306      public abstract double get ();
307    
308      /**
309       * Writes the <code>double</code> at this buffer's current position,
310       * and then increments the position.
311       *
312       * @exception BufferOverflowException If there no remaining
313       * <code>doubles</code> in this buffer.
314       * @exception ReadOnlyBufferException If this buffer is read-only.
315       */
316    public abstract DoubleBuffer put (double b);    public abstract DoubleBuffer put (double b);
317    public abstract double get(int index);  
318    public abstract DoubleBuffer put(int index, double b);    /**
319    public abstract DoubleBuffer compact();     * Absolute get method.
320    public abstract boolean isDirect();     *
321    public abstract DoubleBuffer slice();     * @exception IndexOutOfBoundsException If index is negative or not smaller
322    public abstract DoubleBuffer duplicate();     * than the buffer's limit.
323    public abstract DoubleBuffer asReadOnlyBuffer();     */
324      public abstract double get (int index);
325      
326      /**
327       * Absolute put method.
328       *
329       * @exception IndexOutOfBoundsException If index is negative or not smaller
330       * than the buffer's limit.
331       * @exception ReadOnlyBufferException If this buffer is read-only.
332       */
333      public abstract DoubleBuffer put (int index, double b);
334    
335      /**
336       * Compacts this buffer.
337       *
338       * @exception ReadOnlyBufferException If this buffer is read-only.
339       */
340      public abstract DoubleBuffer compact ();
341    
342      /**
343       * Tells wether or not this buffer is direct.
344       */
345      public abstract boolean isDirect ();
346    
347      /**
348       * Creates a new <code>DoubleBuffer</code> whose content is a shared
349       * subsequence of this buffer's content.
350       */
351      public abstract DoubleBuffer slice ();
352    
353      /**
354       * Creates a new <code>DoubleBuffer</code> that shares this buffer's
355       * content.
356       */
357      public abstract DoubleBuffer duplicate ();
358    
359      /**
360       * Creates a new read-only <code>DoubleBuffer</code> that shares this
361       * buffer's content.
362       */
363      public abstract DoubleBuffer asReadOnlyBuffer ();
364  }  }

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