Package org.zkoss.util

## Class FastReadArray<T>

- java.lang.Object
- - org.zkoss.util.FastReadArray<T>

- All Implemented Interfaces:
    `java.io.Serializable`, `java.lang.Cloneable`

      public class FastReadArray<T>
      extends java.lang.Object
      implements java.io.Serializable, java.lang.Cloneable

  An array of objects that are fast to read but a bit slower to add and remove.

  It is thread-safe.

  Typical use:

      Object[] ary = fra.toArray();
      for (int j = 0; j < ary.length; ++j)
        <i>whatever</i>;

  Since:
    3.0.6
  Author:
    tomyeh
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `FastReadArray​(java.lang.Class<?> klass)` | Constructs an array of the specified class.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `add​(T val)` | Adds an object.
    `void` | `clear()` | Removes all of the elements for this array.
    `java.lang.Object` | `clone()` |
    `boolean` | `equals​(java.lang.Object o)` |
    `int` | `hashCode()` |
    `boolean` | `isEmpty()` | Returns if it is empty.
    `boolean` | `remove​(T val)` | Removes an object.
    `boolean` | `removeBy​(java.lang.Comparable val, boolean atMostOne)` | Removes the object(s) that matches the specified condition.
    `int` | `size()` | Returns the size.
    `T[]` | `toArray()` | Returns the array (never null).
    `java.lang.String` | `toString()` |

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

      `finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### FastReadArray

          public FastReadArray​(java.lang.Class<?> klass)

      Constructs an array of the specified class.

  - ### Method Detail

    - #### toArray

          public T[] toArray()

      Returns the array (never null). To read, you shall store the return value in a local variable and then iterate thru it.

      Note: the return array is readonly. Don't modify the value of any element.

    - #### isEmpty

          public boolean isEmpty()

      Returns if it is empty.

    - #### size

          public int size()

      Returns the size.

    - #### clear

          public void clear()

      Removes all of the elements for this array.
      Since:
        6.0.0

    - #### add

          public void add​(T val)

      Adds an object.

    - #### remove

          public boolean remove​(T val)

      Removes an object.
      Returns:
        whether the object is removed successfully (i.e., found).

    - #### removeBy

          public boolean removeBy​(java.lang.Comparable val,
                                  boolean atMostOne)

      Removes the object(s) that matches the specified condition. By match we mean `Comparable.compareTo(T)` returns 0. In other words, this method invokes val.compareTo() against each element in this array.
      Parameters:
        `atMostOne` - whether to remove the first matched object only. If true, only the first matched object, if any, is removed. If false, all matched object are removed.

    - #### clone

          public java.lang.Object clone()

      Overrides:
        `clone` in class `java.lang.Object`

    - #### equals

          public boolean equals​(java.lang.Object o)

      Overrides:
        `equals` in class `java.lang.Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `java.lang.Object`

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`