org.jboss.cache.util
Class ImmutableListCopy<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by org.jboss.cache.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 (such as in Fqns).

Since:
3.0
Author:
Manik Surtani (manik AT jboss DOT org)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
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.
 
Method Summary
 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)
 
Methods inherited from class java.util.AbstractList
add, clear, equals, hashCode, 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.List
containsAll
 

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

ImmutableListCopy

public ImmutableListCopy(java.util.Collection<? extends E> collection1,
                         java.util.Collection<? extends E> collection2)
Utility constructors to allow combining collections

Parameters:
collection1 - collection to copy from
collection2 - collection to copy from
Method Detail

size

public final int size()
Specified by:
size in interface java.util.Collection<E>
Specified by:
size in interface java.util.List<E>
Specified by:
size in class java.util.AbstractCollection<E>

isEmpty

public final boolean isEmpty()
Specified by:
isEmpty in interface java.util.Collection<E>
Specified by:
isEmpty in interface java.util.List<E>
Overrides:
isEmpty in class java.util.AbstractCollection<E>

contains

public final boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection<E>
Specified by:
contains in interface java.util.List<E>
Overrides:
contains in class java.util.AbstractCollection<E>

iterator

public final java.util.Iterator<E> iterator()
Specified by:
iterator in interface java.lang.Iterable<E>
Specified by:
iterator in interface java.util.Collection<E>
Specified by:
iterator in interface java.util.List<E>
Overrides:
iterator in class java.util.AbstractList<E>

toArray

public final java.lang.Object[] toArray()
Specified by:
toArray in interface java.util.Collection<E>
Specified by:
toArray in interface java.util.List<E>
Overrides:
toArray in class java.util.AbstractCollection<E>

toArray

public final <T> T[] toArray(T[] a)
Specified by:
toArray in interface java.util.Collection<E>
Specified by:
toArray in interface java.util.List<E>
Overrides:
toArray in class java.util.AbstractCollection<E>

add

public final boolean add(E o)
Specified by:
add in interface java.util.Collection<E>
Specified by:
add in interface java.util.List<E>
Overrides:
add in class java.util.AbstractList<E>

remove

public final boolean remove(java.lang.Object o)
Specified by:
remove in interface java.util.Collection<E>
Specified by:
remove in interface java.util.List<E>
Overrides:
remove in class java.util.AbstractCollection<E>

addAll

public final boolean addAll(java.util.Collection<? extends E> c)
Specified by:
addAll in interface java.util.Collection<E>
Specified by:
addAll in interface java.util.List<E>
Overrides:
addAll in class java.util.AbstractCollection<E>

addAll

public final boolean addAll(int index,
                            java.util.Collection<? extends E> c)
Specified by:
addAll in interface java.util.List<E>
Overrides:
addAll in class java.util.AbstractList<E>

removeAll

public final boolean removeAll(java.util.Collection<?> c)
Specified by:
removeAll in interface java.util.Collection<E>
Specified by:
removeAll in interface java.util.List<E>
Overrides:
removeAll in class java.util.AbstractCollection<E>

retainAll

public final boolean retainAll(java.util.Collection<?> c)
Specified by:
retainAll in interface java.util.Collection<E>
Specified by:
retainAll in interface java.util.List<E>
Overrides:
retainAll in class java.util.AbstractCollection<E>

get

public final E get(int index)
Specified by:
get in interface java.util.List<E>
Specified by:
get in class java.util.AbstractList<E>

indexOf

public final int indexOf(java.lang.Object o)
Specified by:
indexOf in interface java.util.List<E>
Overrides:
indexOf in class java.util.AbstractList<E>

lastIndexOf

public final int lastIndexOf(java.lang.Object o)
Specified by:
lastIndexOf in interface java.util.List<E>
Overrides:
lastIndexOf in class java.util.AbstractList<E>

listIterator

public final java.util.ListIterator<E> listIterator()
Specified by:
listIterator in interface java.util.List<E>
Overrides:
listIterator in class java.util.AbstractList<E>

listIterator

public final java.util.ListIterator<E> listIterator(int index)
Specified by:
listIterator in interface java.util.List<E>
Overrides:
listIterator in class java.util.AbstractList<E>

subList

public final java.util.List<E> subList(int fromIndex,
                                       int toIndex)
Specified by:
subList in interface java.util.List<E>
Overrides:
subList in class java.util.AbstractList<E>

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Format: - entry array size (int) - elements (Object)

Specified by:
writeExternal in interface java.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.ClassNotFoundException
See writeExternal(java.io.ObjectOutput) for serialization format

Specified by:
readExternal in interface java.io.Externalizable
Parameters:
in - stream
Throws:
java.io.IOException
java.lang.ClassNotFoundException


Copyright © 2009 JBoss, a division of Red Hat. All Rights Reserved.