• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17 
18 package java.nio;
19 
20 /**
21  * FloatArrayBuffer, ReadWriteFloatArrayBuffer and ReadOnlyFloatArrayBuffer
22  * compose the implementation of array based float buffers.
23  * <p>
24  * ReadWriteFloatArrayBuffer extends FloatArrayBuffer with all the write
25  * methods.
26  * </p>
27  * <p>
28  * This class is marked final for runtime performance.
29  * </p>
30  *
31  */
32 final class ReadWriteFloatArrayBuffer extends FloatArrayBuffer {
33 
copy(FloatArrayBuffer other, int markOfOther)34     static ReadWriteFloatArrayBuffer copy(FloatArrayBuffer other, int markOfOther) {
35         ReadWriteFloatArrayBuffer buf =
36                 new ReadWriteFloatArrayBuffer(other.capacity(), other.backingArray, other.offset);
37         buf.limit = other.limit;
38         buf.position = other.position();
39         buf.mark = markOfOther;
40         return buf;
41     }
42 
ReadWriteFloatArrayBuffer(float[] array)43     ReadWriteFloatArrayBuffer(float[] array) {
44         super(array);
45     }
46 
ReadWriteFloatArrayBuffer(int capacity)47     ReadWriteFloatArrayBuffer(int capacity) {
48         super(capacity);
49     }
50 
ReadWriteFloatArrayBuffer(int capacity, float[] backingArray, int arrayOffset)51     ReadWriteFloatArrayBuffer(int capacity, float[] backingArray, int arrayOffset) {
52         super(capacity, backingArray, arrayOffset);
53     }
54 
55     @Override
asReadOnlyBuffer()56     public FloatBuffer asReadOnlyBuffer() {
57         return ReadOnlyFloatArrayBuffer.copy(this, mark);
58     }
59 
60     @Override
compact()61     public FloatBuffer compact() {
62         System.arraycopy(backingArray, position + offset, backingArray, offset, remaining());
63         position = limit - position;
64         limit = capacity;
65         mark = UNSET_MARK;
66         return this;
67     }
68 
69     @Override
duplicate()70     public FloatBuffer duplicate() {
71         return copy(this, mark);
72     }
73 
74     @Override
isReadOnly()75     public boolean isReadOnly() {
76         return false;
77     }
78 
protectedArray()79     @Override float[] protectedArray() {
80         return backingArray;
81     }
82 
protectedArrayOffset()83     @Override int protectedArrayOffset() {
84         return offset;
85     }
86 
protectedHasArray()87     @Override boolean protectedHasArray() {
88         return true;
89     }
90 
91     @Override
put(float c)92     public FloatBuffer put(float c) {
93         if (position == limit) {
94             throw new BufferOverflowException();
95         }
96         backingArray[offset + position++] = c;
97         return this;
98     }
99 
100     @Override
put(int index, float c)101     public FloatBuffer put(int index, float c) {
102         checkIndex(index);
103         backingArray[offset + index] = c;
104         return this;
105     }
106 
107     @Override
put(float[] src, int srcOffset, int floatCount)108     public FloatBuffer put(float[] src, int srcOffset, int floatCount) {
109         if (floatCount > remaining()) {
110             throw new BufferOverflowException();
111         }
112         System.arraycopy(src, srcOffset, backingArray, offset + position, floatCount);
113         position += floatCount;
114         return this;
115     }
116 
117     @Override
slice()118     public FloatBuffer slice() {
119         return new ReadWriteFloatArrayBuffer(remaining(), backingArray, offset + position);
120     }
121 
122 }
123