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 immutableListimplementations. Based on the size of the data, methods of this class may returnListinstances 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 interfaceImmutableList.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 voidadd(int index, E element)booleanadd(E e)booleanaddAll(int index, Collection<? extends E> c)static <T> ImmutableList.Builder<T>builder()Creates a new empty builder for building immutable lists.voidclear()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 IndexOutOfBoundsExceptionindexOutOfBoundsException(int index)booleanisEmpty()Iterator<E>iterator()ListIterator<E>listIterator()static <T> List<T>of(T... elements)Creates an immutable list that consists of the given elements.Eremove(int index)booleanremoveIf(Predicate<? super E> filter)protected voidremoveRange(int fromIndex, int toIndex)voidreplaceAll(UnaryOperator<E> operator)Eset(int index, E element)voidsort(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:
addin interfaceCollection<E>- Specified by:
addin interfaceList<E>- Overrides:
addin classAbstractList<E>
-
set
public E set(int index, E element)- Specified by:
setin interfaceList<E>- Overrides:
setin classAbstractList<E>
-
add
public void add(int index, E element)- Specified by:
addin interfaceList<E>- Overrides:
addin classAbstractList<E>
-
remove
public E remove(int index)
- Specified by:
removein interfaceList<E>- Overrides:
removein classAbstractList<E>
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceList<E>- Overrides:
clearin classAbstractList<E>
-
addAll
public boolean addAll(int index, Collection<? extends E> c)- Specified by:
addAllin interfaceList<E>- Overrides:
addAllin classAbstractList<E>
-
removeRange
protected void removeRange(int fromIndex, int toIndex)- Overrides:
removeRangein classAbstractList<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceList<E>- Overrides:
isEmptyin 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:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin interfaceList<E>- Overrides:
iteratorin classAbstractList<E>
-
listIterator
public ListIterator<E> listIterator()
- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classAbstractList<E>
-
spliterator
public Spliterator<E> spliterator()
-
indexOutOfBoundsException
protected IndexOutOfBoundsException indexOutOfBoundsException(int index)
-
-