From f65d7a7987ae4b30ef38069b3dffefa4441403f8 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Tue, 12 Jan 2010 18:02:50 +0100 Subject: fixed off-by-one bug in put and get. implemented method chaining pattern. added position(int pos) method. --- .../sun/gluegen/runtime/PointerBuffer.java.javame_cdc_fp | 15 ++++++++++++--- .../com/sun/gluegen/runtime/PointerBuffer.java.javase | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javame_cdc_fp b/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javame_cdc_fp index 4ab666c..0ec54d0 100755 --- a/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javame_cdc_fp +++ b/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javame_cdc_fp @@ -63,6 +63,14 @@ public class PointerBuffer { return position; } + public final PointerBuffer position(int newPos) { + if(0>newPos || newPos>=capacity) { + throw new IndexOutOfBoundsException(); + } + position = newPos; + return this; + } + public final int remaining() { return capacity - position; } @@ -71,8 +79,9 @@ public class PointerBuffer { return position < capacity; } - public final void rewind() { + public final PointerBuffer rewind() { position=0; + return this; } int arrayOffset() { return 0; } @@ -139,7 +148,7 @@ public class PointerBuffer { } public long get() { - long r = get(position+1); + long r = get(position); position++; return r; } @@ -163,7 +172,7 @@ public class PointerBuffer { } public PointerBuffer put(long v) { - put(position+1, v); + put(position, v); position++; return this; } diff --git a/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javase b/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javase index 4957b17..6d0029e 100755 --- a/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javase +++ b/src/java/com/sun/gluegen/runtime/PointerBuffer.java.javase @@ -63,6 +63,14 @@ public class PointerBuffer { return position; } + public final PointerBuffer position(int newPos) { + if(0>newPos || newPos>=capacity) { + throw new IndexOutOfBoundsException(); + } + position = newPos; + return this; + } + public final int remaining() { return capacity - position; } @@ -71,8 +79,9 @@ public class PointerBuffer { return position < capacity; } - public final void rewind() { + public final PointerBuffer rewind() { position=0; + return this; } int arrayOffset() { return 0; } @@ -133,7 +142,7 @@ public class PointerBuffer { } public long get() { - long r = get(position+1); + long r = get(position); position++; return r; } @@ -148,7 +157,7 @@ public class PointerBuffer { } public PointerBuffer put(long v) { - put(position+1, v); + put(position, v); position++; return this; } -- cgit v1.2.3