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 Classes Modifier and Type Class Description static class
ImmutableListCopy.Externalizer
class
ImmutableListCopy.ImmutableSubList<E>
-
Constructor Summary
Constructors Constructor Description ImmutableListCopy()
Constructs a new 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E o)
boolean
addAll(int index, Collection<? extends E> c)
boolean
addAll(Collection<? extends E> c)
boolean
contains(Object o)
boolean
equals(Object o)
E
get(int index)
int
hashCode()
int
indexOf(Object o)
boolean
isEmpty()
Iterator<E>
iterator()
int
lastIndexOf(Object o)
ListIterator<E>
listIterator()
ListIterator<E>
listIterator(int index)
boolean
remove(Object o)
boolean
removeAll(Collection<?> c)
boolean
retainAll(Collection<?> c)
int
size()
List<E>
subList(int fromIndex, int toIndex)
Object[]
toArray()
<T> T[]
toArray(T[] a)
-
-
-
Constructor Detail
-
ImmutableListCopy
public ImmutableListCopy()
Constructs a new ImmutableListCopy. Required by Serialization.
-
ImmutableListCopy
public ImmutableListCopy(Collection<? extends E> c)
Only one copy constructor since the list is immutable.- Parameters:
c
- collection to copy from
-
ImmutableListCopy
public ImmutableListCopy(E[] array)
Assumes that the array passed in is "safe", i.e., is not referenced from elsewhere. Use with care!- Parameters:
array
- to reference
-
ImmutableListCopy
public ImmutableListCopy(Collection<? extends E> collection1, Collection<? extends E> collection2)
Utility constructors to allow combining collections- Parameters:
collection1
- collection to copy fromcollection2
- collection to copy from
-
-
Method Detail
-
size
public final int size()
-
isEmpty
public final boolean isEmpty()
-
contains
public final boolean contains(Object o)
-
toArray
public final Object[] toArray()
-
toArray
public final <T> T[] toArray(T[] a)
-
add
public final boolean add(E o)
-
remove
public final boolean remove(Object o)
-
addAll
public final boolean addAll(Collection<? extends E> c)
-
addAll
public final boolean addAll(int index, Collection<? extends E> c)
-
removeAll
public final boolean removeAll(Collection<?> c)
-
retainAll
public final boolean retainAll(Collection<?> c)
-
get
public final E get(int index)
-
indexOf
public final int indexOf(Object o)
-
lastIndexOf
public final int lastIndexOf(Object o)
-
listIterator
public final ListIterator<E> listIterator()
-
listIterator
public final ListIterator<E> listIterator(int index)
-
equals
public boolean equals(Object o)
-
hashCode
public int hashCode()
-
-