com.artemis.ComponentPool Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of artemis-odb Show documentation
Show all versions of artemis-odb Show documentation
Fork of Artemis Entity System Framework.
package com.artemis;
import com.artemis.utils.Bag;
import com.artemis.utils.reflect.ClassReflection;
import com.artemis.utils.reflect.ReflectionException;
public class ComponentPool {
private final Bag cache;
private Class type;
ComponentPool(Class type) {
this.type = type;
cache = new Bag(type);
}
@SuppressWarnings("unchecked")
T obtain() {
try {
return (T) ((cache.size() > 0)
? cache.removeLast()
: ClassReflection.newInstance(type));
} catch (ReflectionException e) {
throw new InvalidComponentException(type, e.getMessage(), e);
}
}
void free(T component) {
component.reset();
cache.add(component);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy