All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jbox2d.pooling.MutableStack.orig Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
package org.jbox2d.pooling;

public abstract class MutableStack {

	private E[] stack;
	private int index;
	private int size;
	
	public MutableStack(){
		index = 0;
		size = 0;
	}
	
	protected void initStack(int argSize){
		index = argSize - 1; size = argSize;
		stack = createArray(argSize, null);
	}
	
	protected abstract E[] createArray(int argSize, E[] argOld);
	
	public final E pop(){
		if(index >= size){
			stack = createArray(size*2, stack);
			size = stack.length;
		}
		return stack[index++];
	}
	
	public final void push(E argObject){
		assert(index > 0);
		stack[--index] = argObject;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy