Interface ImmutableList<E>

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean equals​(Object obj)
      Force to redefine equals for the implementations of immutable collection classes.
      E get​(int index)
      Returns the element at the specified position in this immutable list.
      int hashCode()
      Force to redefine hashCode for the implementations of immutable collection classes.
      int indexOf​(Object o)
      Returns the index of the first occurrence of the specified element in this immutable list, or -1 if this immutable list does not contain the element.
      int lastIndexOf​(Object o)
      Returns the index of the last occurrence of the specified element in this immutable list, or -1 if this immutable list does not contain the element.
      static <E> ImmutableList<E> of()
      Return an empty ImmutableList, backed by a ArrayList.
      static <E> ImmutableList<E> of​(E v1)
      Return an ImmutableList with 1 entry, backed by a ArrayList.
      static <E> ImmutableList<E> of​(E v1, E v2)
      Return an ImmutableList with 2 entries, backed by a ArrayList.
      static <E> ImmutableList<E> of​(E v1, E v2, E v3)
      Return an ImmutableList with 3 entries, backed by a ArrayList.
      static <E> ImmutableList<E> of​(E v1, E v2, E v3, E v4)
      Return an ImmutableList with 4 entries, backed by a ArrayList.
      static <E> ImmutableList<E> of​(E v1, E v2, E v3, E v4, E v5, E... vn)
      Return an ImmutableList with 5 or more entries, backed by a ArrayList.
      ImmutableList<E> subList​(int fromIndex, int toIndex)
      Returns a safe, immutable copy of the portion of this immutable list between the specified fromIndex, inclusive, and toIndex, exclusive.
      List<E> toList()
      Returns a modifiable copy of this immutable list.
      String toString()
      Force to redefine toString.
    • Method Detail

      • get

        E get​(int index)
        Returns the element at the specified position in this immutable list.
        Parameters:
        index - int; index of the element to return
        Returns:
        the element at the specified position in this immutable list
        Throws:
        IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())
      • indexOf

        int indexOf​(Object o)
        Returns the index of the first occurrence of the specified element in this immutable list, or -1 if this immutable list does not contain the element. More formally, returns the lowest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.
        Parameters:
        o - Object; element to search for
        Returns:
        the index of the first occurrence of the specified element in this immutable list, or -1 if this immutable list does not contain the element
        Throws:
        ClassCastException - if the type of the specified element is incompatible with this immutable list
        NullPointerException - if the specified element is null and this immutable list does not permit null elements
      • lastIndexOf

        int lastIndexOf​(Object o)
        Returns the index of the last occurrence of the specified element in this immutable list, or -1 if this immutable list does not contain the element. More formally, returns the highest index i such that (o==null ? get(i)==null : o.equals(get(i))), or -1 if there is no such index.
        Parameters:
        o - Object; element to search for
        Returns:
        the index of the last occurrence of the specified element in this immutable list, or -1 if this immutable list does not contain the element
        Throws:
        ClassCastException - if the type of the specified element is incompatible with this immutable list
        NullPointerException - if the specified element is null and this immutable list does not permit null elements
      • subList

        ImmutableList<E> subList​(int fromIndex,
                                 int toIndex)
        Returns a safe, immutable copy of the portion of this immutable list between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned immutable list is empty).
        Parameters:
        fromIndex - int; low endpoint (inclusive) of the subList
        toIndex - int; high endpoint (exclusive) of the subList
        Returns:
        a view of the specified range within this immutable list
        Throws:
        IndexOutOfBoundsException - for an illegal endpoint index value (fromIndex < 0 || toIndex > size || fromIndex > toIndex)
      • toList

        List<E> toList()
        Returns a modifiable copy of this immutable list.
        Returns:
        a modifiable copy of this immutable list.
      • equals

        boolean equals​(Object obj)
        Force to redefine equals for the implementations of immutable collection classes.
        Specified by:
        equals in interface ImmutableCollection<E>
        Overrides:
        equals in class Object
        Parameters:
        obj - Object; the object to compare this collection with
        Returns:
        whether the objects are equal
      • hashCode

        int hashCode()
        Force to redefine hashCode for the implementations of immutable collection classes.
        Specified by:
        hashCode in interface ImmutableCollection<E>
        Overrides:
        hashCode in class Object
        Returns:
        the calculated hashCode
      • toString

        String toString()
        Force to redefine toString.
        Overrides:
        toString in class Object
        Returns:
        String; a description of this immutable list
      • of

        static <E> ImmutableList<E> of()
        Return an empty ImmutableList, backed by a ArrayList.
        Type Parameters:
        E - the value type
        Returns:
        ImmutableList<K, V>; an empty ImmutableList
      • of

        static <E> ImmutableList<E> of​(E v1)
        Return an ImmutableList with 1 entry, backed by a ArrayList.
        Type Parameters:
        E - the value type
        Parameters:
        v1 - E; value 1
        Returns:
        ImmutableList<K, V>; an ImmutableList with 1 entry, backed by a ArrayList
      • of

        static <E> ImmutableList<E> of​(E v1,
                                       E v2)
        Return an ImmutableList with 2 entries, backed by a ArrayList.
        Type Parameters:
        E - the value type
        Parameters:
        v1 - E; value 1
        v2 - E; value 2
        Returns:
        ImmutableList<K, V>; an ImmutableList with 2 entries, backed by a ArrayList
      • of

        static <E> ImmutableList<E> of​(E v1,
                                       E v2,
                                       E v3)
        Return an ImmutableList with 3 entries, backed by a ArrayList.
        Type Parameters:
        E - the value type
        Parameters:
        v1 - E; value 1
        v2 - E; value 2
        v3 - E; value 3
        Returns:
        ImmutableList<K, V>; an ImmutableList with 3 entries, backed by a ArrayList
      • of

        static <E> ImmutableList<E> of​(E v1,
                                       E v2,
                                       E v3,
                                       E v4)
        Return an ImmutableList with 4 entries, backed by a ArrayList.
        Type Parameters:
        E - the value type
        Parameters:
        v1 - E; value 1
        v2 - E; value 2
        v3 - E; value 3
        v4 - E; value 4
        Returns:
        ImmutableList<K, V>; an ImmutableList with 4 entries, backed by a ArrayList
      • of

        static <E> ImmutableList<E> of​(E v1,
                                       E v2,
                                       E v3,
                                       E v4,
                                       E v5,
                                       E... vn)
        Return an ImmutableList with 5 or more entries, backed by a ArrayList.
        Type Parameters:
        E - the value type
        Parameters:
        v1 - E; value 1
        v2 - E; value 2
        v3 - E; value 3
        v4 - E; value 4
        v5 - E; value 5
        vn - E...; values 6 and beyond
        Returns:
        ImmutableList<K, V>; an ImmutableList with 5 or more entries, backed by a ArrayList