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
18package java.nio;
19
20/**
21 * LongArrayBuffer, ReadWriteLongArrayBuffer and ReadOnlyLongArrayBuffer compose
22 * the implementation of array based long buffers.
23 * <p>
24 * LongArrayBuffer implements all the shared readonly methods and is extended by
25 * the other two classes.
26 * </p>
27 * <p>
28 * All methods are marked final for runtime performance.
29 * </p>
30 *
31 */
32abstract class LongArrayBuffer extends LongBuffer {
33
34    protected final long[] backingArray;
35
36    protected final int offset;
37
38    LongArrayBuffer(long[] array) {
39        this(array.length, array, 0);
40    }
41
42    LongArrayBuffer(int capacity) {
43        this(capacity, new long[capacity], 0);
44    }
45
46    LongArrayBuffer(int capacity, long[] backingArray, int offset) {
47        super(capacity);
48        this.backingArray = backingArray;
49        this.offset = offset;
50    }
51
52    public final long get() {
53        if (position == limit) {
54            throw new BufferUnderflowException();
55        }
56        return backingArray[offset + position++];
57    }
58
59    public final long get(int index) {
60        if (index < 0 || index >= limit) {
61            throw new IndexOutOfBoundsException();
62        }
63        return backingArray[offset + index];
64    }
65
66    public final LongBuffer get(long[] dest, int off, int len) {
67        int length = dest.length;
68        if (off < 0 || len < 0 || (long)len + (long)off > length) {
69            throw new IndexOutOfBoundsException();
70        }
71        if (len > remaining()) {
72            throw new BufferUnderflowException();
73        }
74        System.arraycopy(backingArray, offset+position, dest, off, len);
75        position += len;
76        return this;
77    }
78
79    public final boolean isDirect() {
80        return false;
81    }
82
83    public final ByteOrder order() {
84        return ByteOrder.nativeOrder();
85    }
86
87}
88