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 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/junit/com/jogamp/common/util/RingBuffer01Base.java') 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