org.jboss.cache.util
Class ImmutableListCopy<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
org.jboss.cache.util.ImmutableListCopy<E>
- All Implemented Interfaces:
- Externalizable, Serializable, Iterable<E>, Collection<E>, List<E>
@Immutable
public class ImmutableListCopy<E>
- extends AbstractList<E>
- implements Externalizable
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 (such as in Fqns).
- Since:
- 3.0
- Author:
- Manik Surtani (manik@jboss.org)
- See Also:
- Serialized Form
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
size
public final int size()
- Specified by:
size
in interface Collection<E>
- Specified by:
size
in interface List<E>
- Specified by:
size
in class AbstractCollection<E>
isEmpty
public final boolean isEmpty()
- Specified by:
isEmpty
in interface Collection<E>
- Specified by:
isEmpty
in interface List<E>
- Overrides:
isEmpty
in class AbstractCollection<E>
contains
public final boolean contains(Object o)
- Specified by:
contains
in interface Collection<E>
- Specified by:
contains
in interface List<E>
- Overrides:
contains
in class AbstractCollection<E>
iterator
public final Iterator<E> iterator()
- Specified by:
iterator
in interface Iterable<E>
- Specified by:
iterator
in interface Collection<E>
- Specified by:
iterator
in interface List<E>
- Overrides:
iterator
in class AbstractList<E>
toArray
public final Object[] toArray()
- Specified by:
toArray
in interface Collection<E>
- Specified by:
toArray
in interface List<E>
- Overrides:
toArray
in class AbstractCollection<E>
toArray
public final <T> T[] toArray(T[] a)
- Specified by:
toArray
in interface Collection<E>
- Specified by:
toArray
in interface List<E>
- Overrides:
toArray
in class AbstractCollection<E>
add
public final boolean add(E o)
- Specified by:
add
in interface Collection<E>
- Specified by:
add
in interface List<E>
- Overrides:
add
in class AbstractList<E>
remove
public final boolean remove(Object o)
- Specified by:
remove
in interface Collection<E>
- Specified by:
remove
in interface List<E>
- Overrides:
remove
in class AbstractCollection<E>
addAll
public final boolean addAll(Collection<? extends E> c)
- Specified by:
addAll
in interface Collection<E>
- Specified by:
addAll
in interface List<E>
- Overrides:
addAll
in class AbstractCollection<E>
addAll
public final boolean addAll(int index,
Collection<? extends E> c)
- Specified by:
addAll
in interface List<E>
- Overrides:
addAll
in class AbstractList<E>
removeAll
public final boolean removeAll(Collection<?> c)
- Specified by:
removeAll
in interface Collection<E>
- Specified by:
removeAll
in interface List<E>
- Overrides:
removeAll
in class AbstractCollection<E>
retainAll
public final boolean retainAll(Collection<?> c)
- Specified by:
retainAll
in interface Collection<E>
- Specified by:
retainAll
in interface List<E>
- Overrides:
retainAll
in class AbstractCollection<E>
get
public final E get(int index)
- Specified by:
get
in interface List<E>
- Specified by:
get
in class AbstractList<E>
indexOf
public final int indexOf(Object o)
- Specified by:
indexOf
in interface List<E>
- Overrides:
indexOf
in class AbstractList<E>
lastIndexOf
public final int lastIndexOf(Object o)
- Specified by:
lastIndexOf
in interface List<E>
- Overrides:
lastIndexOf
in class AbstractList<E>
listIterator
public final ListIterator<E> listIterator()
- Specified by:
listIterator
in interface List<E>
- Overrides:
listIterator
in class AbstractList<E>
listIterator
public final ListIterator<E> listIterator(int index)
- Specified by:
listIterator
in interface List<E>
- Overrides:
listIterator
in class AbstractList<E>
subList
public final List<E> subList(int fromIndex,
int toIndex)
- Specified by:
subList
in interface List<E>
- Overrides:
subList
in class AbstractList<E>
writeExternal
public void writeExternal(ObjectOutput out)
throws IOException
- Format:
- entry array size (int)
- elements (Object)
- Specified by:
writeExternal
in interface Externalizable
- Parameters:
out
- stream to write to
- Throws:
IOException
readExternal
public void readExternal(ObjectInput in)
throws IOException,
ClassNotFoundException
- See
writeExternal(java.io.ObjectOutput)
for serialization format
- Specified by:
readExternal
in interface Externalizable
- Parameters:
in
- stream
- Throws:
IOException
ClassNotFoundException
Copyright © 2009 JBoss, a division of Red Hat. All Rights Reserved.