Class IndexedList<T>

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

@Immutable public class IndexedList<T> extends Object implements Indexed<T>, Iterable<T>
  • Method Details

    • copied

      public static <T> IndexedList<T> copied(List<? extends T> values)
      Produces an instance using a copy of the specified List to ensure that changes to the List will not influence the values returned by the instance's methods. This is generally preferred to the unsafe() constructor.
    • retained

      public static <T> IndexedList<T> retained(List<? extends T> values)
      Produces an instance using the provided List. This makes the instance unsafe for sharing since changes to the List 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>
    • iterator

      @Nonnull public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>