Class SIList<E>

java.lang.Object
org.plumelib.util.SIList<E>
Type Parameters:
E - the type of elements of the list
All Implemented Interfaces:
Serializable, Iterable<E>

public abstract class SIList<E> extends Object implements Iterable<E>, Serializable
An immutable list. Different lists may share structure, making the representation space-efficient and making construction time-efficient. Use this only if you will be creating many lists that share structure. Examples are when one list is the concatenation of other lists, or one list is just like another with a single element added.

"SIList" stands for "Shared Immutable List".

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    add(E element)
    Returns a new list that consists of this one plus one more element.
    static <E2> SIList<E2>
    concat(Iterable<SIList<E2>> lists)
    Create a SIList from a list of SILists.
    static <E2> SIList<E2>
    concat(SIList<E2>... lists)
    Concatenate an array of SILists.
    static <E2> SIList<E2>
    Returns an empty list.
    static <E2> SIList<E2>
    fromList(Collection<E2> list)
    Create a SIList from a JDK list.
    abstract E
    get(@org.checkerframework.checker.index.qual.IndexFor({"this"}) int index)
    Returns the element at the given position of this list.
    abstract SIList<E>
    getSublistContaining(@org.checkerframework.checker.index.qual.IndexFor({"this"}) int index)
    Returns an arbitrary sublist of this list that contains the index.
    abstract boolean
    Returns true if this list is empty.
    static <E2> SIList<E2>
    singleton(E2 elt)
    Returns a new list containing one element.
    static <E2> SIList<E2>
    singletonOrEmpty(@Nullable E2 elt)
    Returns a new list containing zero or one element.
    abstract @org.checkerframework.checker.index.qual.LengthOf({"this"}) int
    Returns the number of elements in this list.
    subList(@org.checkerframework.checker.index.qual.IndexFor({"this"}) int fromIndex, @org.checkerframework.checker.index.qual.IndexOrHigh({"this"}) int toIndex)
    Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
     

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface java.lang.Iterable

    forEach, iterator, spliterator
  • Method Details

    • fromList

      public static <E2> SIList<E2> fromList(Collection<E2> list)
      Create a SIList from a JDK list.
      Type Parameters:
      E2 - the type of list elements
      Parameters:
      list - the elements of the new list
      Returns:
      the list
    • empty

      public static <E2> SIList<E2> empty()
      Returns an empty list.
      Type Parameters:
      E2 - the type of elements of the list
      Returns:
      an empty list
    • singleton

      public static <E2> SIList<E2> singleton(E2 elt)
      Returns a new list containing one element.
      Type Parameters:
      E2 - the type of elements of the list
      Parameters:
      elt - the element
      Returns:
      a new list containing one element
    • singletonOrEmpty

      public static <E2> SIList<E2> singletonOrEmpty(@Nullable E2 elt)
      Returns a new list containing zero or one element.
      Type Parameters:
      E2 - the type of elements of the list
      Parameters:
      elt - the element
      Returns:
      a new list containing the element if it is non-null; if the element is null, returns an empty list
    • add

      public SIList<E> add(E element)
      Returns a new list that consists of this one plus one more element. Does not modify this object.
      Parameters:
      element - the additional element
      Returns:
      a new list that consists of this one plus one more element
    • concat

      public static <E2> SIList<E2> concat(SIList<E2>... lists)
      Concatenate an array of SILists.
      Type Parameters:
      E2 - the type of list elements
      Parameters:
      lists - the lists that will compose the newly-created ListOfLists
      Returns:
      the concatenated list
    • concat

      public static <E2> SIList<E2> concat(Iterable<SIList<E2>> lists)
      Create a SIList from a list of SILists.
      Type Parameters:
      E2 - the type of list elements
      Parameters:
      lists - the lists that will compose the newly-created ListOfLists
      Returns:
      the concatenated list
    • size

      @LengthOf("this") public abstract @org.checkerframework.checker.index.qual.LengthOf({"this"}) int size()
      Returns the number of elements in this list.
      Returns:
      the number of elements in this list
    • isEmpty

      public abstract boolean isEmpty()
      Returns true if this list is empty.
      Returns:
      true if this list is empty, false otherwise
    • get

      public abstract E get(@org.checkerframework.checker.index.qual.IndexFor({"this"}) int index)
      Returns the element at the given position of this list.
      Parameters:
      index - a position in the list
      Returns:
      the element at the index
    • subList

      public SIList<E> subList(@org.checkerframework.checker.index.qual.IndexFor({"this"}) int fromIndex, @org.checkerframework.checker.index.qual.IndexOrHigh({"this"}) int toIndex)
      Returns a view of the portion of this list between the specified fromIndex, inclusive, and toIndex, exclusive.
      Parameters:
      fromIndex - low endpoint (inclusive) of the subList
      toIndex - high endpoint (exclusive) of the subList
      Returns:
      a view of part of this list
    • getSublistContaining

      public abstract SIList<E> getSublistContaining(@org.checkerframework.checker.index.qual.IndexFor({"this"}) int index)
      Returns an arbitrary sublist of this list that contains the index. The result does not necessarily contain the first or last element of this.
      Parameters:
      index - the index into this list
      Returns:
      a sublist containing this index
    • toString

      public String toString(@GuardSatisfied SIList<E> this)
      Overrides:
      toString in class Object