public abstract class ArrayFactory extends Object
This class holds factories to produces arrays of variable length.
It allows for object recycling, pre-allocation and stack allocations:[code]
// 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
| Modifier and Type | Field and Description |
|---|---|
static ArrayFactory |
BOOLEANS_FACTORY
Holds factory for
boolean arrays. |
static ArrayFactory |
BYTES_FACTORY
Holds factory for
byte arrays. |
static ArrayFactory |
CHARS_FACTORY
Holds factory for
char arrays. |
static ArrayFactory |
DOUBLES_FACTORY
Holds factory for
double arrays. |
static ArrayFactory |
FLOATS_FACTORY
Holds factory for
float arrays. |
static ArrayFactory |
INTS_FACTORY
Holds factory for
int arrays. |
static ArrayFactory |
LONGS_FACTORY
Holds factory for
long arrays. |
static ArrayFactory |
OBJECTS_FACTORY
Holds factory for generic
Object arrays. |
static ArrayFactory |
SHORTS_FACTORY
Holds factory for
short arrays. |
| Constructor and Description |
|---|
ArrayFactory()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
Object |
array(int capacity)
Returns an array possibly recycled or preallocated of specified
minimum size.
|
protected abstract Object |
create(int size)
Constructs a new array of specified size from this factory
(using the
new keyword). |
void |
recycle(Object array)
Recycles the specified arrays.
|
public static final ArrayFactory BOOLEANS_FACTORY
boolean arrays.public static final ArrayFactory BYTES_FACTORY
byte arrays.public static final ArrayFactory CHARS_FACTORY
char arrays.public static final ArrayFactory SHORTS_FACTORY
short arrays.public static final ArrayFactory INTS_FACTORY
int arrays.public static final ArrayFactory LONGS_FACTORY
long arrays.public static final ArrayFactory FLOATS_FACTORY
float arrays.public static final ArrayFactory DOUBLES_FACTORY
double arrays.public static final ArrayFactory OBJECTS_FACTORY
Object arrays.public final Object array(int capacity)
capacity - the minimum size of the array to be returned.public void recycle(Object array)
array - the array to be recycled.protected abstract Object create(int size)
new keyword).size - the size of the array.Copyright © 2005–2024 Javolution. All rights reserved.