Class IndexedArray<T>

java.lang.Object
org.javimmutable.collections.indexed.IndexedArray<T>
All Implemented Interfaces:
Indexed<T>

@Immutable public class IndexedArray<T> extends Object implements Indexed<T>
Indexed implementation backed by a java array.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> IndexedArray<T>
    copied(T[] values)
    Produces an instance using a clone of the specified array to ensure that changes to the array will not influence the values returned by the instance's methods.
    find(int index)
    Retrieves a Holder containing the (possibly null) value at the specified index if it exists.
    get(int index)
    Retrieve the value.
    static <T> IndexedArray<T>
    retained(T[] values)
    Produces an instance using the provided array.
    int
    Retrieve the number of values available in the container.

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface org.javimmutable.collections.Indexed

    prefix, reversed, transformed
  • Method Details

    • copied

      public static <T> IndexedArray<T> copied(T[] values)
      Produces an instance using a clone of the specified array to ensure that changes to the array will not influence the values returned by the instance's methods. This is generally preferred to the unsafe() constructor.
    • retained

      public static <T> IndexedArray<T> retained(T[] values)
      Produces an instance using the provided array. This makes the instance unsafe for sharing since changes to the array will cause changes to this instance's values. However this can be useful when performance is important and the instance will not be shared or retained beyond a single method scope.
    • get

      public T get(int index)
      Description copied from interface: Indexed
      Retrieve the value. The index must be valid for the container's current size (i.e. [0-size)
      Specified by:
      get in interface Indexed<T>
    • find

      @Nonnull public Maybe<T> find(int index)
      Description copied from interface: Indexed
      Retrieves a Holder containing the (possibly null) value at the specified index if it exists. If no such value exists returns an empty Holder.
      Specified by:
      find in interface Indexed<T>
    • size

      public int size()
      Description copied from interface: Indexed
      Retrieve the number of values available in the container.
      Specified by:
      size in interface Indexed<T>