28package com.jogamp.common.util;
30import java.nio.BufferOverflowException;
31import java.nio.BufferUnderflowException;
32import java.nio.IntBuffer;
55 this.growSize = growSize;
56 this.buffer =
new int[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 "IntegerStack[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 int[] newBuffer =
95 new int[buffer.length + growSize];
96 System.arraycopy(buffer, 0, newBuffer, 0, position);
111 putOnTop(
final int[] src,
final int srcOffset,
final int length)
throws IndexOutOfBoundsException {
112 growIfNecessary(length);
113 System.arraycopy(src, srcOffset, buffer, position, length);
127 public final IntBuffer
128 putOnTop(
final IntBuffer src,
final int length)
throws IndexOutOfBoundsException, BufferUnderflowException {
129 growIfNecessary(length);
130 src.get(buffer, position, length);
145 getFromTop(
final int[] dest,
final int destOffset,
final int length)
throws IndexOutOfBoundsException {
146 System.arraycopy(buffer, position-length, dest, destOffset, length);
160 public final IntBuffer
161 getFromTop(
final IntBuffer dest,
final int length)
throws IndexOutOfBoundsException, BufferOverflowException {
162 dest.put(buffer, position-length, length);
Simple primitive-type stack.
final int[] putOnTop(final int[] src, final int srcOffset, final int length)
FILO put operation.
final IntBuffer putOnTop(final IntBuffer src, final int length)
FILO put operation.
final IntBuffer getFromTop(final IntBuffer dest, final int length)
FILO get operation.
final int capacity()
Returns this stack's current capacity.
final int position()
Returns the current position of this stack.
final int remaining()
Returns the remaining elements left before stack will grow about getGrowSize().
final int getGrowSize()
Returns the grow size.
final int[] getFromTop(final int[] dest, final int destOffset, final int length)
FILO get operation.
final void position(final int newPosition)
Sets the position of this stack.
final void setGrowSize(final int newGrowSize)
Set new growSize().
Simple primitive-type stack.