1dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski/*
20d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
3dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski *
5dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * This code is free software; you can redistribute it and/or modify it
6dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * under the terms of the GNU General Public License version 2 only, as
7dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * published by the Free Software Foundation.  Oracle designates this
8dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * particular file as subject to the "Classpath" exception as provided
9dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * by Oracle in the LICENSE file that accompanied this code.
10dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski *
11dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * This code is distributed in the hope that it will be useful, but WITHOUT
12dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * version 2 for more details (a copy is included in the LICENSE file that
15dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * accompanied this code).
16dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski *
17dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * You should have received a copy of the GNU General Public License version
18dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 2 along with this work; if not, write to the Free Software Foundation,
19dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski *
21dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * or visit www.oracle.com if you need additional information or have any
23dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * questions.
24dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */
25dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
26dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski// -- This file was mechanically generated: Do not edit! -- //
27dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
28dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebskipackage java.nio;
29dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
30dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
31dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski/**
32dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * A double buffer.
33dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski *
34dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> This class defines four categories of operations upon
35dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * double buffers:
36dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski *
37dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <ul>
38dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski *
390d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *   <li><p> Absolute and relative {@link #get() <i>get</i>} and
400d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *   {@link #put(double) <i>put</i>} methods that read and write
410d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *   single doubles; </p></li>
42dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski *
430d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *   <li><p> Relative {@link #get(double[]) <i>bulk get</i>}
440d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *   methods that transfer contiguous sequences of doubles from this buffer
450d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *   into an array; and</p></li>
46dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski *
470d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *   <li><p> Relative {@link #put(double[]) <i>bulk put</i>}
480d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *   methods that transfer contiguous sequences of doubles from a
490d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *   double array or some other double
500d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *   buffer into this buffer;&#32;and </p></li>
510d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *
520d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *
530d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *   <li><p> Methods for {@link #compact compacting}, {@link
540d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *   #duplicate duplicating}, and {@link #slice slicing}
550d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *   a double buffer.  </p></li>
56dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski *
57dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * </ul>
58dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski *
59dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> Double buffers can be created either by {@link #allocate
600d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * <i>allocation</i>}, which allocates space for the buffer's
610d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *
620d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *
630d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * content, by {@link #wrap(double[]) <i>wrapping</i>} an existing
64dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * double array  into a buffer, or by creating a
65dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <a href="ByteBuffer.html#views"><i>view</i></a> of an existing byte buffer.
66dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski *
670d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *
680d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer*
690d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *
70dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> Like a byte buffer, a double buffer is either <a
71dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * href="ByteBuffer.html#direct"><i>direct</i> or <i>non-direct</i></a>.  A
72dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * double buffer created via the <tt>wrap</tt> methods of this class will
73dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * be non-direct.  A double buffer created as a view of a byte buffer will
74dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * be direct if, and only if, the byte buffer itself is direct.  Whether or not
75dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * a double buffer is direct may be determined by invoking the {@link
76dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * #isDirect isDirect} method.  </p>
77dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski *
780d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer*
790d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *
800d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *
81dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> Methods in this class that do not otherwise have a value to return are
82dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * specified to return the buffer upon which they are invoked.  This allows
83dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * method invocations to be chained.
84dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski *
850d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *
860d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer *
87dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * @author Mark Reinhold
88dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * @author JSR-51 Expert Group
89dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * @since 1.4
90dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */
91dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
92dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebskipublic abstract class DoubleBuffer
930d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer    extends Buffer
940d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer    implements Comparable<DoubleBuffer>
950d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer{
96dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
97dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    // These fields are declared here rather than in Heap-X-Buffer in order to
98dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    // reduce the number of virtual method invocations needed to access these
99dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    // values, which is especially costly when coding small buffers.
100dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    //
101dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    final double[] hb;                  // Non-null only for heap buffers
102dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    final int offset;
103dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    boolean isReadOnly;                 // Valid only for heap buffers
104dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
105dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    // Creates a new buffer with the given mark, position, limit, capacity,
106dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    // backing array, and array offset
107dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    //
108dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    DoubleBuffer(int mark, int pos, int lim, int cap,   // package-private
1090d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer                 double[] hb, int offset)
1100d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer    {
111dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        super(mark, pos, lim, cap, 3);
112dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        this.hb = hb;
113dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        this.offset = offset;
114dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
115dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
116dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    // Creates a new buffer with the given mark, position, limit, and capacity
117dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    //
118dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    DoubleBuffer(int mark, int pos, int lim, int cap) { // package-private
119dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        this(mark, pos, lim, cap, null, 0);
120dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
121dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
122dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
123dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
124dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Allocates a new double buffer.
125dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
126dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> The new buffer's position will be zero, its limit will be its
127dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * capacity, its mark will be undefined, and each of its elements will be
1280d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * initialized to zero.  It will have a {@link #array backing array},
1290d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * and its {@link #arrayOffset array offset} will be zero.
130dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
1310d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param  capacity
1320d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         The new buffer's capacity, in doubles
1330d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
1340d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  The new double buffer
1350d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
1360d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  IllegalArgumentException
1370d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If the <tt>capacity</tt> is a negative integer
138dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
139dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public static DoubleBuffer allocate(int capacity) {
140dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        if (capacity < 0)
141dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            throw new IllegalArgumentException();
142dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        return new HeapDoubleBuffer(capacity, capacity);
143dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
144dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
145dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
146dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Wraps a double array into a buffer.
147dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
148dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> The new buffer will be backed by the given double array;
149dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * that is, modifications to the buffer will cause the array to be modified
150dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * and vice versa.  The new buffer's capacity will be
151dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <tt>array.length</tt>, its position will be <tt>offset</tt>, its limit
152dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * will be <tt>offset + length</tt>, and its mark will be undefined.  Its
1530d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * {@link #array backing array} will be the given array, and
1540d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * its {@link #arrayOffset array offset} will be zero.  </p>
1550d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
1560d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param  array
1570d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         The array that will back the new buffer
1580d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
1590d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param  offset
1600d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         The offset of the subarray to be used; must be non-negative and
1610d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         no larger than <tt>array.length</tt>.  The new buffer's position
1620d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         will be set to this value.
1630d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
1640d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param  length
1650d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         The length of the subarray to be used;
1660d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         must be non-negative and no larger than
1670d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         <tt>array.length - offset</tt>.
1680d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         The new buffer's limit will be set to <tt>offset + length</tt>.
1690d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
1700d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  The new double buffer
1710d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
1720d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  IndexOutOfBoundsException
1730d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If the preconditions on the <tt>offset</tt> and <tt>length</tt>
1740d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          parameters do not hold
175dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
176dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public static DoubleBuffer wrap(double[] array,
1770d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer                                    int offset, int length)
1780d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer    {
179dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        try {
180dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            return new HeapDoubleBuffer(array, offset, length);
181dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        } catch (IllegalArgumentException x) {
182dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            throw new IndexOutOfBoundsException();
183dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        }
184dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
185dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
186dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
187dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Wraps a double array into a buffer.
188dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
189dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> The new buffer will be backed by the given double array;
190dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * that is, modifications to the buffer will cause the array to be modified
191dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * and vice versa.  The new buffer's capacity and limit will be
192dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <tt>array.length</tt>, its position will be zero, and its mark will be
1930d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * undefined.  Its {@link #array backing array} will be the
1940d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * given array, and its {@link #arrayOffset array offset>} will
195dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * be zero.  </p>
196dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
1970d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param  array
1980d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         The array that will back this buffer
1990d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
2000d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  The new double buffer
201dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
202dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public static DoubleBuffer wrap(double[] array) {
203dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        return wrap(array, 0, array.length);
204dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
205dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
206dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
207190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera    /**
208190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * Creates a new double buffer whose content is a shared subsequence of
209190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * this buffer's content.
210190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     *
211190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * <p> The content of the new buffer will start at this buffer's current
212190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * position.  Changes to this buffer's content will be visible in the new
213190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * buffer, and vice versa; the two buffers' position, limit, and mark
214190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * values will be independent.
215190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     *
216190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * <p> The new buffer's position will be zero, its capacity and its limit
217190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * will be the number of doubles remaining in this buffer, and its mark
218190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * will be undefined.  The new buffer will be direct if, and only if, this
219190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * buffer is direct, and it will be read-only if, and only if, this buffer
220190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * is read-only.  </p>
221190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     *
2220d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  The new double buffer
223190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     */
224190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera    public abstract DoubleBuffer slice();
225dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
226190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera    /**
227190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * Creates a new double buffer that shares this buffer's content.
228190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     *
229190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * <p> The content of the new buffer will be that of this buffer.  Changes
230190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * to this buffer's content will be visible in the new buffer, and vice
231190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * versa; the two buffers' position, limit, and mark values will be
232190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * independent.
233190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     *
234190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * <p> The new buffer's capacity, limit, position, and mark values will be
235190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * identical to those of this buffer.  The new buffer will be direct if,
236190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * and only if, this buffer is direct, and it will be read-only if, and
237190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * only if, this buffer is read-only.  </p>
238190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     *
2390d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  The new double buffer
240190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     */
241190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera    public abstract DoubleBuffer duplicate();
242dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
243190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera    /**
244190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * Creates a new, read-only double buffer that shares this buffer's
245190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * content.
246190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     *
247190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * <p> The content of the new buffer will be that of this buffer.  Changes
248190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * to this buffer's content will be visible in the new buffer; the new
249190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * buffer itself, however, will be read-only and will not allow the shared
250190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * content to be modified.  The two buffers' position, limit, and mark
251190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * values will be independent.
252190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     *
253190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * <p> The new buffer's capacity, limit, position, and mark values will be
254190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * identical to those of this buffer.
255190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     *
256190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * <p> If this buffer is itself read-only then this method behaves in
257190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     * exactly the same way as the {@link #duplicate duplicate} method.  </p>
258190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     *
2590d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  The new, read-only double buffer
260190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera     */
261190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera    public abstract DoubleBuffer asReadOnlyBuffer();
262dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
263dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
264190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera    // -- Singleton get/put methods --
265dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
266dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
267dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Relative <i>get</i> method.  Reads the double at this buffer's
2680d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * current position, and then increments the position.
2690d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
2700d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  The double at the buffer's current position
271dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
2720d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  BufferUnderflowException
2730d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If the buffer's current position is not smaller than its limit
274dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
275dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public abstract double get();
276dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
277dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
278dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Relative <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
279dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
280dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> Writes the given double into this buffer at the current
281dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * position, and then increments the position. </p>
282dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
2830d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param  d
2840d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         The double to be written
2850d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
2860d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  This buffer
2870d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
2880d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  BufferOverflowException
2890d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If this buffer's current position is not smaller than its limit
2900d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
2910d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  ReadOnlyBufferException
2920d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If this buffer is read-only
293dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
294dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public abstract DoubleBuffer put(double d);
295dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
296dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
297dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Absolute <i>get</i> method.  Reads the double at the given
2980d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * index.
2990d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
3000d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param  index
3010d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         The index from which the double will be read
302dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
3030d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  The double at the given index
3040d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
3050d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  IndexOutOfBoundsException
3060d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If <tt>index</tt> is negative
3070d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          or not smaller than the buffer's limit
308dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
309dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public abstract double get(int index);
310dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
311dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
312dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Absolute <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
313dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
314dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> Writes the given double into this buffer at the given
315dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * index. </p>
316dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
3170d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param  index
3180d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         The index at which the double will be written
3190d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
3200d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param  d
3210d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         The double value to be written
3220d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
3230d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  This buffer
3240d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
3250d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  IndexOutOfBoundsException
3260d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If <tt>index</tt> is negative
3270d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          or not smaller than the buffer's limit
3280d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
3290d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  ReadOnlyBufferException
3300d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If this buffer is read-only
331dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
332dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public abstract DoubleBuffer put(int index, double d);
333dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
334dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
335dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    // -- Bulk get operations --
336dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
337dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
338dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Relative bulk <i>get</i> method.
339dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
340dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> This method transfers doubles from this buffer into the given
341dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * destination array.  If there are fewer doubles remaining in the
342dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * buffer than are required to satisfy the request, that is, if
343dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <tt>length</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>, then no
344dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * doubles are transferred and a {@link BufferUnderflowException} is
345dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * thrown.
346dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
347dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> Otherwise, this method copies <tt>length</tt> doubles from this
348dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * buffer into the given array, starting at the current position of this
349dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * buffer and at the given offset in the array.  The position of this
350dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * buffer is then incremented by <tt>length</tt>.
351dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
352dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> In other words, an invocation of this method of the form
353dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <tt>src.get(dst,&nbsp;off,&nbsp;len)</tt> has exactly the same effect as
354dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * the loop
355dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
3560d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * <pre>{@code
357dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *     for (int i = off; i < off + len; i++)
3580d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         dst[i] = src.get();
3590d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * }</pre>
360dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
361dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * except that it first checks that there are sufficient doubles in
3620d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * this buffer and it is potentially much more efficient.
3630d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
3640d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param  dst
3650d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         The array into which doubles are to be written
3660d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
3670d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param  offset
3680d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         The offset within the array of the first double to be
3690d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         written; must be non-negative and no larger than
3700d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         <tt>dst.length</tt>
3710d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
3720d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param  length
3730d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         The maximum number of doubles to be written to the given
3740d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         array; must be non-negative and no larger than
3750d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         <tt>dst.length - offset</tt>
3760d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
3770d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  This buffer
3780d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
3790d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  BufferUnderflowException
3800d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If there are fewer than <tt>length</tt> doubles
3810d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          remaining in this buffer
3820d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
3830d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  IndexOutOfBoundsException
3840d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If the preconditions on the <tt>offset</tt> and <tt>length</tt>
3850d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          parameters do not hold
386dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
387dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public DoubleBuffer get(double[] dst, int offset, int length) {
388dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        checkBounds(offset, length, dst.length);
389dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        if (length > remaining())
390dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            throw new BufferUnderflowException();
391dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        int end = offset + length;
392dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        for (int i = offset; i < end; i++)
393dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            dst[i] = get();
394dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        return this;
395dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
396dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
397dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
398dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Relative bulk <i>get</i> method.
399dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
400dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> This method transfers doubles from this buffer into the given
401dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * destination array.  An invocation of this method of the form
402dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <tt>src.get(a)</tt> behaves in exactly the same way as the invocation
403dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
404dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <pre>
405dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *     src.get(a, 0, a.length) </pre>
406dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
4070d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param   dst
4080d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          The destination array
4090d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
4100d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  This buffer
4110d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
4120d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  BufferUnderflowException
4130d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If there are fewer than <tt>length</tt> doubles
4140d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          remaining in this buffer
415dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
416dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public DoubleBuffer get(double[] dst) {
417dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        return get(dst, 0, dst.length);
418dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
419dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
420dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
421dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    // -- Bulk put operations --
422dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
423dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
424dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
425dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
426dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> This method transfers the doubles remaining in the given source
427dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * buffer into this buffer.  If there are more doubles remaining in the
428dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * source buffer than in this buffer, that is, if
429dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <tt>src.remaining()</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>,
430dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * then no doubles are transferred and a {@link
431dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * BufferOverflowException} is thrown.
432dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
433dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> Otherwise, this method copies
434dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <i>n</i>&nbsp;=&nbsp;<tt>src.remaining()</tt> doubles from the given
435dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * buffer into this buffer, starting at each buffer's current position.
436dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * The positions of both buffers are then incremented by <i>n</i>.
437dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
438dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> In other words, an invocation of this method of the form
439dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <tt>dst.put(src)</tt> has exactly the same effect as the loop
440dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
441dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <pre>
442dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *     while (src.hasRemaining())
443dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *         dst.put(src.get()); </pre>
444dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
445dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * except that it first checks that there is sufficient space in this
4460d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * buffer and it is potentially much more efficient.
4470d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
4480d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param  src
4490d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         The source buffer from which doubles are to be read;
4500d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         must not be this buffer
4510d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
4520d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  This buffer
4530d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
4540d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  BufferOverflowException
4550d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If there is insufficient space in this buffer
4560d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          for the remaining doubles in the source buffer
4570d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
4580d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  IllegalArgumentException
4590d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If the source buffer is this buffer
4600d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
4610d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  ReadOnlyBufferException
4620d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If this buffer is read-only
463dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
464dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public DoubleBuffer put(DoubleBuffer src) {
465dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        if (src == this)
466dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            throw new IllegalArgumentException();
467dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        int n = src.remaining();
468dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        if (n > remaining())
469dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            throw new BufferOverflowException();
470dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        for (int i = 0; i < n; i++)
471dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            put(src.get());
472dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        return this;
473dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
474dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
475dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
476dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
477dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
478dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> This method transfers doubles into this buffer from the given
479dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * source array.  If there are more doubles to be copied from the array
480dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * than remain in this buffer, that is, if
481dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <tt>length</tt>&nbsp;<tt>&gt;</tt>&nbsp;<tt>remaining()</tt>, then no
482dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * doubles are transferred and a {@link BufferOverflowException} is
483dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * thrown.
484dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
485dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> Otherwise, this method copies <tt>length</tt> doubles from the
486dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * given array into this buffer, starting at the given offset in the array
487dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * and at the current position of this buffer.  The position of this buffer
488dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * is then incremented by <tt>length</tt>.
489dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
490dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> In other words, an invocation of this method of the form
491dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <tt>dst.put(src,&nbsp;off,&nbsp;len)</tt> has exactly the same effect as
492dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * the loop
493dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
4940d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * <pre>{@code
495dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *     for (int i = off; i < off + len; i++)
4960d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         dst.put(a[i]);
4970d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * }</pre>
498dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
499dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * except that it first checks that there is sufficient space in this
5000d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * buffer and it is potentially much more efficient.
5010d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
5020d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param  src
5030d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         The array from which doubles are to be read
5040d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
5050d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param  offset
5060d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         The offset within the array of the first double to be read;
5070d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         must be non-negative and no larger than <tt>array.length</tt>
5080d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
5090d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param  length
5100d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         The number of doubles to be read from the given array;
5110d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         must be non-negative and no larger than
5120d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *         <tt>array.length - offset</tt>
5130d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
5140d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  This buffer
5150d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
5160d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  BufferOverflowException
5170d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If there is insufficient space in this buffer
5180d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
5190d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  IndexOutOfBoundsException
5200d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If the preconditions on the <tt>offset</tt> and <tt>length</tt>
5210d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          parameters do not hold
5220d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
5230d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  ReadOnlyBufferException
5240d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If this buffer is read-only
525dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
526dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public DoubleBuffer put(double[] src, int offset, int length) {
527dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        checkBounds(offset, length, src.length);
528dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        if (length > remaining())
529dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            throw new BufferOverflowException();
530dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        int end = offset + length;
531dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        for (int i = offset; i < end; i++)
532dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            this.put(src[i]);
533dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        return this;
534dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
535dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
536dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
537dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Relative bulk <i>put</i> method&nbsp;&nbsp;<i>(optional operation)</i>.
538dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
539dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> This method transfers the entire content of the given source
540dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * double array into this buffer.  An invocation of this method of the
541dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * form <tt>dst.put(a)</tt> behaves in exactly the same way as the
542dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * invocation
543dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
544dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <pre>
545dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *     dst.put(a, 0, a.length) </pre>
546dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
5470d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param   src
5480d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          The source array
5490d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
5500d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  This buffer
5510d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
5520d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  BufferOverflowException
5530d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If there is insufficient space in this buffer
5540d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
5550d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  ReadOnlyBufferException
5560d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If this buffer is read-only
557dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
558dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public final DoubleBuffer put(double[] src) {
559dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        return put(src, 0, src.length);
560dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
561dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
562dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
563dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    // -- Other stuff --
564dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
565dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
566dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Tells whether or not this buffer is backed by an accessible double
567dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * array.
568dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
569dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> If this method returns <tt>true</tt> then the {@link #array() array}
570dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * and {@link #arrayOffset() arrayOffset} methods may safely be invoked.
571dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * </p>
572dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
5730d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  <tt>true</tt> if, and only if, this buffer
5740d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          is backed by an array and is not read-only
575dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
576dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public final boolean hasArray() {
577dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        return (hb != null) && !isReadOnly;
578dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
579dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
580dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
581dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Returns the double array that backs this
582dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * buffer&nbsp;&nbsp;<i>(optional operation)</i>.
583dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
584dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> Modifications to this buffer's content will cause the returned
585dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * array's content to be modified, and vice versa.
586dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
587dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> Invoke the {@link #hasArray hasArray} method before invoking this
588dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * method in order to ensure that this buffer has an accessible backing
589dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * array.  </p>
590dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
5910d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  The array that backs this buffer
5920d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
5930d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  ReadOnlyBufferException
5940d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If this buffer is backed by an array but is read-only
5950d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
5960d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  UnsupportedOperationException
5970d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If this buffer is not backed by an accessible array
598dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
599dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public final double[] array() {
600dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        if (hb == null)
601dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            throw new UnsupportedOperationException();
602dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        if (isReadOnly)
603dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            throw new ReadOnlyBufferException();
604dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        return hb;
605dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
606dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
607dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
608dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Returns the offset within this buffer's backing array of the first
609dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * element of the buffer&nbsp;&nbsp;<i>(optional operation)</i>.
610dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
611dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> If this buffer is backed by an array then buffer position <i>p</i>
612dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * corresponds to array index <i>p</i>&nbsp;+&nbsp;<tt>arrayOffset()</tt>.
613dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
614dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> Invoke the {@link #hasArray hasArray} method before invoking this
615dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * method in order to ensure that this buffer has an accessible backing
616dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * array.  </p>
617dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
6180d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  The offset within this buffer's array
6190d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          of the first element of the buffer
6200d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
6210d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  ReadOnlyBufferException
6220d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If this buffer is backed by an array but is read-only
6230d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
6240d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  UnsupportedOperationException
6250d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If this buffer is not backed by an accessible array
626dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
627dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public final int arrayOffset() {
628dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        if (hb == null)
629dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            throw new UnsupportedOperationException();
630dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        if (isReadOnly)
631dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            throw new ReadOnlyBufferException();
632dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        return offset;
633dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
634dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
635dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
636dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Compacts this buffer&nbsp;&nbsp;<i>(optional operation)</i>.
637dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
638dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> The doubles between the buffer's current position and its limit,
639dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * if any, are copied to the beginning of the buffer.  That is, the
640dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * double at index <i>p</i>&nbsp;=&nbsp;<tt>position()</tt> is copied
641dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * to index zero, the double at index <i>p</i>&nbsp;+&nbsp;1 is copied
642dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * to index one, and so forth until the double at index
643dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <tt>limit()</tt>&nbsp;-&nbsp;1 is copied to index
644dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <i>n</i>&nbsp;=&nbsp;<tt>limit()</tt>&nbsp;-&nbsp;<tt>1</tt>&nbsp;-&nbsp;<i>p</i>.
645dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * The buffer's position is then set to <i>n+1</i> and its limit is set to
646dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * its capacity.  The mark, if defined, is discarded.
647dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
648dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> The buffer's position is set to the number of doubles copied,
649dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * rather than to zero, so that an invocation of this method can be
650dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * followed immediately by an invocation of another relative <i>put</i>
651dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * method. </p>
652dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
6530d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer
6540d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
6550d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  This buffer
6560d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
6570d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @throws  ReadOnlyBufferException
6580d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          If this buffer is read-only
659dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
660dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public abstract DoubleBuffer compact();
661dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
662dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
6630d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * Tells whether or not this double buffer is direct.
664dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
6650d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  <tt>true</tt> if, and only if, this buffer is direct
666dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
667dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public abstract boolean isDirect();
668dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
669dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
670dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
6710d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * Returns a string summarizing the state of this buffer.
672dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
6730d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  A summary string
674dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
675dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public String toString() {
676dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        StringBuffer sb = new StringBuffer();
677dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        sb.append(getClass().getName());
678dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        sb.append("[pos=");
679dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        sb.append(position());
680dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        sb.append(" lim=");
681dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        sb.append(limit());
682dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        sb.append(" cap=");
683dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        sb.append(capacity());
684dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        sb.append("]");
685dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        return sb.toString();
686dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
687dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
688dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
689dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
690dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Returns the current hash code of this buffer.
691dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
692dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> The hash code of a double buffer depends only upon its remaining
693dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * elements; that is, upon the elements from <tt>position()</tt> up to, and
694dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * including, the element at <tt>limit()</tt>&nbsp;-&nbsp;<tt>1</tt>.
695dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
696dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> Because buffer hash codes are content-dependent, it is inadvisable
697dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * to use buffers as keys in hash maps or similar data structures unless it
698dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * is known that their contents will not change.  </p>
699dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
7000d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  The current hash code of this buffer
701dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
702dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public int hashCode() {
703dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        int h = 1;
704dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        int p = position();
705dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        for (int i = limit() - 1; i >= p; i--)
706190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera            h = 31 * h + (int) get(i);
707dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        return h;
708dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
709dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
710dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
711dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Tells whether or not this buffer is equal to another object.
712dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
713dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> Two double buffers are equal if, and only if,
714dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
7150d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * <ol>
716dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
7170d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *   <li><p> They have the same element type,  </p></li>
718dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
7190d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *   <li><p> They have the same number of remaining elements, and
7200d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *   </p></li>
721dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
7220d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *   <li><p> The two sequences of remaining elements, considered
7230d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *   independently of their starting positions, are pointwise equal.
7240d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer
7250d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *   This method considers two double elements {@code a} and {@code b}
7260d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *   to be equal if
7270d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *   {@code (a == b) || (Double.isNaN(a) && Double.isNaN(b))}.
7280d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *   The values {@code -0.0} and {@code +0.0} are considered to be
7290d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *   equal, unlike {@link Double#equals(Object)}.
7300d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer
7310d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *   </p></li>
732dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
733dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * </ol>
734dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
735dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> A double buffer is not equal to any other type of object.  </p>
736dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
7370d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @param  ob  The object to which this buffer is to be compared
7380d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *
7390d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  <tt>true</tt> if, and only if, this buffer is equal to the
7400d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *           given object
741dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
742dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public boolean equals(Object ob) {
743dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        if (this == ob)
744dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            return true;
745dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        if (!(ob instanceof DoubleBuffer))
746dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            return false;
7470d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer        DoubleBuffer that = (DoubleBuffer)ob;
748dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        if (this.remaining() != that.remaining())
749dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            return false;
750dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        int p = this.position();
751dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--)
752dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            if (!equals(this.get(i), that.get(j)))
753dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski                return false;
754dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        return true;
755dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
756dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
757dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    private static boolean equals(double x, double y) {
758dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
759dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        return (x == y) || (Double.isNaN(x) && Double.isNaN(y));
760dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
761dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
762dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
763dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
764dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
765dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Compares this buffer to another.
766dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
767dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> Two double buffers are compared by comparing their sequences of
768dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * remaining elements lexicographically, without regard to the starting
769dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * position of each sequence within its corresponding buffer.
7700d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer
771dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Pairs of {@code double} elements are compared as if by invoking
7720d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * {@link Double#compare(double,double)}, except that
773dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * {@code -0.0} and {@code 0.0} are considered to be equal.
774dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * {@code Double.NaN} is considered by this method to be equal
775dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * to itself and greater than all other {@code double} values
776dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * (including {@code Double.POSITIVE_INFINITY}).
7770d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer
778dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
779dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> A double buffer is not comparable to any other type of object.
780dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
7810d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  A negative integer, zero, or a positive integer as this buffer
7820d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     *          is less than, equal to, or greater than the given buffer
783dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
784dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public int compareTo(DoubleBuffer that) {
785dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        int n = this.position() + Math.min(this.remaining(), that.remaining());
786dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        for (int i = this.position(), j = that.position(); i < n; i++, j++) {
7876975f84c2ed72e1e26d20190b6f318718c849008Tobias Thierer            // Android-changed: Call through to Double.compare() instead of
788b304b288d1deafd07ee13e1540acc0a22db07736Narayan Kamath            // duplicating code pointlessly.
789b304b288d1deafd07ee13e1540acc0a22db07736Narayan Kamath            int cmp = Double.compare(this.get(i), that.get(j));
790dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski            if (cmp != 0)
791dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski                return cmp;
792dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        }
793dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski        return this.remaining() - that.remaining();
794dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
795dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
796dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    private static int compare(double x, double y) {
797dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
7980d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer        return ((x < y)  ? -1 :
7990d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer                (x > y)  ? +1 :
8000d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer                (x == y) ?  0 :
8010d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer                Double.isNaN(x) ? (Double.isNaN(y) ? 0 : +1) : -1);
802dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
803dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    }
804dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
805dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    // -- Other char stuff --
806dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
807dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
808dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    // -- Other byte stuff: Access to binary data --
809dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
810dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
811dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    /**
812dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * Retrieves this buffer's byte order.
813dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
814dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * <p> The byte order of a double buffer created by allocation or by
815dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * wrapping an existing <tt>double</tt> array is the {@link
8160d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * ByteOrder#nativeOrder native order} of the underlying
817dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * hardware.  The byte order of a double buffer created as a <a
818dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * href="ByteBuffer.html#views">view</a> of a byte buffer is that of the
819dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     * byte buffer at the moment that the view is created.  </p>
820dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     *
8210d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer     * @return  This buffer's byte order
822dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski     */
823dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski    public abstract ByteOrder order();
824dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
825dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski
826dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski}
827