1dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski/* 22c87ad3a45cecf9e344487cad1abfdebe79f2c7cNarayan Kamath * Copyright (C) 2014 The Android Open Source Project 30d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 4dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 6dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * This code is free software; you can redistribute it and/or modify it 7dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * under the terms of the GNU General Public License version 2 only, as 8dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * published by the Free Software Foundation. Oracle designates this 9dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * particular file as subject to the "Classpath" exception as provided 10dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * by Oracle in the LICENSE file that accompanied this code. 11dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 12dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * This code is distributed in the hope that it will be useful, but WITHOUT 13dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * version 2 for more details (a copy is included in the LICENSE file that 16dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * accompanied this code). 17dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 18dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * You should have received a copy of the GNU General Public License version 19dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 2 along with this work; if not, write to the Free Software Foundation, 20dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 22dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 23dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * or visit www.oracle.com if you need additional information or have any 24dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * questions. 25dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 26dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 27dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski// -- This file was mechanically generated: Do not edit! -- // 28dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 29dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebskipackage java.nio; 30dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 31dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 32dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski/** 33dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * An int buffer. 34dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 35dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> This class defines four categories of operations upon 36dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * int buffers: 37dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 38dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <ul> 39dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 400d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * <li><p> Absolute and relative {@link #get() <i>get</i>} and 410d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * {@link #put(int) <i>put</i>} methods that read and write 420d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * single ints; </p></li> 43dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 440d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * <li><p> Relative {@link #get(int[]) <i>bulk get</i>} 450d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * methods that transfer contiguous sequences of ints from this buffer 460d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * into an array; and</p></li> 47dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 480d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * <li><p> Relative {@link #put(int[]) <i>bulk put</i>} 490d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * methods that transfer contiguous sequences of ints from an 500d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * int array or some other int 510d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * buffer into this buffer; and </p></li> 52dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 530d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 540d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * <li><p> Methods for {@link #compact compacting}, {@link 550d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * #duplicate duplicating}, and {@link #slice slicing} 560d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * an int buffer. </p></li> 57dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 58dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * </ul> 59dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 60dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> Int buffers can be created either by {@link #allocate 610d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * <i>allocation</i>}, which allocates space for the buffer's 620d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 63dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 640d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * content, by {@link #wrap(int[]) <i>wrapping</i>} an existing 65dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * int array into a buffer, or by creating a 66dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <a href="ByteBuffer.html#views"><i>view</i></a> of an existing byte buffer. 67dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 680d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 690d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer* 700d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 71dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> Like a byte buffer, an int buffer is either <a 72dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * href="ByteBuffer.html#direct"><i>direct</i> or <i>non-direct</i></a>. A 73dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * int buffer created via the <tt>wrap</tt> methods of this class will 74dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * be non-direct. An int buffer created as a view of a byte buffer will 75dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * be direct if, and only if, the byte buffer itself is direct. Whether or not 76dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * an int buffer is direct may be determined by invoking the {@link 77dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * #isDirect isDirect} method. </p> 78dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 790d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer* 800d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 810d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 82dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> Methods in this class that do not otherwise have a value to return are 83dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * specified to return the buffer upon which they are invoked. This allows 84dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * method invocations to be chained. 85dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 860d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 870d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 88dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * @author Mark Reinhold 89dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * @author JSR-51 Expert Group 90dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * @since 1.4 91dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 92dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 93dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebskipublic abstract class IntBuffer 940d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer extends Buffer 950d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer implements Comparable<IntBuffer> 960d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer{ 97dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 98dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski // These fields are declared here rather than in Heap-X-Buffer in order to 99dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski // reduce the number of virtual method invocations needed to access these 100dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski // values, which is especially costly when coding small buffers. 101dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski // 102dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski final int[] hb; // Non-null only for heap buffers 103dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski final int offset; 104dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski boolean isReadOnly; // Valid only for heap buffers 105dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 106dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski // Creates a new buffer with the given mark, position, limit, capacity, 107dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski // backing array, and array offset 108dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski // 109dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski IntBuffer(int mark, int pos, int lim, int cap, // package-private 1100d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer int[] hb, int offset) 1110d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer { 112190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera super(mark, pos, lim, cap, 2); 113190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera this.hb = hb; 114190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera this.offset = offset; 115190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera } 116dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 117dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski // Creates a new buffer with the given mark, position, limit, and capacity 118dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski // 119dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski IntBuffer(int mark, int pos, int lim, int cap) { // package-private 120dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski this(mark, pos, lim, cap, null, 0); 121dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 122dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 123dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 124dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 125dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Allocates a new int buffer. 126dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 127dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> The new buffer's position will be zero, its limit will be its 128dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * capacity, its mark will be undefined, and each of its elements will be 1290d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * initialized to zero. It will have a {@link #array backing array}, 1300d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * and its {@link #arrayOffset array offset} will be zero. 131dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 1320d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param capacity 1330d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The new buffer's capacity, in ints 1340d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 1350d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return The new int buffer 1360d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 1370d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws IllegalArgumentException 1380d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If the <tt>capacity</tt> is a negative integer 139dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 140dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public static IntBuffer allocate(int capacity) { 141dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski if (capacity < 0) 142dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski throw new IllegalArgumentException(); 143dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return new HeapIntBuffer(capacity, capacity); 144dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 145dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 146dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 147dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Wraps an int array into a buffer. 148dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 149dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> The new buffer will be backed by the given int array; 150dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * that is, modifications to the buffer will cause the array to be modified 151dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * and vice versa. The new buffer's capacity will be 152dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <tt>array.length</tt>, its position will be <tt>offset</tt>, its limit 153dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * will be <tt>offset + length</tt>, and its mark will be undefined. Its 1540d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * {@link #array backing array} will be the given array, and 1550d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * its {@link #arrayOffset array offset} will be zero. </p> 1560d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 1570d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param array 1580d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The array that will back the new buffer 1590d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 1600d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param offset 1610d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The offset of the subarray to be used; must be non-negative and 1620d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * no larger than <tt>array.length</tt>. The new buffer's position 1630d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * will be set to this value. 1640d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 1650d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param length 1660d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The length of the subarray to be used; 1670d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * must be non-negative and no larger than 1680d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * <tt>array.length - offset</tt>. 1690d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The new buffer's limit will be set to <tt>offset + length</tt>. 1700d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 1710d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return The new int buffer 1720d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 1730d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws IndexOutOfBoundsException 1740d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If the preconditions on the <tt>offset</tt> and <tt>length</tt> 1750d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * parameters do not hold 176dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 177dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public static IntBuffer wrap(int[] array, 1780d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer int offset, int length) 1790d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer { 180dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski try { 181dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return new HeapIntBuffer(array, offset, length); 182dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } catch (IllegalArgumentException x) { 183dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski throw new IndexOutOfBoundsException(); 184dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 185dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 186dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 187dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 188dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Wraps an int array into a buffer. 189dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 190dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> The new buffer will be backed by the given int array; 191dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * that is, modifications to the buffer will cause the array to be modified 192dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * and vice versa. The new buffer's capacity and limit will be 193dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <tt>array.length</tt>, its position will be zero, and its mark will be 1940d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * undefined. Its {@link #array backing array} will be the 1950d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * given array, and its {@link #arrayOffset array offset>} will 196dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * be zero. </p> 197dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 1980d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param array 1990d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The array that will back this buffer 2000d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 2010d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return The new int buffer 202dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 203dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public static IntBuffer wrap(int[] array) { 204dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return wrap(array, 0, array.length); 205dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 206dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 207dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 208190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera /** 209190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * Creates a new int buffer whose content is a shared subsequence of 210190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * this buffer's content. 211190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 212190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * <p> The content of the new buffer will start at this buffer's current 213190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * position. Changes to this buffer's content will be visible in the new 214190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * buffer, and vice versa; the two buffers' position, limit, and mark 215190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * values will be independent. 216190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 217190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * <p> The new buffer's position will be zero, its capacity and its limit 218190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * will be the number of ints remaining in this buffer, and its mark 219190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * will be undefined. The new buffer will be direct if, and only if, this 220190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * buffer is direct, and it will be read-only if, and only if, this buffer 221190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * is read-only. </p> 222190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 2230d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return The new int buffer 224190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera */ 225190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera public abstract IntBuffer slice(); 226dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 227190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera /** 228190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * Creates a new int buffer that shares this buffer's content. 229190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 230190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * <p> The content of the new buffer will be that of this buffer. Changes 231190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * to this buffer's content will be visible in the new buffer, and vice 232190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * versa; the two buffers' position, limit, and mark values will be 233190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * independent. 234190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 235190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * <p> The new buffer's capacity, limit, position, and mark values will be 236190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * identical to those of this buffer. The new buffer will be direct if, 237190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * and only if, this buffer is direct, and it will be read-only if, and 238190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * only if, this buffer is read-only. </p> 239190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 2400d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return The new int buffer 241190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera */ 242190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera public abstract IntBuffer duplicate(); 243dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 244dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 245dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Creates a new, read-only int buffer that shares this buffer's 246dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * content. 247dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 248dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> The content of the new buffer will be that of this buffer. Changes 249dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * to this buffer's content will be visible in the new buffer; the new 250dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * buffer itself, however, will be read-only and will not allow the shared 251dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * content to be modified. The two buffers' position, limit, and mark 252dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * values will be independent. 253dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 254dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> The new buffer's capacity, limit, position, and mark values will be 255dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * identical to those of this buffer. 256dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 257dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> If this buffer is itself read-only then this method behaves in 258dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * exactly the same way as the {@link #duplicate duplicate} method. </p> 259dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 2600d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return The new, read-only int buffer 261dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 262dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public abstract IntBuffer asReadOnlyBuffer(); 263dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 264dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 265dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski // -- Singleton get/put methods -- 266dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 267dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 268dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Relative <i>get</i> method. Reads the int at this buffer's 2690d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * current position, and then increments the position. 270dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 2710d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return The int at the buffer's current position 2720d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 2730d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws BufferUnderflowException 2740d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If the buffer's current position is not smaller than its limit 275dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 276dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public abstract int get(); 277dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 278dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 279dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Relative <i>put</i> method <i>(optional operation)</i>. 280dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 281dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> Writes the given int into this buffer at the current 282dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * position, and then increments the position. </p> 283dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 2840d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param i 2850d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The int to be written 2860d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 2870d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return This buffer 2880d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 2890d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws BufferOverflowException 2900d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If this buffer's current position is not smaller than its limit 2910d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 2920d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws ReadOnlyBufferException 2930d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If this buffer is read-only 294dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 295dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public abstract IntBuffer put(int i); 296dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 297dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 298dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Absolute <i>get</i> method. Reads the int at the given 2990d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * index. 3000d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 3010d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param index 3020d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The index from which the int will be read 303dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 3040d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return The int at the given index 3050d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 3060d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws IndexOutOfBoundsException 3070d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If <tt>index</tt> is negative 3080d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * or not smaller than the buffer's limit 309dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 310dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public abstract int get(int index); 311dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 312dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 313dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Absolute <i>put</i> method <i>(optional operation)</i>. 314dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 315dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> Writes the given int into this buffer at the given 316dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * index. </p> 317dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 3180d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param index 3190d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The index at which the int will be written 3200d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 3210d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param i 3220d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The int value to be written 3230d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 3240d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return This buffer 3250d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 3260d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws IndexOutOfBoundsException 3270d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If <tt>index</tt> is negative 3280d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * or not smaller than the buffer's limit 3290d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 3300d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws ReadOnlyBufferException 3310d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If this buffer is read-only 332dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 333dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public abstract IntBuffer put(int index, int i); 334dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 335dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 336dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski // -- Bulk get operations -- 337dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 338dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 339dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Relative bulk <i>get</i> method. 340dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 341dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> This method transfers ints from this buffer into the given 342dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * destination array. If there are fewer ints remaining in the 343dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * buffer than are required to satisfy the request, that is, if 344dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <tt>length</tt> <tt>></tt> <tt>remaining()</tt>, then no 345dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * ints are transferred and a {@link BufferUnderflowException} is 346dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * thrown. 347dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 348dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> Otherwise, this method copies <tt>length</tt> ints from this 349dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * buffer into the given array, starting at the current position of this 350dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * buffer and at the given offset in the array. The position of this 351dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * buffer is then incremented by <tt>length</tt>. 352dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 353dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> In other words, an invocation of this method of the form 354dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <tt>src.get(dst, off, len)</tt> has exactly the same effect as 355dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * the loop 356dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 3570d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * <pre>{@code 358dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * for (int i = off; i < off + len; i++) 3590d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * dst[i] = src.get(); 3600d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * }</pre> 361dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 362dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * except that it first checks that there are sufficient ints in 3630d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * this buffer and it is potentially much more efficient. 3640d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 3650d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param dst 3660d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The array into which ints are to be written 3670d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 3680d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param offset 3690d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The offset within the array of the first int to be 3700d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * written; must be non-negative and no larger than 3710d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * <tt>dst.length</tt> 3720d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 3730d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param length 3740d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The maximum number of ints to be written to the given 3750d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * array; must be non-negative and no larger than 3760d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * <tt>dst.length - offset</tt> 3770d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 3780d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return This buffer 3790d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 3800d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws BufferUnderflowException 3810d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If there are fewer than <tt>length</tt> ints 3820d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * remaining in this buffer 3830d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 3840d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws IndexOutOfBoundsException 3850d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If the preconditions on the <tt>offset</tt> and <tt>length</tt> 3860d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * parameters do not hold 387dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 388dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public IntBuffer get(int[] dst, int offset, int length) { 389dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski checkBounds(offset, length, dst.length); 390dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski if (length > remaining()) 391dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski throw new BufferUnderflowException(); 392dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski int end = offset + length; 393dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski for (int i = offset; i < end; i++) 394dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski dst[i] = get(); 395dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return this; 396dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 397dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 398dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 399dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Relative bulk <i>get</i> method. 400dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 401dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> This method transfers ints from this buffer into the given 402dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * destination array. An invocation of this method of the form 403dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <tt>src.get(a)</tt> behaves in exactly the same way as the invocation 404dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 405dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <pre> 406dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * src.get(a, 0, a.length) </pre> 407dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 4080d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param dst 4090d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The destination array 4100d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 4110d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return This buffer 4120d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 4130d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws BufferUnderflowException 4140d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If there are fewer than <tt>length</tt> ints 4150d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * remaining in this buffer 416dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 417dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public IntBuffer get(int[] dst) { 418dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return get(dst, 0, dst.length); 419dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 420dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 421dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 422dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski // -- Bulk put operations -- 423dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 424dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 425dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Relative bulk <i>put</i> method <i>(optional operation)</i>. 426dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 427dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> This method transfers the ints remaining in the given source 428dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * buffer into this buffer. If there are more ints remaining in the 429dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * source buffer than in this buffer, that is, if 430dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <tt>src.remaining()</tt> <tt>></tt> <tt>remaining()</tt>, 431dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * then no ints are transferred and a {@link 432dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * BufferOverflowException} is thrown. 433dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 434dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> Otherwise, this method copies 435dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <i>n</i> = <tt>src.remaining()</tt> ints from the given 436dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * buffer into this buffer, starting at each buffer's current position. 437dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * The positions of both buffers are then incremented by <i>n</i>. 438dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 439dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> In other words, an invocation of this method of the form 440dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <tt>dst.put(src)</tt> has exactly the same effect as the loop 441dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 442dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <pre> 443dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * while (src.hasRemaining()) 444dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * dst.put(src.get()); </pre> 445dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 446dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * except that it first checks that there is sufficient space in this 4470d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * buffer and it is potentially much more efficient. 4480d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 4490d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param src 4500d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The source buffer from which ints are to be read; 4510d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * must not be this buffer 4520d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 4530d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return This buffer 4540d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 4550d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws BufferOverflowException 4560d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If there is insufficient space in this buffer 4570d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * for the remaining ints in the source buffer 4580d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 4590d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws IllegalArgumentException 4600d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If the source buffer is this buffer 4610d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 4620d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws ReadOnlyBufferException 4630d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If this buffer is read-only 464dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 465dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public IntBuffer put(IntBuffer src) { 466dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski if (src == this) 467dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski throw new IllegalArgumentException(); 468dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski int n = src.remaining(); 469dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski if (n > remaining()) 470dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski throw new BufferOverflowException(); 471dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski for (int i = 0; i < n; i++) 472dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski put(src.get()); 473dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return this; 474dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 475dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 476dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 477dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Relative bulk <i>put</i> method <i>(optional operation)</i>. 478dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 479dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> This method transfers ints into this buffer from the given 480dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * source array. If there are more ints to be copied from the array 481dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * than remain in this buffer, that is, if 482dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <tt>length</tt> <tt>></tt> <tt>remaining()</tt>, then no 483dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * ints are transferred and a {@link BufferOverflowException} is 484dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * thrown. 485dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 486dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> Otherwise, this method copies <tt>length</tt> ints from the 487dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * given array into this buffer, starting at the given offset in the array 488dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * and at the current position of this buffer. The position of this buffer 489dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * is then incremented by <tt>length</tt>. 490dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 491dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> In other words, an invocation of this method of the form 492dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <tt>dst.put(src, off, len)</tt> has exactly the same effect as 493dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * the loop 494dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 4950d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * <pre>{@code 496dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * for (int i = off; i < off + len; i++) 4970d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * dst.put(a[i]); 4980d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * }</pre> 499dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 500dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * except that it first checks that there is sufficient space in this 5010d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * buffer and it is potentially much more efficient. 5020d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 5030d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param src 5040d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The array from which ints are to be read 5050d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 5060d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param offset 5070d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The offset within the array of the first int to be read; 5080d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * must be non-negative and no larger than <tt>array.length</tt> 5090d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 5100d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param length 5110d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The number of ints to be read from the given array; 5120d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * must be non-negative and no larger than 5130d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * <tt>array.length - offset</tt> 5140d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 5150d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return This buffer 5160d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 5170d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws BufferOverflowException 5180d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If there is insufficient space in this buffer 5190d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 5200d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws IndexOutOfBoundsException 5210d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If the preconditions on the <tt>offset</tt> and <tt>length</tt> 5220d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * parameters do not hold 5230d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 5240d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws ReadOnlyBufferException 5250d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If this buffer is read-only 526dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 527dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public IntBuffer put(int[] src, int offset, int length) { 528dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski checkBounds(offset, length, src.length); 529dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski if (length > remaining()) 530dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski throw new BufferOverflowException(); 531dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski int end = offset + length; 532dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski for (int i = offset; i < end; i++) 533dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski this.put(src[i]); 534dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return this; 535dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 536dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 537dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 538dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Relative bulk <i>put</i> method <i>(optional operation)</i>. 539dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 540dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> This method transfers the entire content of the given source 541dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * int array into this buffer. An invocation of this method of the 542dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * form <tt>dst.put(a)</tt> behaves in exactly the same way as the 543dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * invocation 544dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 545dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <pre> 546dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * dst.put(a, 0, a.length) </pre> 547dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 5480d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param src 5490d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * The source array 5500d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 5510d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return This buffer 5520d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 5530d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws BufferOverflowException 5540d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If there is insufficient space in this buffer 5550d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 5560d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws ReadOnlyBufferException 5570d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If this buffer is read-only 558dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 559dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public final IntBuffer put(int[] src) { 560dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return put(src, 0, src.length); 561dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 562dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 563dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 564dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski // -- Other stuff -- 565dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 566dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 567dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Tells whether or not this buffer is backed by an accessible int 568dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * array. 569dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 570dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> If this method returns <tt>true</tt> then the {@link #array() array} 571dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * and {@link #arrayOffset() arrayOffset} methods may safely be invoked. 572dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * </p> 573dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 5740d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return <tt>true</tt> if, and only if, this buffer 5750d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * is backed by an array and is not read-only 576dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 577dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public final boolean hasArray() { 578dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return (hb != null) && !isReadOnly; 579dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 580dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 581dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 582dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Returns the int array that backs this 583dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * buffer <i>(optional operation)</i>. 584dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 585dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> Modifications to this buffer's content will cause the returned 586dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * array's content to be modified, and vice versa. 587dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 588dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> Invoke the {@link #hasArray hasArray} method before invoking this 589dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * method in order to ensure that this buffer has an accessible backing 590dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * array. </p> 591dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 5920d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return The array that backs this buffer 5930d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 5940d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws ReadOnlyBufferException 5950d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If this buffer is backed by an array but is read-only 5960d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 5970d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws UnsupportedOperationException 5980d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If this buffer is not backed by an accessible array 599dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 600dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public final int[] array() { 601dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski if (hb == null) 602dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski throw new UnsupportedOperationException(); 603dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski if (isReadOnly) 604dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski throw new ReadOnlyBufferException(); 605dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return hb; 606dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 607dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 608dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 609dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Returns the offset within this buffer's backing array of the first 610dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * element of the buffer <i>(optional operation)</i>. 611dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 612dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> If this buffer is backed by an array then buffer position <i>p</i> 613dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * corresponds to array index <i>p</i> + <tt>arrayOffset()</tt>. 614dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 615dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> Invoke the {@link #hasArray hasArray} method before invoking this 616dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * method in order to ensure that this buffer has an accessible backing 617dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * array. </p> 618dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 6190d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return The offset within this buffer's array 6200d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * of the first element of the buffer 6210d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 6220d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws ReadOnlyBufferException 6230d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If this buffer is backed by an array but is read-only 6240d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 6250d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws UnsupportedOperationException 6260d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If this buffer is not backed by an accessible array 627dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 628dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public final int arrayOffset() { 629dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski if (hb == null) 630dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski throw new UnsupportedOperationException(); 631dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski if (isReadOnly) 632dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski throw new ReadOnlyBufferException(); 633dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return offset; 634dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 635dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 636dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 637dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Compacts this buffer <i>(optional operation)</i>. 638dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 639dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> The ints between the buffer's current position and its limit, 640dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * if any, are copied to the beginning of the buffer. That is, the 641dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * int at index <i>p</i> = <tt>position()</tt> is copied 642dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * to index zero, the int at index <i>p</i> + 1 is copied 643dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * to index one, and so forth until the int at index 644dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <tt>limit()</tt> - 1 is copied to index 645dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <i>n</i> = <tt>limit()</tt> - <tt>1</tt> - <i>p</i>. 646dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * The buffer's position is then set to <i>n+1</i> and its limit is set to 647dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * its capacity. The mark, if defined, is discarded. 648dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 649dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> The buffer's position is set to the number of ints copied, 650dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * rather than to zero, so that an invocation of this method can be 651dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * followed immediately by an invocation of another relative <i>put</i> 652dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * method. </p> 653dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 6540d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer 6550d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 6560d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return This buffer 6570d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 6580d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @throws ReadOnlyBufferException 6590d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * If this buffer is read-only 660dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 661dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public abstract IntBuffer compact(); 662dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 663dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 6640d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * Tells whether or not this int buffer is direct. 665dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 6660d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return <tt>true</tt> if, and only if, this buffer is direct 667dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 668dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public abstract boolean isDirect(); 669dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 670dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 671dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 6720d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * Returns a string summarizing the state of this buffer. 673dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 6740d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return A summary string 675dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 676dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public String toString() { 677dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski StringBuffer sb = new StringBuffer(); 678dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski sb.append(getClass().getName()); 679dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski sb.append("[pos="); 680dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski sb.append(position()); 681dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski sb.append(" lim="); 682dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski sb.append(limit()); 683dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski sb.append(" cap="); 684dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski sb.append(capacity()); 685dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski sb.append("]"); 686dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return sb.toString(); 687dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 688dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 689dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 690dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 691dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Returns the current hash code of this buffer. 692dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 693dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> The hash code of a int buffer depends only upon its remaining 694dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * elements; that is, upon the elements from <tt>position()</tt> up to, and 695dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * including, the element at <tt>limit()</tt> - <tt>1</tt>. 696dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 697dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> Because buffer hash codes are content-dependent, it is inadvisable 698dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * to use buffers as keys in hash maps or similar data structures unless it 699dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * is known that their contents will not change. </p> 700dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 7010d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return The current hash code of this buffer 702dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 703dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public int hashCode() { 704dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski int h = 1; 705dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski int p = position(); 706dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski for (int i = limit() - 1; i >= p; i--) 707190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera h = 31 * h + (int) get(i); 708dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return h; 709dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 710dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 711dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 712dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Tells whether or not this buffer is equal to another object. 713dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 714dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> Two int buffers are equal if, and only if, 715dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 7160d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * <ol> 717dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 7180d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * <li><p> They have the same element type, </p></li> 719dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 7200d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * <li><p> They have the same number of remaining elements, and 7210d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * </p></li> 722dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 7230d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * <li><p> The two sequences of remaining elements, considered 7240d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * independently of their starting positions, are pointwise equal. 725dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 726dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 727dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 728dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 729190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 730190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 731190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 7320d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * </p></li> 733190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 734190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * </ol> 735190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 736190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * <p> A int buffer is not equal to any other type of object. </p> 737190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 7380d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @param ob The object to which this buffer is to be compared 7390d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * 7400d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return <tt>true</tt> if, and only if, this buffer is equal to the 7410d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * given object 742190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera */ 743dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public boolean equals(Object ob) { 744dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski if (this == ob) 745dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return true; 746dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski if (!(ob instanceof IntBuffer)) 747dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return false; 7480d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer IntBuffer that = (IntBuffer)ob; 749dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski if (this.remaining() != that.remaining()) 750dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return false; 751dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski int p = this.position(); 752dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski for (int i = this.limit() - 1, j = that.limit() - 1; i >= p; i--, j--) 753dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski if (!equals(this.get(i), that.get(j))) 754dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return false; 755dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return true; 756dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 757dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 758dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski private static boolean equals(int x, int y) { 759dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 760dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 761dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return x == y; 762dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 763dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 764dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 765dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski /** 766dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Compares this buffer to another. 767dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 768dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> Two int buffers are compared by comparing their sequences of 769dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * remaining elements lexicographically, without regard to the starting 770dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * position of each sequence within its corresponding buffer. 771190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 772190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 773190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 774190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 775190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 776190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 777190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 778190a49036750b8bb6c979d958ed56aa3fb4f408aShubham Ajmera * 779dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * Pairs of {@code int} elements are compared as if by invoking 7800d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * {@link Integer#compare(int,int)}. 7810d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer 782dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 783dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * <p> A int buffer is not comparable to any other type of object. 784dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * 7850d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * @return A negative integer, zero, or a positive integer as this buffer 7860d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * is less than, equal to, or greater than the given buffer 787dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski */ 788dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski public int compareTo(IntBuffer that) { 789dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski int n = this.position() + Math.min(this.remaining(), that.remaining()); 790dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski for (int i = this.position(), j = that.position(); i < n; i++, j++) { 791dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski int cmp = compare(this.get(i), that.get(j)); 792dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski if (cmp != 0) 793dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return cmp; 794dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 795dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return this.remaining() - that.remaining(); 796dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski } 797dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 798dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski private static int compare(int x, int y) { 799dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 800dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski 801dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski return Integer.compare(x, y); 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 an int buffer created by allocation or by 815dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * wrapping an existing <tt>int</tt> array is the {@link 8160d6471219bdd70d45b784a810e037e97011d6459Tobias Thierer * ByteOrder#nativeOrder native order} of the underlying 817dee594e6a72064fc994b305487a61f2e2bb250e1Piotr Jastrzebski * hardware. The byte order of an int 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