From f9f881e59c78e3036cb3f956bc97cfc3197f620d Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Sat, 24 Aug 2013 03:14:14 +0200 Subject: *Ringbuffer: Remove Ringbuffer.AllocEmptyArray interface to favor a more simple approach; Split 'grow' into 'growEmpty' and 'growFull' - java.lang.reflect.Array can instantiate an array w/ a given array-type and length - array-type is Class - We either deduct the array-type via array.getClass(), or pass it (ctor for empty Ringbuffer). - Split 'growBuffer(T[] newElements, int amount, ..)' into: - 'growEmptyBuffer(T[] newElements)' - 'growFullBuffer(int amount)' Allowing a more clean API w/ simpler semantics. --- .../com/jogamp/common/util/RingBuffer01Base.java | 30 +++++++++++----------- .../com/jogamp/common/util/TestLFRingBuffer01.java | 10 ++------ .../jogamp/common/util/TestSyncRingBuffer01.java | 11 ++------ 3 files changed, 19 insertions(+), 32 deletions(-) (limited to 'src/junit') diff --git a/src/junit/com/jogamp/common/util/RingBuffer01Base.java b/src/junit/com/jogamp/common/util/RingBuffer01Base.java index 7ac94d4..f7e8fcf 100644 --- a/src/junit/com/jogamp/common/util/RingBuffer01Base.java +++ b/src/junit/com/jogamp/common/util/RingBuffer01Base.java @@ -36,7 +36,7 @@ import com.jogamp.common.util.Ringbuffer; public abstract class RingBuffer01Base { private static boolean DEBUG = false; - + public abstract Ringbuffer createEmpty(int initialCapacity); public abstract Ringbuffer createFull(Integer[] source); @@ -75,7 +75,7 @@ public abstract class RingBuffer01Base { Assert.assertTrue("Is full "+rb, !rb.isFull()); for(int i=0; i rbAllocIntArray = new Ringbuffer.AllocEmptyArray() { - @Override - public Integer[] newArray(int size) { - return new Integer[size]; - } - }; - private void test_GrowEmptyImpl(int initCapacity, int pos) { final int growAmount = 5; final int grownCapacity = initCapacity+growAmount; @@ -248,7 +241,7 @@ public abstract class RingBuffer01Base { if( DEBUG ) { rb.dump(System.err, "GrowEmpty["+pos+"].pre1"); } - rb.growBuffer(growArray, growAmount, rbAllocIntArray); + rb.growEmptyBuffer(growArray); if( DEBUG ) { rb.dump(System.err, "GrowEmpty["+pos+"].post"); } @@ -288,10 +281,6 @@ public abstract class RingBuffer01Base { private void test_GrowFullImpl(int initCapacity, int pos, boolean debug) { final int growAmount = 5; final int grownCapacity = initCapacity+growAmount; - final Integer[] growArray = new Integer[growAmount]; - for(int i=0; i rb = createFull(source); @@ -302,7 +291,7 @@ public abstract class RingBuffer01Base { if( DEBUG || debug ) { rb.dump(System.err, "GrowFull["+pos+"].pre1"); } - rb.growBuffer(growArray, growAmount, rbAllocIntArray); + rb.growFullBuffer(growAmount); if( DEBUG || debug ) { rb.dump(System.err, "GrowFull["+pos+"].post"); } @@ -312,11 +301,22 @@ public abstract class RingBuffer01Base { Assert.assertTrue("Is full "+rb, !rb.isFull()); Assert.assertTrue("Is empty "+rb, !rb.isEmpty()); + for(int i=0; i allocEmptyIntArray = new Ringbuffer.AllocEmptyArray() { - @Override - public Integer[] newArray(int size) { - return new Integer[size]; - } }; - public Ringbuffer createEmpty(int initialCapacity) { - return new LFRingbuffer(initialCapacity, allocEmptyIntArray); + return new LFRingbuffer(Integer[].class, initialCapacity); } public Ringbuffer createFull(Integer[] source) { - return new LFRingbuffer(source, allocEmptyIntArray); + return new LFRingbuffer(source); } public static void main(String args[]) { diff --git a/src/junit/com/jogamp/common/util/TestSyncRingBuffer01.java b/src/junit/com/jogamp/common/util/TestSyncRingBuffer01.java index bc9284b..b598f15 100644 --- a/src/junit/com/jogamp/common/util/TestSyncRingBuffer01.java +++ b/src/junit/com/jogamp/common/util/TestSyncRingBuffer01.java @@ -32,18 +32,11 @@ import com.jogamp.common.util.Ringbuffer; import com.jogamp.common.util.SyncedRingbuffer; public class TestSyncRingBuffer01 extends RingBuffer01Base { - - static final Ringbuffer.AllocEmptyArray allocEmptyIntArray = new Ringbuffer.AllocEmptyArray() { - @Override - public Integer[] newArray(int size) { - return new Integer[size]; - } }; - public Ringbuffer createEmpty(int initialCapacity) { - return new SyncedRingbuffer(initialCapacity, allocEmptyIntArray); + return new SyncedRingbuffer(Integer[].class, initialCapacity); } public Ringbuffer createFull(Integer[] source) { - return new SyncedRingbuffer(source, allocEmptyIntArray); + return new SyncedRingbuffer(source); } public static void main(String args[]) { -- cgit v1.2.3