org.infinispan.util
Class ImmutableListCopy<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by org.infinispan.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

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ImmutableListCopy()
          Constructs a new ImmutableListCopy.
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
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(Collection<? extends E> c)
           
 boolean addAll(int index, Collection<? extends E> c)
           
 boolean contains(Object o)
           
 E get(int index)
           
 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)
          See writeExternal(java.io.ObjectOutput) for serialization format
 boolean 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, 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(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 from
collection2 - collection to copy from
Method Detail

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

Google Analytics

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