2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 * FloatArrayBuffer, ReadWriteFloatArrayBuffer and ReadOnlyFloatArrayBuffer
22 * compose the implementation of array based float buffers.
24 * ReadWriteFloatArrayBuffer extends FloatArrayBuffer with all the write
28 * This class is marked final for runtime performance.
32 final class ReadWriteFloatArrayBuffer extends FloatArrayBuffer {
34 static ReadWriteFloatArrayBuffer copy(FloatArrayBuffer other,
36 ReadWriteFloatArrayBuffer buf = new ReadWriteFloatArrayBuffer(other
37 .capacity(), other.backingArray, other.offset);
38 buf.limit = other.limit();
39 buf.position = other.position();
40 buf.mark = markOfOther;
44 ReadWriteFloatArrayBuffer(float[] array) {
48 ReadWriteFloatArrayBuffer(int capacity) {
52 ReadWriteFloatArrayBuffer(int capacity, float[] backingArray,
54 super(capacity, backingArray, arrayOffset);
58 public FloatBuffer asReadOnlyBuffer() {
59 return ReadOnlyFloatArrayBuffer.copy(this, mark);
63 public FloatBuffer compact() {
64 System.arraycopy(backingArray, position + offset, backingArray, offset,
66 position = limit - position;
73 public FloatBuffer duplicate() {
74 return copy(this, mark);
78 public boolean isReadOnly() {
83 protected float[] protectedArray() {
88 protected int protectedArrayOffset() {
93 protected boolean protectedHasArray() {
98 public FloatBuffer put(float c) {
99 if (position == limit) {
100 throw new BufferOverflowException();
102 backingArray[offset + position++] = c;
107 public FloatBuffer put(int index, float c) {
108 if (index < 0 || index >= limit) {
109 throw new IndexOutOfBoundsException();
111 backingArray[offset + index] = c;
116 public FloatBuffer put(float[] src, int off, int len) {
117 int length = src.length;
118 if (off < 0 || len < 0 || (long) off + (long) len > length) {
119 throw new IndexOutOfBoundsException();
121 if (len > remaining()) {
122 throw new BufferOverflowException();
124 System.arraycopy(src, off, backingArray, offset + position, len);
130 public FloatBuffer slice() {
131 return new ReadWriteFloatArrayBuffer(remaining(), backingArray, offset