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
28package java.nio;
29
30
31/**
32 * A long buffer.
33 *
34 * <p> This class defines four categories of operations upon
35 * long buffers:
36 *
37 * <ul>
38 *
39 * <li><p> Absolute and relative {@link #get() </code><i>get</i><code>} and
40 * {@link #put(long) </code><i>put</i><code>} methods that read and write
41 * single longs; </p></li>
42 *
43 * <li><p> Relative {@link #get(long[]) </code><i>bulk get</i><code>}
44 * methods that transfer contiguous sequences of longs from this buffer
45 * into an array; and</p></li>
46 *
47 * <li><p> Relative {@link #put(long[]) </code><i>bulk put</i><code>}
48 * methods that transfer contiguous sequences of longs from a
49 * long array or some other long
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 long buffer.  </p></li>
55 *
56 * </ul>
57 *
58 * <p> Long 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(long[]) </code><i>wrapping</i><code>} an existing
61 * long 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 long buffer is either <a
65 * href="ByteBuffer.html#direct"><i>direct</i> or <i>non-direct</i></a>.  A
66 * long buffer created via the <tt>wrap</tt> methods of this class will
67 * be non-direct.  A long 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 long 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
81public abstract class LongBuffer
82        extends Buffer
83        implements Comparable<LongBuffer> {
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 long[] 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    //
96    LongBuffer(int mark, int pos, int lim, int cap,   // package-private
97               long[] hb, int offset) {
98        super(mark, pos, lim, cap, 3);
99        this.hb = hb;
100        this.offset = offset;
101    }
102
103    // Creates a new buffer with the given mark, position, limit, and capacity
104    //
105    LongBuffer(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 long 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 longs
120     * @return The new long buffer
121     * @throws IllegalArgumentException If the <tt>capacity</tt> is a negative integer
122     */
123    public static LongBuffer allocate(int capacity) {
124        if (capacity < 0)
125            throw new IllegalArgumentException();
126        return new HeapLongBuffer(capacity, capacity);
127    }
128
129    /**
130     * Wraps a long array into a buffer.
131     *
132     * <p> The new buffer will be backed by the given long 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 long buffer
149     * @throws IndexOutOfBoundsException If the preconditions on the <tt>offset</tt> and
150     *                                   <tt>length</tt>
151     *                                   parameters do not hold
152     */
153    public static LongBuffer wrap(long[] array,
154                                  int offset, int length) {
155        try {
156            return new HeapLongBuffer(array, offset, length);
157        } catch (IllegalArgumentException x) {
158            throw new IndexOutOfBoundsException();
159        }
160    }
161
162    /**
163     * Wraps a long array into a buffer.
164     *
165     * <p> The new buffer will be backed by the given long 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 long buffer
175     */
176    public static LongBuffer wrap(long[] array) {
177        return wrap(array, 0, array.length);
178    }
179
180
181    /**
182     * Creates a new long 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 longs 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 long buffer
197     */
198    public abstract LongBuffer slice();
199
200    /**
201     * Creates a new long 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 long buffer
214     */
215    public abstract LongBuffer duplicate();
216
217    /**
218     * Creates a new, read-only long 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 long buffer
234     */
235    public abstract LongBuffer asReadOnlyBuffer();
236
237
238    // -- Singleton get/put methods --
239
240    /**
241     * Relative <i>get</i> method.  Reads the long at this buffer's
242     * current position, and then increments the position. </p>
243     *
244     * @return The long at the buffer's current position
245     * @throws BufferUnderflowException If the buffer's current position is not smaller than its
246     *                                  limit
247     */
248    public abstract long get();
249
250    /**
251     * Relative <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
252     *
253     * <p> Writes the given long into this buffer at the current
254     * position, and then increments the position. </p>
255     *
256     * @param l The long 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     */
262    public abstract LongBuffer put(long l);
263
264    /**
265     * Absolute <i>get</i> method.  Reads the long at the given
266     * index. </p>
267     *
268     * @param index The index from which the long will be read
269     * @return The long at the given index
270     * @throws IndexOutOfBoundsException If <tt>index</tt> is negative
271     *                                   or not smaller than the buffer's limit
272     */
273    public abstract long get(int index);
274
275    /**
276     * Absolute <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
277     *
278     * <p> Writes the given long into this buffer at the given
279     * index. </p>
280     *
281     * @param index The index at which the long will be written
282     * @param l     The long 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     */
288    public abstract LongBuffer put(int index, long l);
289
290
291    // -- Bulk get operations --
292
293    /**
294     * Relative bulk <i>get</i> method.
295     *
296     * <p> This method transfers longs from this buffer into the given
297     * destination array.  If there are fewer longs 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     * longs are transferred and a {@link BufferUnderflowException} is
301     * thrown.
302     *
303     * <p> Otherwise, this method copies <tt>length</tt> longs 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 longs in
317     * this buffer and it is potentially much more efficient. </p>
318     *
319     * @param dst    The array into which longs are to be written
320     * @param offset The offset within the array of the first long to be
321     *               written; must be non-negative and no larger than
322     *               <tt>dst.length</tt>
323     * @param length The maximum number of longs 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> longs
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     */
333    public LongBuffer get(long[] 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 longs 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> longs
355     *                                  remaining in this buffer
356     */
357    public LongBuffer get(long[] 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 longs remaining in the given source
368     * buffer into this buffer.  If there are more longs 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 longs 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> longs 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 longs 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 longs in the source buffer
394     * @throws IllegalArgumentException If the source buffer is this buffer
395     * @throws ReadOnlyBufferException  If this buffer is read-only
396     */
397    public LongBuffer put(LongBuffer 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 longs into this buffer from the given
412     * source array.  If there are more longs 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     * longs are transferred and a {@link BufferOverflowException} is
416     * thrown.
417     *
418     * <p> Otherwise, this method copies <tt>length</tt> longs 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 longs are to be read
435     * @param offset The offset within the array of the first long to be read;
436     *               must be non-negative and no larger than <tt>array.length</tt>
437     * @param length The number of longs 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     */
447    public LongBuffer put(long[] 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     * long 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     */
472    public final LongBuffer put(long[] 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 long
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     */
490    public final boolean hasArray() {
491        return (hb != null) && !isReadOnly;
492    }
493
494    /**
495     * Returns the long 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     */
509    public final long[] 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     */
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 longs between the buffer's current position and its limit,
545     * if any, are copied to the beginning of the buffer.  That is, the
546     * long at index <i>p</i>&nbsp;=&nbsp;<tt>position()</tt> is copied
547     * to index zero, the long at index <i>p</i>&nbsp;+&nbsp;1 is copied
548     * to index one, and so forth until the long 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 longs 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     */
562    public abstract LongBuffer compact();
563
564    /**
565     * Tells whether or not this long buffer is direct. </p>
566     *
567     * @return <tt>true</tt> if, and only if, this buffer is direct
568     */
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     */
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 long 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     */
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 long 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     *
628     *
629     *
630     *
631     *
632     *
633     * </p></li>
634     *
635     * </ol>
636     *
637     * <p> A long 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     */
643    public boolean equals(Object ob) {
644        if (this == ob)
645            return true;
646        if (!(ob instanceof LongBuffer))
647            return false;
648        LongBuffer that = (LongBuffer) 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
658    private static boolean equals(long x, long y) {
659
660
661        return x == y;
662
663    }
664
665    /**
666     * Compares this buffer to another.
667     *
668     * <p> Two long 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     *
673     *
674     *
675     *
676     *
677     *
678     *
679     * Pairs of {@code long} elements are compared as if by invoking
680     * {@link Long#compare(long, long)}.
681     *
682     *
683     * <p> A long 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     */
688    public int compareTo(LongBuffer 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
698    private static int compare(long x, long y) {
699
700
701        return Long.compare(x, y);
702
703    }
704
705    // -- Other char stuff --
706
707
708    // -- Other byte stuff: Access to binary data --
709
710
711    /**
712     * Retrieves this buffer's byte order.
713     *
714     * <p> The byte order of a long buffer created by allocation or by
715     * wrapping an existing <tt>long</tt> array is the {@link
716     * ByteOrder#nativeOrder </code>native order<code>} of the underlying
717     * hardware.  The byte order of a long buffer created as a <a
718     * href="ByteBuffer.html#views">view</a> of a byte buffer is that of the
719     * byte buffer at the moment that the view is created.  </p>
720     *
721     * @return This buffer's byte order
722     */
723    public abstract ByteOrder order();
724
725
726}
727