28package com.jogamp.common.util;
30import java.nio.BufferOverflowException;
31import java.nio.BufferUnderflowException;
32import java.nio.FloatBuffer;
45 private float[] buffer;
53 public FloatStack(
final int initialSize,
final int growSize) {
55 this.growSize = growSize;
56 this.buffer =
new float[initialSize];
60 public final int capacity() {
return buffer.length; }
66 public final void position(
final int newPosition)
throws IndexOutOfBoundsException {
67 if( 0 > position || position >= buffer.length ) {
68 throw new IndexOutOfBoundsException(
"Invalid new position "+newPosition+
", "+this.
toString());
70 position = newPosition;
74 public final int remaining() {
return buffer.length - position; }
80 public final void setGrowSize(
final int newGrowSize) { growSize = newGrowSize; }
84 return "FloatStack[0..(pos "+position+
").."+buffer.length+
", remaining "+
remaining()+
"]";
89 private final void growIfNecessary(
final int length)
throws IndexOutOfBoundsException {
90 if( position + length > buffer.length ) {
92 throw new IndexOutOfBoundsException(
"Out of fixed stack size: "+
this);
94 final float[] newBuffer =
95 new float[buffer.length + growSize];
96 System.arraycopy(buffer, 0, newBuffer, 0, position);
111 putOnTop(
final float[] src,
final int srcOffset,
final int length)
throws IndexOutOfBoundsException {
112 growIfNecessary(length);
113 System.arraycopy(src, srcOffset, buffer, position, length);
127 public final FloatBuffer
128 putOnTop(
final FloatBuffer src,
final int length)
throws IndexOutOfBoundsException, BufferUnderflowException {
129 growIfNecessary(length);
130 src.get(buffer, position, length);
145 getFromTop(
final float[] dest,
final int destOffset,
final int length)
throws IndexOutOfBoundsException {
146 System.arraycopy(buffer, position-length, dest, destOffset, length);
160 public final FloatBuffer
161 getFromTop(
final FloatBuffer dest,
final int length)
throws IndexOutOfBoundsException, BufferOverflowException {
162 dest.put(buffer, position-length, length);
Simple primitive-type stack.
final int capacity()
Returns this stack's current capacity.
final int remaining()
Returns the remaining elements left before stack will grow about getGrowSize().
final void position(final int newPosition)
Sets the position of this stack.
final FloatBuffer putOnTop(final FloatBuffer src, final int length)
FILO put operation.
final float[] getFromTop(final float[] dest, final int destOffset, final int length)
FILO get operation.
final int getGrowSize()
Returns the grow size.
final FloatBuffer getFromTop(final FloatBuffer dest, final int length)
FILO get operation.
final float[] putOnTop(final float[] src, final int srcOffset, final int length)
FILO put operation.
final int position()
Returns the current position of this stack.
final void setGrowSize(final int newGrowSize)
Set new growSize().
Simple primitive-type stack.