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 classImmutableListCopy.ExternalizerclassImmutableListCopy.ImmutableSubList
-
Field Summary
Fields Modifier and Type Field Description static Object[]EMPTY_ARRAY
-
Constructor Summary
Constructors Constructor Description ImmutableListCopy()Constructs 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E o)booleanaddAll(int index, Collection<? extends E> c)booleanaddAll(Collection<? extends E> c)booleancontains(Object o)booleanequals(Object o)Eget(int index)inthashCode()intindexOf(Object o)booleanisEmpty()Iterator<E>iterator()intlastIndexOf(Object o)ListIterator<E>listIterator()ListIterator<E>listIterator(int index)booleanremove(Object o)booleanremoveAll(Collection<?> c)booleanretainAll(Collection<?> c)intsize()List<E>subList(int fromIndex, int toIndex)Object[]toArray()<T> T[]toArray(T[] a)
-
-
-
Field Detail
-
EMPTY_ARRAY
public static final Object[] EMPTY_ARRAY
-
-
Constructor Detail
-
ImmutableListCopy
public ImmutableListCopy()
Constructs an empty ImmutableListCopy.
-
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()
-
-