Package org.jboss.weld.util.collections
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 immutableList
implementations. Based on the size of the data, methods of this class may returnList
instances using various storage strategies in order to achieve the best performance / memory consumption balance.- Author:
- Jozef Hartinger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ImmutableList.Builder<T>
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, E element)
boolean
add(E e)
boolean
addAll(int index, Collection<? extends E> c)
static <T> ImmutableList.Builder<T>
builder()
Creates a new empty builder for building immutable lists.void
clear()
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.static <T> List<T>
copyOf(Iterable<T> source)
static <T> List<T>
copyOf(Collection<T> source)
Creates an immutable list that consists of the elements in the given collection.static <T> List<T>
copyOf(T[] elements)
Creates an immutable list that consists of the elements in the given array.protected IndexOutOfBoundsException
indexOutOfBoundsException(int index)
boolean
isEmpty()
Iterator<E>
iterator()
ListIterator<E>
listIterator()
static <T> List<T>
of(T... elements)
Creates an immutable list that consists of the given elements.E
remove(int index)
boolean
removeIf(Predicate<? super E> filter)
protected void
removeRange(int fromIndex, int toIndex)
void
replaceAll(UnaryOperator<E> operator)
E
set(int index, E element)
void
sort(Comparator<? super E> c)
Spliterator<E>
spliterator()
-
Methods inherited from class java.util.AbstractList
equals, get, hashCode, indexOf, lastIndexOf, listIterator, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, remove, removeAll, retainAll, size, 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, stream, toArray
-
-
-
-
Method Detail
-
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
-
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 interfaceCollection<E>
- Specified by:
add
in interfaceList<E>
- Overrides:
add
in classAbstractList<E>
-
set
public E set(int index, E element)
- Specified by:
set
in interfaceList<E>
- Overrides:
set
in classAbstractList<E>
-
add
public void add(int index, E element)
- Specified by:
add
in interfaceList<E>
- Overrides:
add
in classAbstractList<E>
-
remove
public E remove(int index)
- Specified by:
remove
in interfaceList<E>
- Overrides:
remove
in classAbstractList<E>
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceList<E>
- Overrides:
clear
in classAbstractList<E>
-
addAll
public boolean addAll(int index, Collection<? extends E> c)
- Specified by:
addAll
in interfaceList<E>
- Overrides:
addAll
in classAbstractList<E>
-
removeRange
protected void removeRange(int fromIndex, int toIndex)
- Overrides:
removeRange
in classAbstractList<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceList<E>
- Overrides:
isEmpty
in classAbstractCollection<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 interfaceCollection<E>
- Specified by:
iterator
in interfaceIterable<E>
- Specified by:
iterator
in interfaceList<E>
- Overrides:
iterator
in classAbstractList<E>
-
listIterator
public ListIterator<E> listIterator()
- Specified by:
listIterator
in interfaceList<E>
- Overrides:
listIterator
in classAbstractList<E>
-
spliterator
public Spliterator<E> spliterator()
-
indexOutOfBoundsException
protected IndexOutOfBoundsException indexOutOfBoundsException(int index)
-
-