public class ImmutableListCopy<E> extends java.util.AbstractList<E> implements java.io.Externalizable, Immutables.Immutable
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.
Modifier and Type | Class and Description |
---|---|
private class |
ImmutableListCopy.ImmutableIterator |
private class |
ImmutableListCopy.ImmutableSubList<E> |
Modifier and Type | Field and Description |
---|---|
private E[] |
elements |
private static long |
serialVersionUID |
private int |
size |
Constructor and Description |
---|
ImmutableListCopy()
Constructs a new ImmutableListCopy.
|
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
|
ImmutableListCopy(E[] array)
Assumes that the array passed in is "safe", i.e., is not referenced from elsewhere.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E o) |
boolean |
addAll(java.util.Collection<? extends E> c) |
boolean |
addAll(int index,
java.util.Collection<? extends E> c) |
boolean |
contains(java.lang.Object o) |
E |
get(int index) |
int |
indexOf(java.lang.Object o) |
boolean |
isEmpty() |
java.util.Iterator<E> |
iterator() |
int |
lastIndexOf(java.lang.Object o) |
java.util.ListIterator<E> |
listIterator() |
java.util.ListIterator<E> |
listIterator(int index) |
void |
readExternal(java.io.ObjectInput in)
See
writeExternal(java.io.ObjectOutput) for serialization format |
boolean |
remove(java.lang.Object o) |
boolean |
removeAll(java.util.Collection<?> c) |
boolean |
retainAll(java.util.Collection<?> c) |
int |
size() |
java.util.List<E> |
subList(int fromIndex,
int toIndex) |
java.lang.Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
void |
writeExternal(java.io.ObjectOutput out)
Format: - entry array size (int) - elements (Object)
|
add, clear, equals, hashCode, remove, removeRange, set
private static final long serialVersionUID
private E[] elements
private int size
public ImmutableListCopy()
public ImmutableListCopy(java.util.Collection<? extends E> c)
c
- collection to copy frompublic ImmutableListCopy(E[] array)
array
- to referencepublic final int size()
public final boolean isEmpty()
public final boolean contains(java.lang.Object o)
public final java.util.Iterator<E> iterator()
public final java.lang.Object[] toArray()
public final <T> T[] toArray(T[] a)
public final boolean add(E o)
public final boolean remove(java.lang.Object o)
public final boolean addAll(java.util.Collection<? extends E> c)
public final boolean addAll(int index, java.util.Collection<? extends E> c)
public final boolean removeAll(java.util.Collection<?> c)
public final boolean retainAll(java.util.Collection<?> c)
public final E get(int index)
public final int indexOf(java.lang.Object o)
public final int lastIndexOf(java.lang.Object o)
public final java.util.ListIterator<E> listIterator()
public final java.util.ListIterator<E> listIterator(int index)
public final java.util.List<E> subList(int fromIndex, int toIndex)
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
out
- stream to write tojava.io.IOException
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
writeExternal(java.io.ObjectOutput)
for serialization formatreadExternal
in interface java.io.Externalizable
in
- streamjava.io.IOException
java.lang.ClassNotFoundException