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:
Externalizable,Serializable,Iterable<E>,Collection<E>,List<E>,Immutables.Immutable
@Immutable public class ImmutableListCopy<E> extends AbstractList<E> implements 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>
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
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 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)voidreadExternal(ObjectInput in)SeewriteExternal(java.io.ObjectOutput)for serialization formatbooleanremove(Object o)booleanremoveAll(Collection<?> c)booleanretainAll(Collection<?> c)intsize()List<E>subList(int fromIndex, int toIndex)Object[]toArray()<T> T[]toArray(T[] a)voidwriteExternal(ObjectOutput out)Format: - entry array size (int) - elements (Object)-
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
-
-
-
-
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()
- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceList<E>- Specified by:
sizein classAbstractCollection<E>
-
isEmpty
public final boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceList<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
contains
public final boolean contains(Object o)
- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceList<E>- Overrides:
containsin classAbstractCollection<E>
-
toArray
public final Object[] toArray()
- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceList<E>- Overrides:
toArrayin classAbstractCollection<E>
-
toArray
public final <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceList<E>- Overrides:
toArrayin classAbstractCollection<E>
-
add
public final boolean add(E o)
- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceList<E>- Overrides:
addin classAbstractList<E>
-
remove
public final boolean remove(Object o)
- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceList<E>- Overrides:
removein classAbstractCollection<E>
-
addAll
public final boolean addAll(Collection<? extends E> c)
- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceList<E>- Overrides:
addAllin classAbstractCollection<E>
-
addAll
public final boolean addAll(int index, Collection<? extends E> c)
-
removeAll
public final boolean removeAll(Collection<?> c)
- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceList<E>- Overrides:
removeAllin classAbstractCollection<E>
-
retainAll
public final boolean retainAll(Collection<?> c)
- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceList<E>- Overrides:
retainAllin classAbstractCollection<E>
-
get
public final E get(int index)
-
indexOf
public final int indexOf(Object o)
-
lastIndexOf
public final int lastIndexOf(Object o)
- Specified by:
lastIndexOfin interfaceList<E>- Overrides:
lastIndexOfin classAbstractList<E>
-
listIterator
public final ListIterator<E> listIterator()
- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classAbstractList<E>
-
listIterator
public final ListIterator<E> listIterator(int index)
- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classAbstractList<E>
-
equals
public boolean equals(Object o)
- Specified by:
equalsin interfaceCollection<E>- Specified by:
equalsin interfaceList<E>- Overrides:
equalsin classAbstractList<E>
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceCollection<E>- Specified by:
hashCodein interfaceList<E>- Overrides:
hashCodein classAbstractList<E>
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
Format: - entry array size (int) - elements (Object)- Specified by:
writeExternalin interfaceExternalizable- Parameters:
out- stream to write to- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
SeewriteExternal(java.io.ObjectOutput)for serialization format- Specified by:
readExternalin interfaceExternalizable- Parameters:
in- stream- Throws:
IOExceptionClassNotFoundException
-
-