Class ImmutableNullableList<E>

  • Type Parameters:
    E - Element type
    All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>

    public class ImmutableNullableList<E>
    extends java.util.AbstractList<E>
    An immutable list that may contain null values.

    If the list cannot contain null values, use ImmutableList.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  ImmutableNullableList.Builder<E>
      A builder for creating immutable nullable list instances.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private E[] elements  
      private static java.util.List SINGLETON_NULL  
      • Fields inherited from class java.util.AbstractList

        modCount
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ImmutableNullableList​(E[] elements)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <E> ImmutableNullableList.Builder<E> builder()
      Returns a new builder.
      static <E> java.util.List<E> copyOf​(E[] elements)
      Returns an immutable list containing the given elements, in order.
      static <E> java.util.List<E> copyOf​(java.lang.Iterable<? extends E> elements)
      Returns an immutable list containing the given elements, in order.
      static <E> java.util.List<E> copyOf​(java.util.Collection<? extends E> elements)
      Returns an immutable list containing the given elements, in order.
      E get​(int index)  
      static <E> java.util.List<E> of​(E e1)
      Creates an immutable list of 1 element.
      static <E> java.util.List<E> of​(E e1, E e2)
      Creates an immutable list of 2 elements.
      static <E> java.util.List<E> of​(E e1, E e2, E e3)
      Creates an immutable list of 3 elements.
      static <E> java.util.List<E> of​(E e1, E e2, E e3, E e4)
      Creates an immutable list of 4 elements.
      static <E> java.util.List<E> of​(E e1, E e2, E e3, E e4, E e5)
      Creates an immutable list of 5 elements.
      static <E> java.util.List<E> of​(E e1, E e2, E e3, E e4, E e5, E e6)
      Creates an immutable list of 6 elements.
      static <E> java.util.List<E> of​(E e1, E e2, E e3, E e4, E e5, E e6, E e7)
      Creates an immutable list of 7 elements.
      static <E> java.util.List<E> of​(E e1, E e2, E e3, E e4, E e5, E e6, E e7, E e8, E... others)
      Creates an immutable list of 8 or more elements.
      int size()  
      • Methods inherited from class java.util.AbstractList

        add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
      • Methods inherited from class java.util.AbstractCollection

        addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.List

        addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
    • Field Detail

      • SINGLETON_NULL

        private static final java.util.List SINGLETON_NULL
      • elements

        private final E[] elements
    • Constructor Detail

      • ImmutableNullableList

        private ImmutableNullableList​(E[] elements)
    • Method Detail

      • copyOf

        public static <E> java.util.List<E> copyOf​(java.util.Collection<? extends E> elements)
        Returns an immutable list containing the given elements, in order.

        Behavior as ImmutableList.copyOf(java.util.Collection) except that this list allows nulls.

      • copyOf

        public static <E> java.util.List<E> copyOf​(java.lang.Iterable<? extends E> elements)
        Returns an immutable list containing the given elements, in order.

        Behavior as ImmutableList.copyOf(Iterable) except that this list allows nulls.

      • copyOf

        public static <E> java.util.List<E> copyOf​(E[] elements)
        Returns an immutable list containing the given elements, in order.

        Behavior as ImmutableList.copyOf(Object[]) except that this list allows nulls.

      • of

        public static <E> java.util.List<E> of​(E e1)
        Creates an immutable list of 1 element.
      • of

        public static <E> java.util.List<E> of​(E e1,
                                               E e2)
        Creates an immutable list of 2 elements.
      • of

        public static <E> java.util.List<E> of​(E e1,
                                               E e2,
                                               E e3)
        Creates an immutable list of 3 elements.
      • of

        public static <E> java.util.List<E> of​(E e1,
                                               E e2,
                                               E e3,
                                               E e4)
        Creates an immutable list of 4 elements.
      • of

        public static <E> java.util.List<E> of​(E e1,
                                               E e2,
                                               E e3,
                                               E e4,
                                               E e5)
        Creates an immutable list of 5 elements.
      • of

        public static <E> java.util.List<E> of​(E e1,
                                               E e2,
                                               E e3,
                                               E e4,
                                               E e5,
                                               E e6)
        Creates an immutable list of 6 elements.
      • of

        public static <E> java.util.List<E> of​(E e1,
                                               E e2,
                                               E e3,
                                               E e4,
                                               E e5,
                                               E e6,
                                               E e7)
        Creates an immutable list of 7 elements.
      • of

        public static <E> java.util.List<E> of​(E e1,
                                               E e2,
                                               E e3,
                                               E e4,
                                               E e5,
                                               E e6,
                                               E e7,
                                               E e8,
                                               E... others)
        Creates an immutable list of 8 or more elements.
      • get

        public E get​(int index)
        Specified by:
        get in interface java.util.List<E>
        Specified by:
        get in class java.util.AbstractList<E>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.List<E>
        Specified by:
        size in class java.util.AbstractCollection<E>