Package org.infinispan.commons.util
Class ImmutableListCopy<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
org.infinispan.commons.util.ImmutableListCopy<E>
- All Implemented Interfaces:
Iterable<E>,Collection<E>,List<E>,Immutables.Immutable
@Immutable
public class ImmutableListCopy<E>
extends AbstractList<E>
implements Immutables.Immutable
A lightweight, read-only copy of a List. Typically used in place of the common idiom:
return
Collections.unmodifiableList(new ArrayList( myInternalList ));
a it is far more efficient than making a defensive copy and then wrapping the defensive copy in a read-only wrapper.
Also used whenever a read-only reference List is needed.
- Since:
- 4.0
- Author:
- Manik Surtani (manik@jboss.org)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classclass -
Field Summary
FieldsFields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty ImmutableListCopy.ImmutableListCopy(E[] array) Assumes that the array passed in is "safe", i.e., is not referenced from elsewhere.ImmutableListCopy(Collection<? extends E> c) Only one copy constructor since the list is immutable.ImmutableListCopy(Collection<? extends E> collection1, Collection<? extends E> collection2) Utility constructors to allow combining collections -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanfinal booleanaddAll(int index, Collection<? extends E> c) final booleanaddAll(Collection<? extends E> c) final booleanbooleanfinal Eget(int index) inthashCode()final intfinal booleanisEmpty()iterator()final intfinal ListIterator<E>final ListIterator<E>listIterator(int index) final booleanfinal booleanremoveAll(Collection<?> c) final booleanretainAll(Collection<?> c) final intsize()subList(int fromIndex, int toIndex) final Object[]toArray()final <T> T[]toArray(T[] a) Methods inherited from class java.util.AbstractList
add, clear, remove, removeRange, setMethods inherited from class java.util.AbstractCollection
containsAll, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
containsAll, replaceAll, sort, spliterator
-
Field Details
-
EMPTY_ARRAY
-
-
Constructor Details
-
ImmutableListCopy
public ImmutableListCopy()Constructs an empty ImmutableListCopy. -
ImmutableListCopy
Only one copy constructor since the list is immutable.- Parameters:
c- collection to copy from
-
ImmutableListCopy
Assumes that the array passed in is "safe", i.e., is not referenced from elsewhere. Use with care!- Parameters:
array- to reference
-
ImmutableListCopy
Utility constructors to allow combining collections- Parameters:
collection1- collection to copy fromcollection2- collection to copy from
-
-
Method Details
-
size
public final int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceList<E>- Specified by:
sizein classAbstractCollection<E>
-
isEmpty
public final boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceList<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
contains
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceList<E>- Overrides:
containsin classAbstractCollection<E>
-
iterator
-
toArray
- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceList<E>- Overrides:
toArrayin classAbstractCollection<E>
-
toArray
public final <T> T[] toArray(T[] a) - Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceList<E>- Overrides:
toArrayin classAbstractCollection<E>
-
add
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceList<E>- Overrides:
addin classAbstractList<E>
-
remove
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceList<E>- Overrides:
removein classAbstractCollection<E>
-
addAll
- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceList<E>- Overrides:
addAllin classAbstractCollection<E>
-
addAll
-
removeAll
- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceList<E>- Overrides:
removeAllin classAbstractCollection<E>
-
retainAll
- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceList<E>- Overrides:
retainAllin classAbstractCollection<E>
-
get
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOfin interfaceList<E>- Overrides:
lastIndexOfin classAbstractList<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classAbstractList<E>
-
listIterator
- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classAbstractList<E>
-
subList
-
equals
- Specified by:
equalsin interfaceCollection<E>- Specified by:
equalsin interfaceList<E>- Overrides:
equalsin classAbstractList<E>
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceCollection<E>- Specified by:
hashCodein interfaceList<E>- Overrides:
hashCodein classAbstractList<E>
-