Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.2 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javolution.context
Class ArrayFactory<T>

    java.lang.Object
      javolution.context.ArrayFactory<T>

    public abstract class ArrayFactory<T>

extends java.lang.Object

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);

Version:
  5.0, May 5, 2007
Author:
  Jean-Marie Dautelle

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

### BOOLEANS_FACTORY

    public static final ArrayFactory<boolean[]> BOOLEANS_FACTORY

  Holds factory for `boolean` arrays.

### BYTES_FACTORY

    public static final ArrayFactory<byte[]> BYTES_FACTORY

  Holds factory for `byte` arrays.

### CHARS_FACTORY

    public static final ArrayFactory<char[]> CHARS_FACTORY

  Holds factory for `char` arrays.

### SHORTS_FACTORY

    public static final ArrayFactory<short[]> SHORTS_FACTORY

  Holds factory for `short` arrays.

### INTS_FACTORY

    public static final ArrayFactory<int[]> INTS_FACTORY

  Holds factory for `int` arrays.

### LONGS_FACTORY

    public static final ArrayFactory<long[]> LONGS_FACTORY

  Holds factory for `long` arrays.

### FLOATS_FACTORY

    public static final ArrayFactory<float[]> FLOATS_FACTORY

### DOUBLES_FACTORY

    public static final ArrayFactory<double[]> DOUBLES_FACTORY

### OBJECTS_FACTORY

    public static final ArrayFactory<java.lang.Object[]> OBJECTS_FACTORY

  Holds factory for generic `Object` arrays.

Constructor Detail

### ArrayFactory

    public ArrayFactory()

  Default constructor.

Method Detail

### array

    public final T array(int capacity)

  Returns an array possibly recycled or preallocated of specified minimum size.

  Parameters:
    `capacity` - the minimum size of the array to be returned.
  Returns:
    a recycled, pre-allocated or new factory array.

### recycle

    public void recycle(T array)

  Recycles the specified arrays.

  Parameters:
    `array` - the array to be recycled.

### create

    protected abstract T create(int size)

  Constructs a new array of specified size from this factory (using the `new` keyword).

  Parameters:
    `size` - the size of the array.
  Returns:
    a new factory array.

Overview | Package | Class | Tree | Deprecated | Index | Help
| J avolution v5.2 (J2SE 1.5+)
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005 - 2007 Javolution.