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