Class ImmutableList<E>

Type Parameters:
E -
All Implemented Interfaces:
Immutable, Iterable<E>, Collection<E>, List<E>, SequencedCollection<E>

public final class ImmutableList<E> extends ImmutableCollection<E> implements List<E>
  • Method Details

    • empty

      public static <E> ImmutableList<E> empty()
      Returns an empty ImmutableList.
      Type Parameters:
      E - the type of elements in this list
      Returns:
      an empty ImmutableList
    • just

      public static <E> ImmutableList<E> just(E e)
      Returns an ImmutableList containing just the provided element.
      Type Parameters:
      E - the type of the element
      Parameters:
      e - the element to be included in the ImmutableList
      Returns:
      an ImmutableList containing the provided element
    • of

      public static <E> ImmutableList<E> of(E e1)
      Returns an ImmutableList containing just the provided element.
      Type Parameters:
      E - the type of the element
      Parameters:
      e1 - the element to be included in the ImmutableList
      Returns:
      an ImmutableList containing the provided element
    • of

      public static <E> ImmutableList<E> of(E e1, E e2)
      Returns an ImmutableList containing the provided elements.
      Type Parameters:
      E - the type of the elements
      Parameters:
      e1 - the first element to be included in the ImmutableList
      e2 - the second element to be included in the ImmutableList
      Returns:
      an ImmutableList containing the provided elements
    • of

      public static <E> ImmutableList<E> of(E e1, E e2, E e3)
      Returns an ImmutableList containing the provided elements.
      Type Parameters:
      E - the type of the elements
      Parameters:
      e1 - the first element to be included in the ImmutableList
      e2 - the second element to be included in the ImmutableList
      e3 - the third element to be included in the ImmutableList
      Returns:
      an ImmutableList containing the provided elements
    • of

      public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4)
      Returns an ImmutableList containing the provided elements.
      Type Parameters:
      E - the type of the elements
      Parameters:
      e1 - the first element to be included in the ImmutableList
      e2 - the second element to be included in the ImmutableList
      e3 - the third element to be included in the ImmutableList
      e4 - the fourth element to be included in the ImmutableList
      Returns:
      an ImmutableList containing the provided elements
    • of

      public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5)
      Returns an ImmutableList containing the provided elements.
      Type Parameters:
      E - the type of the elements
      Parameters:
      e1 - the first element to be included in the ImmutableList
      e2 - the second element to be included in the ImmutableList
      e3 - the third element to be included in the ImmutableList
      e4 - the fourth element to be included in the ImmutableList
      e5 - the fifth element to be included in the ImmutableList
      Returns:
      an ImmutableList containing the provided elements
    • of

      public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5, E e6)
      Returns an ImmutableList containing the provided elements.
      Type Parameters:
      E - the type of the elements
      Parameters:
      e1 - the first element to be included in the ImmutableList
      e2 - the second element to be included in the ImmutableList
      e3 - the third element to be included in the ImmutableList
      e4 - the fourth element to be included in the ImmutableList
      e5 - the fifth element to be included in the ImmutableList
      e6 - the sixth element to be included in the ImmutableList
      Returns:
      an ImmutableList containing the provided elements
    • of

      public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7)
      Returns an ImmutableList containing the provided elements.
      Type Parameters:
      E - the type of the elements
      Parameters:
      e1 - the first element to be included in the ImmutableList
      e2 - the second element to be included in the ImmutableList
      e3 - the third element to be included in the ImmutableList
      e4 - the fourth element to be included in the ImmutableList
      e5 - the fifth element to be included in the ImmutableList
      e6 - the sixth element to be included in the ImmutableList
      e7 - the seventh element to be included in the ImmutableList
      Returns:
      an ImmutableList containing the provided elements
    • of

      public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8)
      Returns an ImmutableList containing the provided elements.
      Type Parameters:
      E - the type of the elements
      Parameters:
      e1 - the first element to be included in the ImmutableList
      e2 - the second element to be included in the ImmutableList
      e3 - the third element to be included in the ImmutableList
      e4 - the fourth element to be included in the ImmutableList
      e5 - the fifth element to be included in the ImmutableList
      e6 - the sixth element to be included in the ImmutableList
      e7 - the seventh element to be included in the ImmutableList
      e8 - the eighth element to be included in the ImmutableList
      Returns:
      an ImmutableList containing the provided elements
    • of

      public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9)
      Returns an ImmutableList containing the provided elements.
      Type Parameters:
      E - the type of the elements
      Parameters:
      e1 - the first element to be included in the ImmutableList
      e2 - the second element to be included in the ImmutableList
      e3 - the third element to be included in the ImmutableList
      e4 - the fourth element to be included in the ImmutableList
      e5 - the fifth element to be included in the ImmutableList
      e6 - the sixth element to be included in the ImmutableList
      e7 - the seventh element to be included in the ImmutableList
      e8 - the eighth element to be included in the ImmutableList
      e9 - the ninth element to be included in the ImmutableList
      Returns:
      an ImmutableList containing the provided elements
    • of

      public static <E> ImmutableList<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E e9, E e10)
      Returns an ImmutableList containing the provided elements.
      Type Parameters:
      E - the type of the elements
      Parameters:
      e1 - the first element to be included in the ImmutableList
      e2 - the second element to be included in the ImmutableList
      e3 - the third element to be included in the ImmutableList
      e4 - the fourth element to be included in the ImmutableList
      e5 - the fifth element to be included in the ImmutableList
      e6 - the sixth element to be included in the ImmutableList
      e7 - the seventh element to be included in the ImmutableList
      e8 - the eighth element to be included in the ImmutableList
      e9 - the ninth element to be included in the ImmutableList
      e10 - the tenth element to be included in the ImmutableList
      Returns:
      an ImmutableList containing the provided elements
    • of

      @SafeVarargs public static <E> ImmutableList<E> of(E... a)
      Returns an ImmutableList containing the provided elements. And it's not backed by the specified array. If the specified array is null or empty, an empty ImmutableList is returned.
      Type Parameters:
      E - the type of the elements
      Parameters:
      a - the elements to be included in the ImmutableList
      Returns:
      an ImmutableList containing the provided elements
      See Also:
    • copyOf

      public static <E> ImmutableList<E> copyOf(Collection<? extends E> c)
      Returns an ImmutableList containing the elements of the provided collection. If the provided collection is already an instance of ImmutableList, it is directly returned. If the provided collection is null or empty, an empty ImmutableList is returned. Otherwise, a new ImmutableList is created with the elements of the provided collection.
      Type Parameters:
      E - the type of elements in the collection
      Parameters:
      c - the collection whose elements are to be placed into this list
      Returns:
      an ImmutableList containing the elements of the specified collection
    • wrap

      @Beta public static <E> ImmutableList<E> wrap(List<? extends E> list)
      Wraps the provided list into an ImmutableList. Changes to the specified List will be reflected in the ImmutableList. If the provided list is already an instance of ImmutableList, it is directly returned. If the list is null, an empty ImmutableList is returned. Otherwise, returned a new ImmutableList backed by the provided list.
      Type Parameters:
      E - the type of elements in the list
      Parameters:
      list - the list to be wrapped into an ImmutableList
      Returns:
      an ImmutableList backed by the provided list
    • wrap

      @Deprecated public static <E> ImmutableCollection<E> wrap(Collection<? extends E> c) throws UnsupportedOperationException
      Deprecated.
      throws UnsupportedOperationException
      This method is deprecated and will throw an UnsupportedOperationException if used.
      Type Parameters:
      E -
      Parameters:
      c -
      Returns:
      Throws:
      UnsupportedOperationException
    • get

      public E get(int index)
      Specified by:
      get in interface List<E>
      Parameters:
      index -
      Returns:
    • indexOf

      public int indexOf(Object valueToFind)
      Specified by:
      indexOf in interface List<E>
      Parameters:
      valueToFind -
      Returns:
    • lastIndexOf

      public int lastIndexOf(Object valueToFind)
      Last index of.
      Specified by:
      lastIndexOf in interface List<E>
      Parameters:
      valueToFind -
      Returns:
    • listIterator

      public ImmutableListIterator<E> listIterator()
      Specified by:
      listIterator in interface List<E>
    • listIterator

      public ImmutableListIterator<E> listIterator(int index)
      Specified by:
      listIterator in interface List<E>
      Parameters:
      index -
      Returns:
    • subList

      public ImmutableList<E> subList(int fromIndex, int toIndex)
      Specified by:
      subList in interface List<E>
      Parameters:
      fromIndex -
      toIndex -
      Returns:
    • addAll

      @Deprecated public boolean addAll(int index, Collection<? extends E> newElements) throws UnsupportedOperationException
      Deprecated.
      throws UnsupportedOperationException
      Adds the all.
      Specified by:
      addAll in interface List<E>
      Parameters:
      index -
      newElements -
      Returns:
      Throws:
      UnsupportedOperationException
    • set

      @Deprecated public E set(int index, E element) throws UnsupportedOperationException
      Deprecated.
      throws UnsupportedOperationException
      Specified by:
      set in interface List<E>
      Parameters:
      index -
      element -
      Returns:
      Throws:
      UnsupportedOperationException
    • add

      @Deprecated public void add(int index, E element) throws UnsupportedOperationException
      Deprecated.
      throws UnsupportedOperationException
      Specified by:
      add in interface List<E>
      Parameters:
      index -
      element -
      Throws:
      UnsupportedOperationException
    • remove

      @Deprecated public E remove(int index) throws UnsupportedOperationException
      Deprecated.
      throws UnsupportedOperationException
      Specified by:
      remove in interface List<E>
      Parameters:
      index -
      Returns:
      Throws:
      UnsupportedOperationException
    • replaceAll

      @Deprecated public void replaceAll(UnaryOperator<E> operator) throws UnsupportedOperationException
      Deprecated.
      throws UnsupportedOperationException
      Specified by:
      replaceAll in interface List<E>
      Parameters:
      operator -
      Throws:
      UnsupportedOperationException
    • sort

      @Deprecated public void sort(Comparator<? super E> c) throws UnsupportedOperationException
      Deprecated.
      throws UnsupportedOperationException
      Specified by:
      sort in interface List<E>
      Parameters:
      c -
      Throws:
      UnsupportedOperationException
    • builder

      public static <E> ImmutableList.Builder<E> builder()
      Type Parameters:
      E -
      Returns:
    • builder

      public static <E> ImmutableList.Builder<E> builder(List<E> holder)
      Type Parameters:
      E -
      Parameters:
      holder -
      Returns: