1 /*
2  * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 // -- This file was mechanically generated: Do not edit! -- //
27 
28 package java.nio;
29 
30 
31 /**
32  * A float buffer.
33  *
34  * <p> This class defines four categories of operations upon
35  * float buffers:
36  *
37  * <ul>
38  *
39  * <li><p> Absolute and relative {@link #get() </code><i>get</i><code>} and
40  * {@link #put(float) </code><i>put</i><code>} methods that read and write
41  * single floats; </p></li>
42  *
43  * <li><p> Relative {@link #get(float[]) </code><i>bulk get</i><code>}
44  * methods that transfer contiguous sequences of floats from this buffer
45  * into an array; and</p></li>
46  *
47  * <li><p> Relative {@link #put(float[]) </code><i>bulk put</i><code>}
48  * methods that transfer contiguous sequences of floats from a
49  * float array or some other float
50  * buffer into this buffer;&#32;and </p></li>
51  *
52  * <li><p> Methods for {@link #compact </code>compacting<code>}, {@link
53  * #duplicate </code>duplicating<code>}, and {@link #slice
54  * </code>slicing<code>} a float buffer.  </p></li>
55  *
56  * </ul>
57  *
58  * <p> Float buffers can be created either by {@link #allocate
59  * </code><i>allocation</i><code>}, which allocates space for the buffer's
60  * content, by {@link #wrap(float[]) </code><i>wrapping</i><code>} an existing
61  * float array  into a buffer, or by creating a
62  * <a href="ByteBuffer.html#views"><i>view</i></a> of an existing byte buffer.
63  *
64  * <p> Like a byte buffer, a float buffer is either <a
65  * href="ByteBuffer.html#direct"><i>direct</i> or <i>non-direct</i></a>.  A
66  * float buffer created via the <tt>wrap</tt> methods of this class will
67  * be non-direct.  A float buffer created as a view of a byte buffer will
68  * be direct if, and only if, the byte buffer itself is direct.  Whether or not
69  * a float buffer is direct may be determined by invoking the {@link
70  * #isDirect isDirect} method.  </p>
71  *
72  * <p> Methods in this class that do not otherwise have a value to return are
73  * specified to return the buffer upon which they are invoked.  This allows
74  * method invocations to be chained.
75  *
76  * @author Mark Reinhold
77  * @author JSR-51 Expert Group
78  * @since 1.4
79  */
80 
81 public abstract class FloatBuffer
82         extends Buffer
83         implements Comparable<FloatBuffer> {
84 
85     // These fields are declared here rather than in Heap-X-Buffer in order to
86     // reduce the number of virtual method invocations needed to access these
87     // values, which is especially costly when coding small buffers.
88     //
89     final float[] hb;                  // Non-null only for heap buffers
90     final int offset;
91     boolean isReadOnly;                 // Valid only for heap buffers
92 
93     // Creates a new buffer with the given mark, position, limit, capacity,
94     // backing array, and array offset
95     //
FloatBuffer(int mark, int pos, int lim, int cap, float[] hb, int offset)96     FloatBuffer(int mark, int pos, int lim, int cap,   // package-private
97                 float[] hb, int offset) {
98         super(mark, pos, lim, cap, 2);
99         this.hb = hb;
100         this.offset = offset;
101     }
102 
103     // Creates a new buffer with the given mark, position, limit, and capacity
104     //
FloatBuffer(int mark, int pos, int lim, int cap)105     FloatBuffer(int mark, int pos, int lim, int cap) { // package-private
106         this(mark, pos, lim, cap, null, 0);
107     }
108 
109 
110     /**
111      * Allocates a new float buffer.
112      *
113      * <p> The new buffer's position will be zero, its limit will be its
114      * capacity, its mark will be undefined, and each of its elements will be
115      * initialized to zero.  It will have a {@link #array
116      * </code>backing array<code>}, and its {@link #arrayOffset </code>array
117      * offset<code>} will be zero.
118      *
119      * @param capacity The new buffer's capacity, in floats
120      * @return The new float buffer
121      * @throws IllegalArgumentException If the <tt>capacity</tt> is a negative integer
122      */
allocate(int capacity)123     public static FloatBuffer allocate(int capacity) {
124         if (capacity < 0)
125             throw new IllegalArgumentException();
126         return new HeapFloatBuffer(capacity, capacity);
127     }
128 
129     /**
130      * Wraps a float array into a buffer.
131      *
132      * <p> The new buffer will be backed by the given float array;
133      * that is, modifications to the buffer will cause the array to be modified
134      * and vice versa.  The new buffer's capacity will be
135      * <tt>array.length</tt>, its position will be <tt>offset</tt>, its limit
136      * will be <tt>offset + length</tt>, and its mark will be undefined.  Its
137      * {@link #array </code>backing array<code>} will be the given array, and
138      * its {@link #arrayOffset </code>array offset<code>} will be zero.  </p>
139      *
140      * @param array  The array that will back the new buffer
141      * @param offset The offset of the subarray to be used; must be non-negative and
142      *               no larger than <tt>array.length</tt>.  The new buffer's position
143      *               will be set to this value.
144      * @param length The length of the subarray to be used;
145      *               must be non-negative and no larger than
146      *               <tt>array.length - offset</tt>.
147      *               The new buffer's limit will be set to <tt>offset + length</tt>.
148      * @return The new float buffer
149      * @throws IndexOutOfBoundsException If the preconditions on the <tt>offset</tt> and
150      *                                   <tt>length</tt>
151      *                                   parameters do not hold
152      */
wrap(float[] array, int offset, int length)153     public static FloatBuffer wrap(float[] array,
154                                    int offset, int length) {
155         try {
156             return new HeapFloatBuffer(array, offset, length);
157         } catch (IllegalArgumentException x) {
158             throw new IndexOutOfBoundsException();
159         }
160     }
161 
162     /**
163      * Wraps a float array into a buffer.
164      *
165      * <p> The new buffer will be backed by the given float array;
166      * that is, modifications to the buffer will cause the array to be modified
167      * and vice versa.  The new buffer's capacity and limit will be
168      * <tt>array.length</tt>, its position will be zero, and its mark will be
169      * undefined.  Its {@link #array </code>backing array<code>} will be the
170      * given array, and its {@link #arrayOffset </code>array offset<code>} will
171      * be zero.  </p>
172      *
173      * @param array The array that will back this buffer
174      * @return The new float buffer
175      */
wrap(float[] array)176     public static FloatBuffer wrap(float[] array) {
177         return wrap(array, 0, array.length);
178     }
179 
180 
181     /**
182      * Creates a new float buffer whose content is a shared subsequence of
183      * this buffer's content.
184      *
185      * <p> The content of the new buffer will start at this buffer's current
186      * position.  Changes to this buffer's content will be visible in the new
187      * buffer, and vice versa; the two buffers' position, limit, and mark
188      * values will be independent.
189      *
190      * <p> The new buffer's position will be zero, its capacity and its limit
191      * will be the number of floats remaining in this buffer, and its mark
192      * will be undefined.  The new buffer will be direct if, and only if, this
193      * buffer is direct, and it will be read-only if, and only if, this buffer
194      * is read-only.  </p>
195      *
196      * @return The new float buffer
197      */
slice()198     public abstract FloatBuffer slice();
199 
200     /**
201      * Creates a new float buffer that shares this buffer's content.
202      *
203      * <p> The content of the new buffer will be that of this buffer.  Changes
204      * to this buffer's content will be visible in the new buffer, and vice
205      * versa; the two buffers' position, limit, and mark values will be
206      * independent.
207      *
208      * <p> The new buffer's capacity, limit, position, and mark values will be
209      * identical to those of this buffer.  The new buffer will be direct if,
210      * and only if, this buffer is direct, and it will be read-only if, and
211      * only if, this buffer is read-only.  </p>
212      *
213      * @return The new float buffer
214      */
duplicate()215     public abstract FloatBuffer duplicate();
216 
217     /**
218      * Creates a new, read-only float buffer that shares this buffer's
219      * content.
220      *
221      * <p> The content of the new buffer will be that of this buffer.  Changes
222      * to this buffer's content will be visible in the new buffer; the new
223      * buffer itself, however, will be read-only and will not allow the shared
224      * content to be modified.  The two buffers' position, limit, and mark
225      * values will be independent.
226      *
227      * <p> The new buffer's capacity, limit, position, and mark values will be
228      * identical to those of this buffer.
229      *
230      * <p> If this buffer is itself read-only then this method behaves in
231      * exactly the same way as the {@link #duplicate duplicate} method.  </p>
232      *
233      * @return The new, read-only float buffer
234      */
asReadOnlyBuffer()235     public abstract FloatBuffer asReadOnlyBuffer();
236 
237 
238     // -- Singleton get/put methods --
239 
240     /**
241      * Relative <i>get</i> method.  Reads the float at this buffer's
242      * current position, and then increments the position. </p>
243      *
244      * @return The float at the buffer's current position
245      * @throws BufferUnderflowException If the buffer's current position is not smaller than its
246      *                                  limit
247      */
get()248     public abstract float get();
249 
250     /**
251      * Relative <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
252      *
253      * <p> Writes the given float into this buffer at the current
254      * position, and then increments the position. </p>
255      *
256      * @param f The float to be written
257      * @return This buffer
258      * @throws BufferOverflowException If this buffer's current position is not smaller than its
259      *                                 limit
260      * @throws ReadOnlyBufferException If this buffer is read-only
261      */
put(float f)262     public abstract FloatBuffer put(float f);
263 
264     /**
265      * Absolute <i>get</i> method.  Reads the float at the given
266      * index. </p>
267      *
268      * @param index The index from which the float will be read
269      * @return The float at the given index
270      * @throws IndexOutOfBoundsException If <tt>index</tt> is negative
271      *                                   or not smaller than the buffer's limit
272      */
get(int index)273     public abstract float get(int index);
274 
275     /**
276      * Absolute <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
277      *
278      * <p> Writes the given float into this buffer at the given
279      * index. </p>
280      *
281      * @param index The index at which the float will be written
282      * @param f     The float value to be written
283      * @return This buffer
284      * @throws IndexOutOfBoundsException If <tt>index</tt> is negative
285      *                                   or not smaller than the buffer's limit
286      * @throws ReadOnlyBufferException   If this buffer is read-only
287      */
put(int index, float f)288     public abstract FloatBuffer put(int index, float f);
289 
290 
291     // -- Bulk get operations --
292 
293     /**
294      * Relative bulk <i>get</i> method.
295      *
296      * <p> This method transfers floats from this buffer into the given
297      * destination array.  If there are fewer floats remaining in the
298      * buffer than are required to satisfy the request, that is, if
299      * <tt>length</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>, then no
300      * floats are transferred and a {@link BufferUnderflowException} is
301      * thrown.
302      *
303      * <p> Otherwise, this method copies <tt>length</tt> floats from this
304      * buffer into the given array, starting at the current position of this
305      * buffer and at the given offset in the array.  The position of this
306      * buffer is then incremented by <tt>length</tt>.
307      *
308      * <p> In other words, an invocation of this method of the form
309      * <tt>src.get(dst,&nbsp;off,&nbsp;len)</tt> has exactly the same effect as
310      * the loop
311      *
312      * <pre>
313      *     for (int i = off; i < off + len; i++)
314      *         dst[i] = src.get(); </pre>
315      *
316      * except that it first checks that there are sufficient floats in
317      * this buffer and it is potentially much more efficient. </p>
318      *
319      * @param dst    The array into which floats are to be written
320      * @param offset The offset within the array of the first float to be
321      *               written; must be non-negative and no larger than
322      *               <tt>dst.length</tt>
323      * @param length The maximum number of floats to be written to the given
324      *               array; must be non-negative and no larger than
325      *               <tt>dst.length - offset</tt>
326      * @return This buffer
327      * @throws BufferUnderflowException  If there are fewer than <tt>length</tt> floats
328      *                                   remaining in this buffer
329      * @throws IndexOutOfBoundsException If the preconditions on the <tt>offset</tt> and
330      *                                   <tt>length</tt>
331      *                                   parameters do not hold
332      */
get(float[] dst, int offset, int length)333     public FloatBuffer get(float[] dst, int offset, int length) {
334         checkBounds(offset, length, dst.length);
335         if (length > remaining())
336             throw new BufferUnderflowException();
337         int end = offset + length;
338         for (int i = offset; i < end; i++)
339             dst[i] = get();
340         return this;
341     }
342 
343     /**
344      * Relative bulk <i>get</i> method.
345      *
346      * <p> This method transfers floats from this buffer into the given
347      * destination array.  An invocation of this method of the form
348      * <tt>src.get(a)</tt> behaves in exactly the same way as the invocation
349      *
350      * <pre>
351      *     src.get(a, 0, a.length) </pre>
352      *
353      * @return This buffer
354      * @throws BufferUnderflowException If there are fewer than <tt>length</tt> floats
355      *                                  remaining in this buffer
356      */
get(float[] dst)357     public FloatBuffer get(float[] dst) {
358         return get(dst, 0, dst.length);
359     }
360 
361 
362     // -- Bulk put operations --
363 
364     /**
365      * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
366      *
367      * <p> This method transfers the floats remaining in the given source
368      * buffer into this buffer.  If there are more floats remaining in the
369      * source buffer than in this buffer, that is, if
370      * <tt>src.remaining()</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>,
371      * then no floats are transferred and a {@link
372      * BufferOverflowException} is thrown.
373      *
374      * <p> Otherwise, this method copies
375      * <i>n</i>&nbsp;=&nbsp;<tt>src.remaining()</tt> floats from the given
376      * buffer into this buffer, starting at each buffer's current position.
377      * The positions of both buffers are then incremented by <i>n</i>.
378      *
379      * <p> In other words, an invocation of this method of the form
380      * <tt>dst.put(src)</tt> has exactly the same effect as the loop
381      *
382      * <pre>
383      *     while (src.hasRemaining())
384      *         dst.put(src.get()); </pre>
385      *
386      * except that it first checks that there is sufficient space in this
387      * buffer and it is potentially much more efficient. </p>
388      *
389      * @param src The source buffer from which floats are to be read;
390      *            must not be this buffer
391      * @return This buffer
392      * @throws BufferOverflowException  If there is insufficient space in this buffer
393      *                                  for the remaining floats in the source buffer
394      * @throws IllegalArgumentException If the source buffer is this buffer
395      * @throws ReadOnlyBufferException  If this buffer is read-only
396      */
put(FloatBuffer src)397     public FloatBuffer put(FloatBuffer src) {
398         if (src == this)
399             throw new IllegalArgumentException();
400         int n = src.remaining();
401         if (n > remaining())
402             throw new BufferOverflowException();
403         for (int i = 0; i < n; i++)
404             put(src.get());
405         return this;
406     }
407 
408     /**
409      * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
410      *
411      * <p> This method transfers floats into this buffer from the given
412      * source array.  If there are more floats to be copied from the array
413      * than remain in this buffer, that is, if
414      * <tt>length</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>, then no
415      * floats are transferred and a {@link BufferOverflowException} is
416      * thrown.
417      *
418      * <p> Otherwise, this method copies <tt>length</tt> floats from the
419      * given array into this buffer, starting at the given offset in the array
420      * and at the current position of this buffer.  The position of this buffer
421      * is then incremented by <tt>length</tt>.
422      *
423      * <p> In other words, an invocation of this method of the form
424      * <tt>dst.put(src,&nbsp;off,&nbsp;len)</tt> has exactly the same effect as
425      * the loop
426      *
427      * <pre>
428      *     for (int i = off; i < off + len; i++)
429      *         dst.put(a[i]); </pre>
430      *
431      * except that it first checks that there is sufficient space in this
432      * buffer and it is potentially much more efficient. </p>
433      *
434      * @param src    The array from which floats are to be read
435      * @param offset The offset within the array of the first float to be read;
436      *               must be non-negative and no larger than <tt>array.length</tt>
437      * @param length The number of floats to be read from the given array;
438      *               must be non-negative and no larger than
439      *               <tt>array.length - offset</tt>
440      * @return This buffer
441      * @throws BufferOverflowException   If there is insufficient space in this buffer
442      * @throws IndexOutOfBoundsException If the preconditions on the <tt>offset</tt> and
443      *                                   <tt>length</tt>
444      *                                   parameters do not hold
445      * @throws ReadOnlyBufferException   If this buffer is read-only
446      */
put(float[] src, int offset, int length)447     public FloatBuffer put(float[] src, int offset, int length) {
448         checkBounds(offset, length, src.length);
449         if (length > remaining())
450             throw new BufferOverflowException();
451         int end = offset + length;
452         for (int i = offset; i < end; i++)
453             this.put(src[i]);
454         return this;
455     }
456 
457     /**
458      * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
459      *
460      * <p> This method transfers the entire content of the given source
461      * float array into this buffer.  An invocation of this method of the
462      * form <tt>dst.put(a)</tt> behaves in exactly the same way as the
463      * invocation
464      *
465      * <pre>
466      *     dst.put(a, 0, a.length) </pre>
467      *
468      * @return This buffer
469      * @throws BufferOverflowException If there is insufficient space in this buffer
470      * @throws ReadOnlyBufferException If this buffer is read-only
471      */
put(float[] src)472     public final FloatBuffer put(float[] src) {
473         return put(src, 0, src.length);
474     }
475 
476 
477     // -- Other stuff --
478 
479     /**
480      * Tells whether or not this buffer is backed by an accessible float
481      * array.
482      *
483      * <p> If this method returns <tt>true</tt> then the {@link #array() array}
484      * and {@link #arrayOffset() arrayOffset} methods may safely be invoked.
485      * </p>
486      *
487      * @return <tt>true</tt> if, and only if, this buffer
488      * is backed by an array and is not read-only
489      */
hasArray()490     public final boolean hasArray() {
491         return (hb != null) && !isReadOnly;
492     }
493 
494     /**
495      * Returns the float array that backs this
496      * buffer&nbsp;&nbsp;<i>(optional operation)</i>.
497      *
498      * <p> Modifications to this buffer's content will cause the returned
499      * array's content to be modified, and vice versa.
500      *
501      * <p> Invoke the {@link #hasArray hasArray} method before invoking this
502      * method in order to ensure that this buffer has an accessible backing
503      * array.  </p>
504      *
505      * @return The array that backs this buffer
506      * @throws ReadOnlyBufferException       If this buffer is backed by an array but is read-only
507      * @throws UnsupportedOperationException If this buffer is not backed by an accessible array
508      */
array()509     public final float[] array() {
510         if (hb == null)
511             throw new UnsupportedOperationException();
512         if (isReadOnly)
513             throw new ReadOnlyBufferException();
514         return hb;
515     }
516 
517     /**
518      * Returns the offset within this buffer's backing array of the first
519      * element of the buffer&nbsp;&nbsp;<i>(optional operation)</i>.
520      *
521      * <p> If this buffer is backed by an array then buffer position <i>p</i>
522      * corresponds to array index <i>p</i>&nbsp;+&nbsp;<tt>arrayOffset()</tt>.
523      *
524      * <p> Invoke the {@link #hasArray hasArray} method before invoking this
525      * method in order to ensure that this buffer has an accessible backing
526      * array.  </p>
527      *
528      * @return The offset within this buffer's array
529      * of the first element of the buffer
530      * @throws ReadOnlyBufferException       If this buffer is backed by an array but is read-only
531      * @throws UnsupportedOperationException If this buffer is not backed by an accessible array
532      */
arrayOffset()533     public final int arrayOffset() {
534         if (hb == null)
535             throw new UnsupportedOperationException();
536         if (isReadOnly)
537             throw new ReadOnlyBufferException();
538         return offset;
539     }
540 
541     /**
542      * Compacts this buffer&nbsp;&nbsp;<i>(optional operation)</i>.
543      *
544      * <p> The floats between the buffer's current position and its limit,
545      * if any, are copied to the beginning of the buffer.  That is, the
546      * float at index <i>p</i>&nbsp;=&nbsp;<tt>position()</tt> is copied
547      * to index zero, the float at index <i>p</i>&nbsp;+&nbsp;1 is copied
548      * to index one, and so forth until the float at index
549      * <tt>limit()</tt>&nbsp;-&nbsp;1 is copied to index
550      * <i>n</i>&nbsp;=&nbsp;<tt>limit()</tt>&nbsp;-&nbsp;<tt>1</tt>&nbsp;-&nbsp;<i>p</i>.
551      * The buffer's position is then set to <i>n+1</i> and its limit is set to
552      * its capacity.  The mark, if defined, is discarded.
553      *
554      * <p> The buffer's position is set to the number of floats copied,
555      * rather than to zero, so that an invocation of this method can be
556      * followed immediately by an invocation of another relative <i>put</i>
557      * method. </p>
558      *
559      * @return This buffer
560      * @throws ReadOnlyBufferException If this buffer is read-only
561      */
compact()562     public abstract FloatBuffer compact();
563 
564     /**
565      * Tells whether or not this float buffer is direct. </p>
566      *
567      * @return <tt>true</tt> if, and only if, this buffer is direct
568      */
isDirect()569     public abstract boolean isDirect();
570 
571 
572     /**
573      * Returns a string summarizing the state of this buffer.  </p>
574      *
575      * @return A summary string
576      */
toString()577     public String toString() {
578         StringBuffer sb = new StringBuffer();
579         sb.append(getClass().getName());
580         sb.append("[pos=");
581         sb.append(position());
582         sb.append(" lim=");
583         sb.append(limit());
584         sb.append(" cap=");
585         sb.append(capacity());
586         sb.append("]");
587         return sb.toString();
588     }
589 
590 
591     /**
592      * Returns the current hash code of this buffer.
593      *
594      * <p> The hash code of a float buffer depends only upon its remaining
595      * elements; that is, upon the elements from <tt>position()</tt> up to, and
596      * including, the element at <tt>limit()</tt>&nbsp;-&nbsp;<tt>1</tt>.
597      *
598      * <p> Because buffer hash codes are content-dependent, it is inadvisable
599      * to use buffers as keys in hash maps or similar data structures unless it
600      * is known that their contents will not change.  </p>
601      *
602      * @return The current hash code of this buffer
603      */
hashCode()604     public int hashCode() {
605         int h = 1;
606         int p = position();
607         for (int i = limit() - 1; i >= p; i--)
608             h = 31 * h + (int) get(i);
609         return h;
610     }
611 
612     /**
613      * Tells whether or not this buffer is equal to another object.
614      *
615      * <p> Two float buffers are equal if, and only if,
616      *
617      * <p><ol>
618      *
619      * <li><p> They have the same element type,  </p></li>
620      *
621      * <li><p> They have the same number of remaining elements, and
622      * </p></li>
623      *
624      * <li><p> The two sequences of remaining elements, considered
625      * independently of their starting positions, are pointwise equal.
626      *
627      * This method considers two float elements {@code a} and {@code b}
628      * to be equal if
629      * {@code (a == b) || (Float.isNaN(a) && Float.isNaN(b))}.
630      * The values {@code -0.0} and {@code +0.0} are considered to be
631      * equal, unlike {@link Float#equals(Object)}.
632      *
633      * </p></li>
634      *
635      * </ol>
636      *
637      * <p> A float buffer is not equal to any other type of object.  </p>
638      *
639      * @param ob The object to which this buffer is to be compared
640      * @return <tt>true</tt> if, and only if, this buffer is equal to the
641      * given object
642      */
equals(Object ob)643     public boolean equals(Object ob) {
644         if (this == ob)
645             return true;
646         if (!(ob instanceof FloatBuffer))
647             return false;
648         FloatBuffer that = (FloatBuffer) ob;
649         if (this.remaining() != that.remaining())
650             return false;
651         int p = this.position();
652         for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--)
653             if (!equals(this.get(i), that.get(j)))
654                 return false;
655         return true;
656     }
657 
equals(float x, float y)658     private static boolean equals(float x, float y) {
659 
660         return (x == y) || (Float.isNaN(x) && Float.isNaN(y));
661 
662 
663     }
664 
665     /**
666      * Compares this buffer to another.
667      *
668      * <p> Two float buffers are compared by comparing their sequences of
669      * remaining elements lexicographically, without regard to the starting
670      * position of each sequence within its corresponding buffer.
671      *
672      * Pairs of {@code float} elements are compared as if by invoking
673      * {@link Float#compare(float, float)}, except that
674      * {@code -0.0} and {@code 0.0} are considered to be equal.
675      * {@code Float.NaN} is considered by this method to be equal
676      * to itself and greater than all other {@code float} values
677      * (including {@code Float.POSITIVE_INFINITY}).
678      *
679      *
680      *
681      *
682      *
683      * <p> A float buffer is not comparable to any other type of object.
684      *
685      * @return A negative integer, zero, or a positive integer as this buffer
686      * is less than, equal to, or greater than the given buffer
687      */
compareTo(FloatBuffer that)688     public int compareTo(FloatBuffer that) {
689         int n = this.position() + Math.min(this.remaining(), that.remaining());
690         for (int i = this.position(), j = that.position(); i < n; i++, j++) {
691             int cmp = compare(this.get(i), that.get(j));
692             if (cmp != 0)
693                 return cmp;
694         }
695         return this.remaining() - that.remaining();
696     }
697 
compare(float x, float y)698     private static int compare(float x, float y) {
699 
700         return ((x < y) ? -1 :
701                 (x > y) ? +1 :
702                         (x == y) ? 0 :
703                                 Float.isNaN(x) ? (Float.isNaN(y) ? 0 : +1) : -1);
704 
705 
706     }
707 
708     /**
709      * Retrieves this buffer's byte order.
710      *
711      * <p> The byte order of a float buffer created by allocation or by
712      * wrapping an existing <tt>float</tt> array is the {@link
713      * ByteOrder#nativeOrder </code>native order<code>} of the underlying
714      * hardware.  The byte order of a float buffer created as a <a
715      * href="ByteBuffer.html#views">view</a> of a byte buffer is that of the
716      * byte buffer at the moment that the view is created.  </p>
717      *
718      * @return This buffer's byte order
719      */
order()720     public abstract ByteOrder order();
721 
722 
723 }
724