com.badlogic.gdx.utils.reflect.ArrayReflection Java Examples
The following examples show how to use
com.badlogic.gdx.utils.reflect.ArrayReflection.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CircularBuffer.java From gdx-ai with Apache License 2.0 | 5 votes |
/** Creates a new backing array with the specified capacity containing the current items. * @param newCapacity the new capacity */ protected void resize (int newCapacity) { @SuppressWarnings("unchecked") T[] newItems = (T[])ArrayReflection.newInstance(items.getClass().getComponentType(), newCapacity); if (tail > head) { System.arraycopy(items, head, newItems, 0, size); } else if (size > 0) { // NOTE: when head == tail the buffer can be empty or full System.arraycopy(items, head, newItems, 0, items.length - head); System.arraycopy(items, 0, newItems, items.length - head, tail); } head = 0; tail = size; items = newItems; }
Example #2
Source File: Array.java From collider with Apache License 2.0 | 5 votes |
/** Creates a new backing array with the specified size containing the current items. */ protected T[] resize (int newSize) { T[] items = this.items; T[] newItems = (T[])ArrayReflection.newInstance(items.getClass().getComponentType(), newSize); System.arraycopy(items, 0, newItems, 0, Math.min(size, newItems.length)); this.items = newItems; return newItems; }
Example #3
Source File: Array.java From collider with Apache License 2.0 | 4 votes |
/** Creates a new array with {@link #items} of the specified type. * @param ordered If false, methods that remove elements may change the order of other elements in the array, which avoids a * memory copy. * @param capacity Any elements added beyond this will cause the backing array to be grown. */ public Array (boolean ordered, int capacity, Class arrayType) { this.ordered = ordered; items = (T[])ArrayReflection.newInstance(arrayType, capacity); }
Example #4
Source File: Array.java From collider with Apache License 2.0 | 4 votes |
public <V> V[] toArray (Class type) { V[] result = (V[])ArrayReflection.newInstance(type, size); System.arraycopy(items, 0, result, 0, size); return result; }