org.apache.lucene.facet.search

## Class ArraysPool

- java.lang.Object
- - org.apache.lucene.facet.search.ArraysPool

    public final class ArraysPool
    extends Object

A thread-safe pool of `int[]` and `float[]` arrays. One specifies the maximum number of arrays in the constructor. Calls to `allocateFloatArray()` or `allocateIntArray()` take an array from the pool, and if one is not available, allocate a new one. When you are done using the array, you should `free` it.

This class is used by `ReusingFacetArrays` for temporal facet aggregation arrays, which can be reused across searches instead of being allocated afresh on every search.

WARNING: This API is experimental and might change in incompatible ways in the next release.

### Field Summary

Fields
`int` `arrayLength`

### Constructor Summary

Constructors
Constructor and Description
`ArraysPool(int arrayLength, int maxArrays)` Specifies the max number of arrays to pool, as well as the length of each array to allocate.

### Method Summary

Methods
`float[]` `allocateFloatArray()` Allocates a new `float[]`.
`int[]` `allocateIntArray()` Allocates a new `int[]`.
`void` `free(float[] arr)` Frees a no-longer-needed array.
`void` `free(int[] arr)` Frees a no-longer-needed array.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### arrayLength

    public final int arrayLength

### Constructor Detail

#### ArraysPool

    public ArraysPool(int arrayLength,
              int maxArrays)

Specifies the max number of arrays to pool, as well as the length of each array to allocate.

Parameters:
  `arrayLength` - the size of the arrays to allocate
  `maxArrays` - the maximum number of arrays to pool, from each type
Throws:
  `IllegalArgumentException` - if maxArrays is set to 0.

### Method Detail

#### allocateIntArray

    public final int[] allocateIntArray()

Allocates a new `int[]`. If there's an available array in the pool, it is used, otherwise a new array is allocated.

#### allocateFloatArray

    public final float[] allocateFloatArray()

Allocates a new `float[]`. If there's an available array in the pool, it is used, otherwise a new array is allocated.

#### free

    public final void free(int[] arr)

Frees a no-longer-needed array. If there's room in the pool, the array is added to it, otherwise discarded.

#### free

    public final void free(float[] arr)

Frees a no-longer-needed array. If there's room in the pool, the array is added to it, otherwise discarded.