Interface IDeque<T>

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

@Immutable public interface IDeque<T> extends ICollection<T>, Indexed<T>, InvariantCheckable, 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.
     
    Removes the first value from the list and reduces size by 1.
    Removes the last value from the list and reduces size by 1.
    default java.util.stream.Collector<T,?,IDeque<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.
    get(int index)
    Retrieves the value at the specified index (which must be within the bounds of the list).
    Returns an unmodifiable List implementation backed by this list.
    insert(T value)
    Adds a value to the end of the list.
    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.
    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.
    default Maybe<T>
    Returns a Holder containing a value if this list contains only a single value and that value is non-null.
    suffix(int offset)
    Return the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items.
    <A> IDeque<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> IDeque<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.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

    • get

      T get(int index)
      Retrieves the value at the specified index (which must be within the bounds of the list).
      Specified by:
      get in interface Indexed<T>
      Throws:
      IndexOutOfBoundsException - if index is out of bounds
    • assign

      @Nonnull IDeque<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.
      Throws:
      IndexOutOfBoundsException - if index is out of bounds
    • insert

      @Nonnull IDeque<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>
    • insertFirst

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

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

      @Nonnull IDeque<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>
      Returns:
      instance of list containing the collection
    • insertAll

      @Nonnull IDeque<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>
      Returns:
      instance of list containing the collection
    • insertAllFirst

      @Nonnull IDeque<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.
      Returns:
      instance of list containing the collection
    • insertAllFirst

      @Nonnull IDeque<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.
      Returns:
      instance of list containing the collection
    • insertAllLast

      @Nonnull IDeque<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()
      Returns:
      instance of list containing the collection
    • insertAllLast

      @Nonnull IDeque<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()
      Returns:
      instance of list containing the collection
    • deleteFirst

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

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

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

      @Nonnull List<T> getList()
      Returns an unmodifiable List implementation backed by this list.
    • reverse

      @Nonnull IDeque<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.
    • select

      @Nonnull IDeque<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.
      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 IDeque<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.
      Parameters:
      predicate - decides whether to include an element
      Returns:
      list of same type as this containing only those elements for which predicate returns false
    • dequeCollector

      @Nonnull default java.util.stream.Collector<T,?,IDeque<T>> dequeCollector()
      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> IDeque<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.
      Parameters:
      transform - transformation applied to each element
      Returns:
      the collection after all elements have been processed
    • transformSome

      <A> IDeque<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.
      Parameters:
      transform - transformation applied to each element
      Returns:
      the collection after all elements have been processed
    • single

      default Maybe<T> single()
      Returns a Holder containing a value if this list contains only a single value and that value is non-null. Otherwise returns and empty Holder. i.e. empty unless size() == 1 and get(0) returns a non-null value.
      Returns:
      Holder possibly containing the single non-null value in this list
    • prefix

      @Nonnull IDeque<T> prefix(int limit)
      Return the (possibly empty) list containing the first limit values.
      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 IDeque<T> suffix(int offset)
      Return the (possibly empty) list containing the values starting at offset (inclusive) and including all remaining items.
      Parameters:
      offset - first index (inclusive) of values to include
      Returns:
      a possibly empty list containing the values
    • middle

      @Nonnull IDeque<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.
      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