public RecyclingArrayList(Class<T> clazz) { this(DEFAULT_INITIAL_SIZE, GenericTypeBuilder.createBuilderWithEmptyConstructor(clazz)); }
private void fillElementDataIfNeeded() { for (int i = 0; i < elementData.length; i++) { if (elementData[i] == null) elementData[i] = builder.newInstance(); } }
public CommandArrayDeque(int numElements, Class<C> commandClass) { super(numElements); commandBuilder = GenericTypeBuilder.createBuilderWithEmptyConstructor(commandClass); unusedCommands = new ArrayDeque<>(numElements); for (int i = 0; i < numElements; i++) unusedCommands.add(commandBuilder.newInstance()); }
public RecyclingQuadrantDependentList(Class<V> clazz) { quadrantDependentList = new QuadrantDependentList<>(); builder = GenericTypeBuilder.createBuilderWithEmptyConstructor(clazz); elementStorageForWhenNull = (V[]) Array.newInstance(clazz, 4); for (int i = 0; i < 4; i++) { V newInstance = builder.newInstance(); elementStorageForWhenNull[i] = newInstance; } valueArrays = (V[][]) new Object[5][]; valueArrays[0] = (V[]) Array.newInstance(clazz, 0); valueArrays[1] = (V[]) Array.newInstance(clazz, 1); valueArrays[2] = (V[]) Array.newInstance(clazz, 2); valueArrays[3] = (V[]) Array.newInstance(clazz, 3); valueArrays[4] = (V[]) elementStorageForWhenNull; }
private C getOrCreateUnusedCommand() { if (unusedCommands.isEmpty()) return commandBuilder.newInstance(); else return unusedCommands.poll(); }
public RecyclingArrayList(int initialSize, Class<T> clazz) { this(initialSize, GenericTypeBuilder.createBuilderWithEmptyConstructor(clazz)); }
protected void ensureCapacity(int minCapacity) { if (minCapacity <= elementData.length) return; int previousArraySize = elementData.length; int newArraySize = previousArraySize + (previousArraySize >> 1); if (newArraySize - minCapacity < 0) newArraySize = minCapacity; if (newArraySize - MAX_ARRAY_SIZE > 0) newArraySize = checkWithMaxCapacity(minCapacity); elementData = Arrays.copyOf(elementData, newArraySize); for (int i = previousArraySize; i < newArraySize; i++) { elementData[i] = builder.newInstance(); } }