diff options
author | Sven Gothel <[email protected]> | 2013-08-24 03:14:14 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-08-24 03:14:14 +0200 |
commit | f9f881e59c78e3036cb3f956bc97cfc3197f620d (patch) | |
tree | 9362ac0e063eb48ed7c563d0ad83953bc828ed9b /src/java/com/jogamp/common/util/Ringbuffer.java | |
parent | 30475c6bbeb9a5d48899b281ead8bb305679028d (diff) |
*Ringbuffer: Remove Ringbuffer<T>.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<? extends T[]>
- 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.
Diffstat (limited to 'src/java/com/jogamp/common/util/Ringbuffer.java')
-rw-r--r-- | src/java/com/jogamp/common/util/Ringbuffer.java | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/src/java/com/jogamp/common/util/Ringbuffer.java b/src/java/com/jogamp/common/util/Ringbuffer.java index 733a235..e524768 100644 --- a/src/java/com/jogamp/common/util/Ringbuffer.java +++ b/src/java/com/jogamp/common/util/Ringbuffer.java @@ -44,18 +44,6 @@ import java.io.PrintStream; */ public interface Ringbuffer<T> { - /** - * Implementation hook for {@link #growBuffer(Object[], int, AllocEmptyArray)} - * to pass an implementation of {@link #newArray(int)}. - * @param <T> type of array - */ - public static interface AllocEmptyArray<T> { - /** - * Returns a new allocated empty array of generic type T with given size. - */ - public T[] newArray(int size); - } - /** Returns a short string representation incl. size/capacity and internal r/w index (impl. dependent). */ public String toString(); @@ -190,25 +178,28 @@ public interface Ringbuffer<T> { public void waitForFreeSlots(int count) throws InterruptedException; /** - * Grows a full or empty ring buffer, increasing it's capacity about the amount. + * Grows an empty ring buffer, increasing it's capacity about the amount. * <p> * Growing an empty ring buffer increases it's size about the amount, i.e. renders it not empty. * The new elements are inserted at the read position, able to be read out via {@link #get()} etc. * </p> + * + * @param newElements array of new full elements the empty buffer shall grow about. + * @throws IllegalStateException if buffer is not empty + * @throws IllegalArgumentException if newElements is null + */ + public void growEmptyBuffer(T[] newElements) throws IllegalStateException, IllegalArgumentException; + + /** + * Grows a full ring buffer, increasing it's capacity about the amount. * <p> * Growing a full ring buffer leaves the size intact, i.e. renders it not full. - * The new elements are inserted at the write position, able to be written to via {@link #put(Object)} etc. + * New <code>null</code> elements are inserted at the write position, able to be written to via {@link #put(Object)} etc. * </p> - * - * @param newElements array of new empty elements the buffer shall grow about, maybe <code>null</code>. - * If not <code>null</code>, array size must be <= <code>amount</code> * @param amount the amount of elements the buffer shall grow about - * @param allocEmptyArray implementation hook to allocate a new empty array of generic type T - * @throws IllegalStateException if buffer is neither full nor empty - * @throws IllegalArgumentException if newElements is given but is > amount + * + * @throws IllegalStateException if buffer is not full + * @throws IllegalArgumentException if amount is < 0 */ - public void growBuffer(T[] newElements, int amount, - AllocEmptyArray<T> allocEmptyArray) throws IllegalStateException, - IllegalArgumentException; - + public void growFullBuffer(int amount) throws IllegalStateException, IllegalArgumentException; }
\ No newline at end of file |