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 class
class
-
Field Summary
Fields -
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 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)
-
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() -
isEmpty
public final boolean isEmpty() -
contains
-
iterator
-
toArray
-
toArray
public final <T> T[] toArray(T[] a) -
add
-
remove
-
addAll
-
addAll
-
removeAll
-
retainAll
-
get
-
indexOf
-
lastIndexOf
-
listIterator
-
listIterator
-
subList
-
equals
-
hashCode
public int hashCode()
-