01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: * DoubleArrayBuffer, ReadWriteDoubleArrayBuffer and ReadOnlyDoubleArrayBuffer
22: * compose the implementation of array based double buffers.
23: * <p>
24: * DoubleArrayBuffer implements all the shared readonly methods and is extended
25: * by the other two classes.
26: * </p>
27: * <p>
28: * All methods are marked final for runtime performance.
29: * </p>
30: *
31: */
32: abstract class DoubleArrayBuffer extends DoubleBuffer {
33:
34: protected final double[] backingArray;
35:
36: protected final int offset;
37:
38: DoubleArrayBuffer(double[] array) {
39: this (array.length, array, 0);
40: }
41:
42: DoubleArrayBuffer(int capacity) {
43: this (capacity, new double[capacity], 0);
44: }
45:
46: DoubleArrayBuffer(int capacity, double[] backingArray, int offset) {
47: super (capacity);
48: this .backingArray = backingArray;
49: this .offset = offset;
50: }
51:
52: @Override
53: public final double get() {
54: if (position == limit) {
55: throw new BufferUnderflowException();
56: }
57: return backingArray[offset + position++];
58: }
59:
60: @Override
61: public final double get(int index) {
62: if (index < 0 || index >= limit) {
63: throw new IndexOutOfBoundsException();
64: }
65: return backingArray[offset + index];
66: }
67:
68: @Override
69: public final DoubleBuffer get(double[] dest, int off, int len) {
70: int length = dest.length;
71: if (off < 0 || len < 0 || (long) off + (long) len > length) {
72: throw new IndexOutOfBoundsException();
73: }
74: if (len > remaining()) {
75: throw new BufferUnderflowException();
76: }
77: System.arraycopy(backingArray, offset + position, dest, off,
78: len);
79: position += len;
80: return this ;
81: }
82:
83: @Override
84: public final boolean isDirect() {
85: return false;
86: }
87:
88: @Override
89: public final ByteOrder order() {
90: return ByteOrder.nativeOrder();
91: }
92:
93: }
|