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