Interface IList<T>

All Superinterfaces:
ICollection<T>, IDeque<T>, Indexed<T>, InvariantCheckable, IStreamable<T>, Iterable<T>, Serializable, SplitableIterable<T>
All Known Implementing Classes:
TreeList

@Immutable public interface IList<T> extends IDeque<T>, Serializable
Interface for containers that store items in list form with individual items available for get() and assign() using their indexes. Items inserted into the list are always added at either the front or the end of the list and indexes of items are always in the range 0 through size() - 1.
  • Method Summary

    Modifier and Type
    Method
    Description
    assign(int index, T value)
    Replaces the value at the specified index (which must be within current bounds of the list) with the new value.
    delete(int index)
    Delete value at index (which must be within the current bounds of the list).
     
    Removes the first value from the list and reduces size by 1.
    Removes the last value from the list and reduces size by 1.
    insert(int index, T value)
    Insert value at index (which must be within 0 to size).
    insert(T value)
    Adds a value to the end of the list.
    insertAll(int index, Iterable<? extends T> values)
    Inserts all elements at index (which must be within 0 to size) in the same order they appear in the Iterable.
    insertAll(int index, Iterator<? extends T> values)
    Inserts all elements at index (which must be within 0 to size) in the same order they appear in the Iterable.
    insertAll(Iterable<? extends T> values)
    Adds the values to the end of the list in the same order they appear in the Iterable.
    insertAll(Iterator<? extends T> values)
    Adds the values to the end of the list in the same order they appear in the Iterable.
    insertAllFirst(Iterable<? extends T> values)
    Adds the values to the beginning of the list in the same order they appear in the Iterable.
    insertAllFirst(Iterator<? extends T> values)
    Adds the values to the beginning of the list in the same order they appear in the Iterable.
    insertAllLast(Iterable<? extends T> values)
    Adds the values to the end of the list in the same order they appear in the Iterable.
    insertAllLast(Iterator<? extends T> values)
    Adds the values to the end of the list in the same order they appear in the Iterable.
    insertFirst(T value)
    Adds a value to the front of the list.
    insertLast(T value)
    Adds a value to the end of the list.
    default java.util.stream.Collector<T,?,IList<T>>
    Returns a Collector that creates a list of the same type as this containing all of the collected values inserted after whatever starting values this already contained.
    middle(int offset, int limit)
    Return the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items up to but excluding the value at index limit.
    prefix(int limit)
    Return the (possibly empty) list containing the first limit values.
    reject(java.util.function.Predicate<T> predicate)
    Returns a list of the same type as this containing all those elements for which predicate returns false.
    Returns a list containing the same elements as this list but with their order reversed so that first in this list is last in returned list etc.
    select(java.util.function.Predicate<T> predicate)
    Returns a list of the same type as this containing only those elements for which predicate returns true.
    slice(int offset, int limit)
    Return the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items up to but excluding the value at index limit.
    suffix(int offset)
    Return the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items.
    <A> IList<A>
    transform(Func1<T,A> transform)
    Apply the transform function to all elements in iterator order and add each transformed value to a new collection of this type.
    <A> IList<A>
    transformSome(Func1<T,Maybe<A>> transform)
    Apply the transform function to all elements in iterator order and add the contents of non-empty Holders to a new collection of this type.

    Methods inherited from interface org.javimmutable.collections.ICollection

    isEmpty, isNonEmpty, size

    Methods inherited from interface org.javimmutable.collections.IDeque

    dequeCollector, get, getList, single

    Methods inherited from interface org.javimmutable.collections.Indexed

    find, reversed, size, transformed

    Methods inherited from interface org.javimmutable.collections.InvariantCheckable

    checkInvariants

    Methods inherited from interface org.javimmutable.collections.IStreamable

    getSpliteratorCharacteristics, iterator, parallelStream, spliterator, stream

    Methods inherited from interface java.lang.Iterable

    forEach

    Methods inherited from interface org.javimmutable.collections.SplitableIterable

    forEachThrows, indexedForEach, indexedForEachThrows, reduce, reduceThrows
  • Method Details

    • assign

      @Nonnull IList<T> assign(int index, @Nullable T value)
      Replaces the value at the specified index (which must be within current bounds of the list) with the new value.
      Specified by:
      assign in interface IDeque<T>
      Throws:
      IndexOutOfBoundsException - if index is out of bounds
    • insert

      @Nonnull IList<T> insert(@Nullable T value)
      Adds a value to the end of the list. May be invoked on an empty list.
      Specified by:
      insert in interface ICollection<T>
      Specified by:
      insert in interface IDeque<T>
    • insert

      @Nonnull IList<T> insert(int index, @Nullable T value)
      Insert value at index (which must be within 0 to size). Shifts all values at and after index one position to the right and adds 1 to size of the list.
    • insertFirst

      @Nonnull IList<T> insertFirst(@Nullable T value)
      Adds a value to the front of the list. May be invoked on an empty list. Synonym for insert()
      Specified by:
      insertFirst in interface IDeque<T>
    • insertLast

      @Nonnull IList<T> insertLast(@Nullable T value)
      Adds a value to the end of the list. May be invoked on an empty list. Synonym for insert().
      Specified by:
      insertLast in interface IDeque<T>
    • insertAll

      @Nonnull IList<T> insertAll(@Nonnull Iterable<? extends T> values)
      Adds the values to the end of the list in the same order they appear in the Iterable. May be invoked on an empty list.
      Specified by:
      insertAll in interface ICollection<T>
      Specified by:
      insertAll in interface IDeque<T>
      Returns:
      instance of list containing the collection
    • insertAll

      @Nonnull IList<T> insertAll(@Nonnull Iterator<? extends T> values)
      Adds the values to the end of the list in the same order they appear in the Iterable. May be invoked on an empty list.
      Specified by:
      insertAll in interface ICollection<T>
      Specified by:
      insertAll in interface IDeque<T>
      Returns:
      instance of list containing the collection
    • insertAll

      @Nonnull IList<T> insertAll(int index, @Nonnull Iterable<? extends T> values)
      Inserts all elements at index (which must be within 0 to size) in the same order they appear in the Iterable. Shifts all values at and after index x positions to the right and adds x to size of the list, where x is the number of elements being inserted.
      Returns:
      instance of list containing the collection
    • insertAll

      @Nonnull IList<T> insertAll(int index, @Nonnull Iterator<? extends T> values)
      Inserts all elements at index (which must be within 0 to size) in the same order they appear in the Iterable. Shifts all values at and after index x positions to the right and adds x to size of the list, where x is the number of elements being inserted.
      Returns:
      instance of list containing the collection
    • insertAllFirst

      @Nonnull IList<T> insertAllFirst(@Nonnull Iterable<? extends T> values)
      Adds the values to the beginning of the list in the same order they appear in the Iterable. May be invoked on an empty list.
      Specified by:
      insertAllFirst in interface IDeque<T>
      Returns:
      instance of list containing the collection
    • insertAllFirst

      @Nonnull IList<T> insertAllFirst(@Nonnull Iterator<? extends T> values)
      Adds the values to the beginning of the list in the same order they appear in the Iterable. May be invoked on an empty list.
      Specified by:
      insertAllFirst in interface IDeque<T>
      Returns:
      instance of list containing the collection
    • insertAllLast

      @Nonnull IList<T> insertAllLast(@Nonnull Iterable<? extends T> values)
      Adds the values to the end of the list in the same order they appear in the Iterable. May be invoked on an empty list. Synonym for insertAll()
      Specified by:
      insertAllLast in interface IDeque<T>
      Returns:
      instance of list containing the collection
    • insertAllLast

      @Nonnull IList<T> insertAllLast(@Nonnull Iterator<? extends T> values)
      Adds the values to the end of the list in the same order they appear in the Iterable. May be invoked on an empty list. Synonym for insertAll()
      Specified by:
      insertAllLast in interface IDeque<T>
      Returns:
      instance of list containing the collection
    • deleteFirst

      @Nonnull IList<T> deleteFirst()
      Removes the first value from the list and reduces size by 1. size() must be greater than zero
      Specified by:
      deleteFirst in interface IDeque<T>
      Returns:
      new IList without last value
      Throws:
      IndexOutOfBoundsException - if list is already empty
    • deleteLast

      @Nonnull IList<T> deleteLast()
      Removes the last value from the list and reduces size by 1. size() must be greater than zero
      Specified by:
      deleteLast in interface IDeque<T>
      Returns:
      new IList without last value
      Throws:
      IndexOutOfBoundsException - if list is already empty
    • delete

      @Nonnull IList<T> delete(int index)
      Delete value at index (which must be within the current bounds of the list). Shifts all values at and after index one position to the left and subtracts 1 from size of the list.
    • deleteAll

      @Nonnull IList<T> deleteAll()
      Specified by:
      deleteAll in interface ICollection<T>
      Specified by:
      deleteAll in interface IDeque<T>
      Returns:
      an equivalent collection with no values
    • reverse

      @Nonnull IList<T> reverse()
      Returns a list containing the same elements as this list but with their order reversed so that first in this list is last in returned list etc.
      Specified by:
      reverse in interface IDeque<T>
    • select

      @Nonnull IList<T> select(@Nonnull java.util.function.Predicate<T> predicate)
      Returns a list of the same type as this containing only those elements for which predicate returns true. Implementations are optimized assuming predicate will return false more often than true.
      Specified by:
      select in interface IDeque<T>
      Parameters:
      predicate - decides whether to include an element
      Returns:
      list of same type as this containing only those elements for which predicate returns true
    • reject

      @Nonnull IList<T> reject(@Nonnull java.util.function.Predicate<T> predicate)
      Returns a list of the same type as this containing all those elements for which predicate returns false. Implementations can be optimized assuming predicate will return false more often than true.
      Specified by:
      reject in interface IDeque<T>
      Parameters:
      predicate - decides whether to include an element
      Returns:
      list of same type as this containing only those elements for which predicate returns false
    • listCollector

      @Nonnull default java.util.stream.Collector<T,?,IList<T>> listCollector()
      Returns a Collector that creates a list of the same type as this containing all of the collected values inserted after whatever starting values this already contained.
    • transform

      <A> IList<A> transform(@Nonnull Func1<T,A> transform)
      Apply the transform function to all elements in iterator order and add each transformed value to a new collection of this type.
      Specified by:
      transform in interface IDeque<T>
      Parameters:
      transform - transformation applied to each element
      Returns:
      the collection after all elements have been processed
    • transformSome

      <A> IList<A> transformSome(@Nonnull Func1<T,Maybe<A>> transform)
      Apply the transform function to all elements in iterator order and add the contents of non-empty Holders to a new collection of this type.
      Specified by:
      transformSome in interface IDeque<T>
      Parameters:
      transform - transformation applied to each element
      Returns:
      the collection after all elements have been processed
    • prefix

      @Nonnull IList<T> prefix(int limit)
      Return the (possibly empty) list containing the first limit values.
      Specified by:
      prefix in interface IDeque<T>
      Specified by:
      prefix in interface Indexed<T>
      Parameters:
      limit - last index (exclusive) of values to include
      Returns:
      a possibly empty list containing the values
    • suffix

      @Nonnull IList<T> suffix(int offset)
      Return the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items.
      Specified by:
      suffix in interface IDeque<T>
      Parameters:
      offset - first index (inclusive) of values to include
      Returns:
      a possibly empty list containing the values
    • middle

      @Nonnull IList<T> middle(int offset, int limit)
      Return the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items up to but excluding the value at index limit.
      Specified by:
      middle in interface IDeque<T>
      Parameters:
      offset - first index (inclusive) of values to include
      limit - last index (exclusive) of values to include
      Returns:
      a possibly empty list containing the values
    • slice

      @Nonnull IList<T> slice(int offset, int limit)
      Return the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items up to but excluding the value at index limit. Similar to middle() but accepts a more permissive set of values. Negative values are interpreted relative to the end of the list and are inclusive when used as limit. This (-5,-1) would return the last 5 elements of the list. Bounds checking is removed and values past the end of the list are simply set to the end of the list. So (0,10000) for a list with five elements would be equivalent to (0,5).
      Parameters:
      offset - first index (inclusive) of values to include
      limit - last index (exclusive) of values to include
      Returns:
      a possibly empty list containing the values