|
J avolution v5.2 (J2SE 1.5+) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavolution.context.ArrayFactory<T>
public abstract class ArrayFactory<T>
This class holds factories to produces arrays of variable length.
It allows for object recycling, pre-allocation and stack
allocations:
// Primitive types.
char[] buffer = ArrayFactory.CHARS_FACTORY.array(1024); // Possibly recycled.
for (int i = reader.read(buffer, 0, buffer.length); i > 0;) {
...
}
ArrayFactory.CHARS_FACTORY.recycle(buffer); //
// Custom types.
static ArrayFactory<Vertex[]> VERTICES_FACTORY = new ArrayFactory<Vertex[]> {
protected Vertex[] create(int size) {
return new Vertex[size];
}
};
...
Vertex[] vertices = VERTICES_FACTORY.array(256);
Field Summary | |
---|---|
static ArrayFactory<boolean[]> |
BOOLEANS_FACTORY
Holds factory for boolean arrays. |
static ArrayFactory<byte[]> |
BYTES_FACTORY
Holds factory for byte arrays. |
static ArrayFactory<char[]> |
CHARS_FACTORY
Holds factory for char arrays. |
static ArrayFactory<double[]> |
DOUBLES_FACTORY
|
static ArrayFactory<float[]> |
FLOATS_FACTORY
|
static ArrayFactory<int[]> |
INTS_FACTORY
Holds factory for int arrays. |
static ArrayFactory<long[]> |
LONGS_FACTORY
Holds factory for long arrays. |
static ArrayFactory<java.lang.Object[]> |
OBJECTS_FACTORY
Holds factory for generic Object arrays. |
static ArrayFactory<short[]> |
SHORTS_FACTORY
Holds factory for short arrays. |
Constructor Summary | |
---|---|
ArrayFactory()
Default constructor. |
Method Summary | |
---|---|
T |
array(int capacity)
Returns an array possibly recycled or preallocated of specified minimum size. |
protected abstract T |
create(int size)
Constructs a new array of specified size from this factory (using the new keyword). |
void |
recycle(T array)
Recycles the specified arrays. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final ArrayFactory<boolean[]> BOOLEANS_FACTORY
boolean
arrays.
public static final ArrayFactory<byte[]> BYTES_FACTORY
byte
arrays.
public static final ArrayFactory<char[]> CHARS_FACTORY
char
arrays.
public static final ArrayFactory<short[]> SHORTS_FACTORY
short
arrays.
public static final ArrayFactory<int[]> INTS_FACTORY
int
arrays.
public static final ArrayFactory<long[]> LONGS_FACTORY
long
arrays.
public static final ArrayFactory<float[]> FLOATS_FACTORY
public static final ArrayFactory<double[]> DOUBLES_FACTORY
public static final ArrayFactory<java.lang.Object[]> OBJECTS_FACTORY
Object
arrays.
Constructor Detail |
---|
public ArrayFactory()
Method Detail |
---|
public final T array(int capacity)
capacity
- the minimum size of the array to be returned.
public void recycle(T array)
array
- the array to be recycled.protected abstract T create(int size)
new
keyword).
size
- the size of the array.
|
J avolution v5.2 (J2SE 1.5+) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |