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
Modifier and TypeClassDescriptionstatic class
class
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorDescriptionConstructs 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 boolean
final boolean
addAll
(int index, Collection<? extends E> c) final boolean
addAll
(Collection<? extends E> c) final boolean
boolean
final E
get
(int index) int
hashCode()
final int
final boolean
isEmpty()
iterator()
final int
final ListIterator<E>
final ListIterator<E>
listIterator
(int index) final boolean
final boolean
removeAll
(Collection<?> c) final boolean
retainAll
(Collection<?> c) final int
size()
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, set
Methods inherited from class java.util.AbstractCollection
containsAll, 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.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:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceList<E>
- Specified by:
size
in classAbstractCollection<E>
-
isEmpty
public final boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceList<E>
- Overrides:
isEmpty
in classAbstractCollection<E>
-
contains
- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceList<E>
- Overrides:
contains
in classAbstractCollection<E>
-
iterator
-
toArray
- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceList<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
toArray
public final <T> T[] toArray(T[] a) - Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceList<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
add
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceList<E>
- Overrides:
add
in classAbstractList<E>
-
remove
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceList<E>
- Overrides:
remove
in classAbstractCollection<E>
-
addAll
- Specified by:
addAll
in interfaceCollection<E>
- Specified by:
addAll
in interfaceList<E>
- Overrides:
addAll
in classAbstractCollection<E>
-
addAll
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E>
- Specified by:
removeAll
in interfaceList<E>
- Overrides:
removeAll
in classAbstractCollection<E>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<E>
- Specified by:
retainAll
in interfaceList<E>
- Overrides:
retainAll
in classAbstractCollection<E>
-
get
-
indexOf
-
lastIndexOf
- Specified by:
lastIndexOf
in interfaceList<E>
- Overrides:
lastIndexOf
in classAbstractList<E>
-
listIterator
- Specified by:
listIterator
in interfaceList<E>
- Overrides:
listIterator
in classAbstractList<E>
-
listIterator
- Specified by:
listIterator
in interfaceList<E>
- Overrides:
listIterator
in classAbstractList<E>
-
subList
-
equals
- Specified by:
equals
in interfaceCollection<E>
- Specified by:
equals
in interfaceList<E>
- Overrides:
equals
in classAbstractList<E>
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<E>
- Specified by:
hashCode
in interfaceList<E>
- Overrides:
hashCode
in classAbstractList<E>
-