Class FastArray

java.lang.Object
org.codehaus.groovy.util.FastArray
All Implemented Interfaces:
Serializable, Cloneable

public class FastArray extends Object implements Cloneable, Serializable
Resizable object array optimized for append-heavy internal use and lightweight list views.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final FastArray
    Shared empty instance with zero capacity.
    int
    Number of populated elements in the backing array.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an empty array with the default initial capacity.
    FastArray(int initialCapacity)
    Creates an empty array with the specified initial capacity.
    FastArray(Object[] objects)
    Creates an array backed by the supplied object array.
    Creates an array containing the elements of the supplied collection.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Appends an element to the end of this array, growing the backing storage when needed.
    void
    addAll(Object[] newData, int size)
    Appends the first size elements from the supplied array.
    void
    addAll(List coll)
    Appends the contents of the supplied list.
    void
    addAll(FastArray newData)
    Appends the populated contents of another FastArray.
    void
    Removes all populated elements while preserving the current capacity.
    Returns a shallow copy with duplicated backing storage.
    Returns a copy containing the populated elements of this array.
    get(int index)
    Returns the element at the specified index.
    Returns the backing storage array.
    boolean
    Indicates whether this array contains any populated elements.
    void
    remove(int index)
    Removes the element at the specified index and compacts the populated range.
    void
    set(int index, Object o)
    Replaces the element stored at the specified index.
    int
    Returns the number of populated elements.
    Returns a list view of the populated elements.
    Returns a list-style string containing the populated elements.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • EMPTY_LIST

      public static final FastArray EMPTY_LIST
      Shared empty instance with zero capacity.
    • size

      public int size
      Number of populated elements in the backing array.
  • Constructor Details

    • FastArray

      public FastArray(int initialCapacity)
      Creates an empty array with the specified initial capacity.
      Parameters:
      initialCapacity - the initial storage size
    • FastArray

      public FastArray()
      Creates an empty array with the default initial capacity.
    • FastArray

      public FastArray(Collection c)
      Creates an array containing the elements of the supplied collection.
      Parameters:
      c - the values to copy
    • FastArray

      public FastArray(Object[] objects)
      Creates an array backed by the supplied object array.
      Parameters:
      objects - the backing storage containing the initial elements
  • Method Details

    • get

      public Object get(int index)
      Returns the element at the specified index.
      Parameters:
      index - the populated index to read
      Returns:
      the stored element
    • add

      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
    • set

      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
    • size

      public int size()
      Returns the number of populated elements.
      Returns:
      the logical size of this array
    • clear

      public void clear()
      Removes all populated elements while preserving the current capacity.
    • addAll

      public void addAll(FastArray newData)
      Appends the populated contents of another FastArray.
      Parameters:
      newData - the source array to append
    • addAll

      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
    • copy

      public FastArray copy()
      Returns a copy containing the populated elements of this array.
      Returns:
      a new FastArray with copied storage
    • isEmpty

      public boolean isEmpty()
      Indicates whether this array contains any populated elements.
      Returns:
      true if no elements are stored
    • addAll

      public void addAll(List coll)
      Appends the contents of the supplied list.
      Parameters:
      coll - the values to append
    • remove

      public void remove(int index)
      Removes the element at the specified index and compacts the populated range.
      Parameters:
      index - the populated index to remove
    • toList

      public List toList()
      Returns a list view of the populated elements.
      Returns:
      a list reflecting the current contents of this array
    • getArray

      public Object[] getArray()
      Returns the backing storage array.
      Returns:
      the underlying array, including unused slots
    • toString

      public String toString()
      Returns a list-style string containing the populated elements.
      Overrides:
      toString in class Object
      Returns:
      the string form of the populated contents
    • clone

      public FastArray clone()
      Returns a shallow copy with duplicated backing storage.
      Overrides:
      clone in class Object
      Returns:
      a cloned FastArray