001: /*
002: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License version
007: * 2 only, as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful, but
010: * WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * General Public License version 2 for more details (a copy is
013: * included at /legal/license.txt).
014: *
015: * You should have received a copy of the GNU General Public License
016: * version 2 along with this work; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
018: * 02110-1301 USA
019: *
020: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
021: * Clara, CA 95054 or visit www.sun.com if you need additional
022: * information or have any questions.
023: */
024:
025: package java.nio;
026:
027: /**
028: * A <code>Buffer</code> storing <code>float</code> data.
029: */
030: class FloatBufferImpl extends FloatBuffer {
031:
032: FloatBufferImpl(ByteBufferImpl parent, int capacity, float[] array,
033: int arrayOffset, boolean isDirect) {
034: this .parent = parent;
035: this .isDirect = isDirect;
036: this .array = array;
037: this .arrayOffset = arrayOffset;
038: this .capacity = this .limit = capacity;
039: this .position = 0;
040: }
041:
042: public float get() {
043: if (position >= limit) {
044: throw new BufferUnderflowException();
045: }
046: return get(position++);
047: }
048:
049: public float get(int index) {
050: if (index < 0 || index >= limit) {
051: throw new IndexOutOfBoundsException();
052: }
053:
054: int bytePtr = arrayOffset + (index << 2);
055: if (isDirect) {
056: return ByteBufferImpl._getFloat(bytePtr);
057: } else if (array != null) {
058: return array[arrayOffset + index];
059: } else {
060: return parent.getFloat(bytePtr);
061: }
062: }
063:
064: public FloatBuffer put(float f) {
065: if (position >= limit) {
066: throw new BufferOverflowException();
067: }
068: return put(position++, f);
069: }
070:
071: public FloatBuffer put(int index, float f) {
072: if (index < 0 || index >= limit) {
073: throw new IndexOutOfBoundsException();
074: }
075:
076: int bytePtr = arrayOffset + (index << 2);
077: if (isDirect) {
078: ByteBufferImpl._putFloat(bytePtr, f);
079: } else if (array != null) {
080: array[arrayOffset + index] = f;
081: } else {
082: parent.putFloat(bytePtr, f);
083: }
084: return this ;
085: }
086:
087: public FloatBuffer slice() {
088: int pos = position;
089: if (isDirect) {
090: pos <<= 2;
091: }
092: return new FloatBufferImpl(parent, limit - position, array,
093: arrayOffset + pos, isDirect);
094: }
095:
096: public boolean isDirect() {
097: return isDirect;
098: }
099:
100: public int nativeAddress() {
101: return arrayOffset;
102: }
103:
104: // public String toString() {
105: // return "FloatBufferImpl[" +
106: // "parent=" + parent +
107: // ",array=" + array +
108: // ",arrayOffset=" + arrayOffset +
109: // ",capacity=" + capacity +
110: // ",limit=" + limit +
111: // ",position=" + position +
112: // ",isDirect=" + isDirect +
113: // ",disposed=" + disposed + "]";
114: // }
115:
116: public void dispose() {
117: // Need revisit
118: this .disposed = true;
119: }
120: }
|