From 8b3e5b94bcd3167278eb972b2be37086d3bd2996 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 31 Dec 2012 14:52:36 +0100 Subject: PrimitiveStack: Add 'void position(int)' to set new position. Add test case w/ initialSizeElem:=0. --- src/java/com/jogamp/common/util/FloatStack.java | 10 ++- .../com/jogamp/common/util/PrimitiveStack.java | 18 +++-- .../com/jogamp/common/util/TestFloatStack01.java | 78 ++++++++++++++++------ 3 files changed, 79 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/java/com/jogamp/common/util/FloatStack.java b/src/java/com/jogamp/common/util/FloatStack.java index e5790a9..2addd76 100644 --- a/src/java/com/jogamp/common/util/FloatStack.java +++ b/src/java/com/jogamp/common/util/FloatStack.java @@ -62,6 +62,14 @@ public class /*name*/FloatStack/*name*/ implements PrimitiveStack { @Override public final int position() { return position; } + @Override + public final void position(int newPosition) throws IndexOutOfBoundsException { + if( 0 > position || position >= buffer.length ) { + throw new IndexOutOfBoundsException("Invalid new position "+newPosition+", "+this.toString()); + } + position = newPosition; + } + @Override public final int remaining() { return buffer.length - position; } @@ -72,7 +80,7 @@ public class /*name*/FloatStack/*name*/ implements PrimitiveStack { public final void setGrowSize(int newGrowSize) { growSize = newGrowSize; } public final String toString() { - return "FloatStack[0..(top "+position+").."+buffer.length+", remaining "+remaining()+"]"; + return "FloatStack[0..(pos "+position+").."+buffer.length+", remaining "+remaining()+"]"; } public final /*value*/float/*value*/[] buffer() { return buffer; } diff --git a/src/java/com/jogamp/common/util/PrimitiveStack.java b/src/java/com/jogamp/common/util/PrimitiveStack.java index 23447e3..89ae72e 100644 --- a/src/java/com/jogamp/common/util/PrimitiveStack.java +++ b/src/java/com/jogamp/common/util/PrimitiveStack.java @@ -41,16 +41,24 @@ public interface PrimitiveStack { int capacity(); /** - * Returns the current position where the next put operation will store the next element. + * Returns the current position of this stack. *

- * The position equals to the number of elements already stored. + * Position is in the range: 0 ≤ position < {@link #capacity()}. *

- *

- * 0 denotes an empty stack. + *

+ * The position equals to the number of elements stored. *

**/ int position(); + /** + * Sets the position of this stack. + * + * @param newPosition the new position + * @throws IndexOutOfBoundsException if newPosition is outside of range: 0 ≤ position < {@link #capacity()}. + */ + void position(int newPosition) throws IndexOutOfBoundsException; + /** * Returns the remaining elements left before stack will grow about {@link #getGrowSize()}. *
@@ -68,5 +76,5 @@ public interface PrimitiveStack {
     int getGrowSize();
 
     /** Set new {@link #growSize(). */
-    void setGrowSize(int newGrowSize);
+    void setGrowSize(int newGrowSize);    
 }
diff --git a/src/junit/com/jogamp/common/util/TestFloatStack01.java b/src/junit/com/jogamp/common/util/TestFloatStack01.java
index 0a2b077..90ac2e0 100644
--- a/src/junit/com/jogamp/common/util/TestFloatStack01.java
+++ b/src/junit/com/jogamp/common/util/TestFloatStack01.java
@@ -51,15 +51,28 @@ public class /*testname*/TestFloatStack01/*testname*/ extends JunitTracer {
     
     
     @Test
-    public void test01PrimitiveArray() {
+    public void test01PrimitiveArray_I32_G02() {
+        final int initialSizeElem = 32;
+        final int growSizeElem = 2;
+        testPrimitiveArrayImpl(initialSizeElem, growSizeElem);
+    }
+    
+    @Test
+    public void test02PrimitiveArray_I00_G32() {
+        final int initialSizeElem = 0;
+        final int growSizeElem = 32;
+        testPrimitiveArrayImpl(initialSizeElem, growSizeElem);
+    }
+    
+    static private final boolean VERBOSE = false;
+    
+    private void testPrimitiveArrayImpl(int initialSizeElem, int growSizeElem) {
         final int compNum  = 3; 
         /*value*/float/*value*/[] e0 = 
                 new /*value*/float/*value*/[] { 0, 1, 2 };
         /*value*/float/*value*/[] e1 = 
                 new /*value*/float/*value*/[] { 3, 4, 5 };
         
-        final int initialSizeElem = 32;
-        final int growSizeElem = 2;
         final int totalSizeElem = initialSizeElem+2*growSizeElem;
         
         final int initialSizeComp = initialSizeElem*compNum;
@@ -72,27 +85,38 @@ public class /*testname*/TestFloatStack01/*testname*/ extends JunitTracer {
         //
         // PUT
         //
-        
+        if(VERBOSE) {
+            System.err.println("0: "+fs0);
+        }
         for(int i=0; i