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:
java.io.Externalizable,java.io.Serializable,java.lang.Iterable<E>,java.util.Collection<E>,java.util.List<E>,Immutables.Immutable
@Immutable public class ImmutableListCopy<E> extends java.util.AbstractList<E> implements java.io.Externalizable, 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)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classImmutableListCopy.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(java.util.Collection<? extends E> c)Only one copy constructor since the list is immutable.ImmutableListCopy(java.util.Collection<? extends E> collection1, java.util.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, java.util.Collection<? extends E> c)booleanaddAll(java.util.Collection<? extends E> c)booleancontains(java.lang.Object o)booleanequals(java.lang.Object o)Eget(int index)inthashCode()intindexOf(java.lang.Object o)booleanisEmpty()java.util.Iterator<E>iterator()intlastIndexOf(java.lang.Object o)java.util.ListIterator<E>listIterator()java.util.ListIterator<E>listIterator(int index)voidreadExternal(java.io.ObjectInput in)SeewriteExternal(java.io.ObjectOutput)for serialization formatbooleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)booleanretainAll(java.util.Collection<?> c)intsize()java.util.List<E>subList(int fromIndex, int toIndex)java.lang.Object[]toArray()<T> T[]toArray(T[] a)voidwriteExternal(java.io.ObjectOutput out)Format: - entry array size (int) - elements (Object)
-
-
-
Constructor Detail
-
ImmutableListCopy
public ImmutableListCopy()
Constructs a new ImmutableListCopy. Required by Serialization.
-
ImmutableListCopy
public ImmutableListCopy(java.util.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
-
-
Method Detail
-
size
public final int size()
-
isEmpty
public final boolean isEmpty()
-
contains
public final boolean contains(java.lang.Object o)
-
iterator
public final java.util.Iterator<E> iterator()
-
toArray
public final java.lang.Object[] toArray()
-
toArray
public final <T> T[] toArray(T[] a)
-
add
public final boolean add(E o)
-
remove
public final boolean remove(java.lang.Object o)
-
addAll
public final boolean addAll(java.util.Collection<? extends E> c)
-
addAll
public final boolean addAll(int index, java.util.Collection<? extends E> c)
-
removeAll
public final boolean removeAll(java.util.Collection<?> c)
-
retainAll
public final boolean retainAll(java.util.Collection<?> c)
-
get
public final E get(int index)
-
indexOf
public final int indexOf(java.lang.Object o)
-
lastIndexOf
public final int lastIndexOf(java.lang.Object o)
-
listIterator
public final java.util.ListIterator<E> listIterator()
-
listIterator
public final java.util.ListIterator<E> listIterator(int index)
-
subList
public final java.util.List<E> subList(int fromIndex, int toIndex)
-
equals
public boolean equals(java.lang.Object o)
-
hashCode
public int hashCode()
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOExceptionFormat: - entry array size (int) - elements (Object)- Specified by:
writeExternalin interfacejava.io.Externalizable- Parameters:
out- stream to write to- Throws:
java.io.IOException
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundExceptionSeewriteExternal(java.io.ObjectOutput)for serialization format- Specified by:
readExternalin interfacejava.io.Externalizable- Parameters:
in- stream- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
-