Package: org.codehaus.groovy.util

## [Java] Class FastArray

- org.codehaus.groovy.util.FastArray

- All Implemented Interfaces and Traits:
    Cloneable, Serializable

      public class FastArray
      extends Object
      implements Cloneable, Serializable

  Resizable object array optimized for append-heavy internal use and lightweight list views.

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static FastArray` | `EMPTY_LIST` | Shared empty instance with zero capacity.
    `int` | `size` | Number of populated elements in the backing array.

  - ### Constructor Summary

    Constructors
    Constructor and description
    `FastArray(int initialCapacity)` Creates an empty array with the specified initial capacity.
    `FastArray()` Creates an empty array with the default initial capacity.
    `FastArray(Collection c)` Creates an array containing the elements of the supplied collection.
    `FastArray(Object[] objects)` Creates an array backed by the supplied object array.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `add(Object o)` Appends an element to the end of this array, growing the backing storage when needed.
    `` | `public void` | `addAll(FastArray newData)` Appends the populated contents of another `FastArray`.
    `` | `public void` | `addAll(Object[] newData, int size)` Appends the first `size` elements from the supplied array.
    `` | `public void` | `addAll(List coll)` Appends the contents of the supplied list.
    `` | `public void` | `clear()` Removes all populated elements while preserving the current capacity.
    `` | `public FastArray` | `clone()` Returns a shallow copy with duplicated backing storage.
    `` | `public FastArray` | `copy()` Returns a copy containing the populated elements of this array.
    `` | `public Object` | `get(int index)` Returns the element at the specified index.
    `` | `public Object[]` | `getArray()` Returns the backing storage array.
    `` | `public boolean` | `isEmpty()` Indicates whether this array contains any populated elements.
    `` | `public void` | `remove(int index)` Removes the element at the specified index and compacts the populated range.
    `` | `public void` | `set(int index, Object o)` Replaces the element stored at the specified index.
    `` | `public int` | `size()` Returns the number of populated elements.
    `` | `public List` | `toList()` Returns a list view of the populated elements.
    `` | `public String` | `toString()` Returns a list-style string containing the populated elements.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### public static final FastArray EMPTY_LIST

      Shared empty instance with zero capacity.

    - #### public int size

      Number of populated elements in the backing array.

  - ### Constructor Detail

    - #### public FastArray(int initialCapacity)

      Creates an empty array with the specified initial capacity.

      Parameters:
        `initialCapacity` - the initial storage size

    - #### public FastArray()

      Creates an empty array with the default initial capacity.

    - #### public FastArray(Collection c)

      Creates an array containing the elements of the supplied collection.

      Parameters:
        `c` - the values to copy

    - #### public FastArray(Object[] objects)

      Creates an array backed by the supplied object array.

      Parameters:
        `objects` - the backing storage containing the initial elements

  - ### Method Detail

    - #### public void add(Object o)

      Appends an element to the end of this array, growing the backing storage when needed.

      Parameters:
        `o` - the element to append

    - #### public void addAll(FastArray newData)

      Appends the populated contents of another `FastArray`.

      Parameters:
        `newData` - the source array to append

    - #### public void addAll(Object[] newData, int size)

      Appends the first `size` elements from the supplied array.

      Parameters:
        `newData` - the source storage
        `size` - the number of elements to append

    - #### public void addAll(List coll)

      Appends the contents of the supplied list.

      Parameters:
        `coll` - the values to append

    - #### public void clear()

      Removes all populated elements while preserving the current capacity.

    - #### public FastArray clone()

      Returns a shallow copy with duplicated backing storage.

      Returns:
        a cloned `FastArray`

    - #### public FastArray copy()

      Returns a copy containing the populated elements of this array.

      Returns:
        a new `FastArray` with copied storage

    - #### public Object get(int index)

      Returns the element at the specified index.

      Parameters:
        `index` - the populated index to read
      Returns:
        the stored element

    - #### public Object[] getArray()

      Returns the backing storage array.

      Returns:
        the underlying array, including unused slots

    - #### public boolean isEmpty()

      Indicates whether this array contains any populated elements.

      Returns:
        `true` if no elements are stored

    - #### public void remove(int index)

      Removes the element at the specified index and compacts the populated range.

      Parameters:
        `index` - the populated index to remove

    - #### public void set(int index, Object o)

      Replaces the element stored at the specified index.

      Parameters:
        `index` - the populated index to update
        `o` - the replacement element

    - #### public int size()

      Returns the number of populated elements.

      Returns:
        the logical size of this array

    - #### public List toList()

      Returns a list view of the populated elements.

      Returns:
        a list reflecting the current contents of this array

    - #### public String toString()

      Returns a list-style string containing the populated elements.

      Returns:
        the string form of the populated contents