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 class
ImmutableListCopy.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 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)
void
readExternal(ObjectInput in)
SeewriteExternal(java.io.ObjectOutput)
for serialization formatboolean
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)
void
writeExternal(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:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceList<E>
- Specified by:
size
in classAbstractCollection<E>
-
isEmpty
public final boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceList<E>
- Overrides:
isEmpty
in classAbstractCollection<E>
-
contains
public final boolean contains(Object o)
- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceList<E>
- Overrides:
contains
in classAbstractCollection<E>
-
toArray
public final Object[] toArray()
- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceList<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
toArray
public final <T> T[] toArray(T[] a)
- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceList<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
add
public final boolean add(E o)
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceList<E>
- Overrides:
add
in classAbstractList<E>
-
remove
public final boolean remove(Object o)
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceList<E>
- Overrides:
remove
in classAbstractCollection<E>
-
addAll
public final boolean addAll(Collection<? extends E> c)
- Specified by:
addAll
in interfaceCollection<E>
- Specified by:
addAll
in interfaceList<E>
- Overrides:
addAll
in classAbstractCollection<E>
-
addAll
public final boolean addAll(int index, Collection<? extends E> c)
-
removeAll
public final boolean removeAll(Collection<?> c)
- Specified by:
removeAll
in interfaceCollection<E>
- Specified by:
removeAll
in interfaceList<E>
- Overrides:
removeAll
in classAbstractCollection<E>
-
retainAll
public final boolean retainAll(Collection<?> c)
- Specified by:
retainAll
in interfaceCollection<E>
- Specified by:
retainAll
in interfaceList<E>
- Overrides:
retainAll
in 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:
lastIndexOf
in interfaceList<E>
- Overrides:
lastIndexOf
in classAbstractList<E>
-
listIterator
public final ListIterator<E> listIterator()
- Specified by:
listIterator
in interfaceList<E>
- Overrides:
listIterator
in classAbstractList<E>
-
listIterator
public final ListIterator<E> listIterator(int index)
- Specified by:
listIterator
in interfaceList<E>
- Overrides:
listIterator
in classAbstractList<E>
-
equals
public boolean equals(Object o)
- Specified by:
equals
in interfaceCollection<E>
- Specified by:
equals
in interfaceList<E>
- Overrides:
equals
in classAbstractList<E>
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfaceCollection<E>
- Specified by:
hashCode
in interfaceList<E>
- Overrides:
hashCode
in classAbstractList<E>
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
Format: - entry array size (int) - elements (Object)- Specified by:
writeExternal
in 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:
readExternal
in interfaceExternalizable
- Parameters:
in
- stream- Throws:
IOException
ClassNotFoundException
-
-