Class ImmutableList<E>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
org.jboss.weld.util.collections.ImmutableList<E>
Type Parameters:
E - the element type
All Implemented Interfaces:
Iterable<E>, Collection<E>, List<E>

public abstract class ImmutableList<E> extends AbstractList<E>
Weld's immutable List implementations. Based on the size of the data, methods of this class may return List instances using various storage strategies in order to achieve the best performance / memory consumption balance.
Author:
Jozef Hartinger
  • Method Details

    • of

      @SafeVarargs public static <T> List<T> of(T... elements)
      Creates an immutable list that consists of the given elements. This method should only be used in the varargs form. If there is a need to create an immutable list of an array of elements, copyOf(Object[]) should be used instead.
      Parameters:
      elements - the given elements
      Returns:
      an immutable list
    • copyOf

      public static <T> List<T> copyOf(T[] elements)
      Creates an immutable list that consists of the elements in the given array. A copy of the given array is used which means that any modifications to the given array will not affect the immutable list.
      Parameters:
      elements - the given array of elements
      Returns:
      an immutable list
    • copyOf

      public static <T> List<T> copyOf(Collection<T> source)
      Creates an immutable list that consists of the elements in the given collection. If the given collection is already an immutable list, it is returned directly.
      Parameters:
      source - the given collection
      Returns:
      an immutable list
    • copyOf

      public static <T> List<T> copyOf(Iterable<T> source)
    • collector

      public static <T> org.jboss.weld.util.collections.ImmutableList.ImmutableListCollector<T> collector()
      Returns a collector that can be used to collect items of a stream into an immutable list.
      Returns:
      collector
    • builder

      public static <T> ImmutableList.Builder<T> builder()
      Creates a new empty builder for building immutable lists.
      Returns:
      a new empty builder
    • add

      public boolean add(E e)
      Specified by:
      add in interface Collection<E>
      Specified by:
      add in interface List<E>
      Overrides:
      add in class AbstractList<E>
    • set

      public E set(int index, E element)
      Specified by:
      set in interface List<E>
      Overrides:
      set in class AbstractList<E>
    • add

      public void add(int index, E element)
      Specified by:
      add in interface List<E>
      Overrides:
      add in class AbstractList<E>
    • remove

      public E remove(int index)
      Specified by:
      remove in interface List<E>
      Overrides:
      remove in class AbstractList<E>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<E>
      Specified by:
      clear in interface List<E>
      Overrides:
      clear in class AbstractList<E>
    • addAll

      public boolean addAll(int index, Collection<? extends E> c)
      Specified by:
      addAll in interface List<E>
      Overrides:
      addAll in class AbstractList<E>
    • removeRange

      protected void removeRange(int fromIndex, int toIndex)
      Overrides:
      removeRange in class AbstractList<E>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<E>
      Specified by:
      isEmpty in interface List<E>
      Overrides:
      isEmpty in class AbstractCollection<E>
    • replaceAll

      public void replaceAll(UnaryOperator<E> operator)
    • sort

      public void sort(Comparator<? super E> c)
    • removeIf

      public boolean removeIf(Predicate<? super E> filter)
    • iterator

      public Iterator<E> iterator()
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
      Specified by:
      iterator in interface List<E>
      Overrides:
      iterator in class AbstractList<E>
    • listIterator

      public ListIterator<E> listIterator()
      Specified by:
      listIterator in interface List<E>
      Overrides:
      listIterator in class AbstractList<E>
    • spliterator

      public Spliterator<E> spliterator()
    • indexOutOfBoundsException

      protected IndexOutOfBoundsException indexOutOfBoundsException(int index)