org.apache.commons.collections.list
Class TransformedList<I,O>

java.lang.Object
  extended by org.apache.commons.collections.collection.AbstractCollectionDecorator<E>
      extended by org.apache.commons.collections.collection.AbstractSerializableCollectionDecorator
          extended by org.apache.commons.collections.collection.TransformedCollection<I,O>
              extended by org.apache.commons.collections.list.TransformedList<I,O>
All Implemented Interfaces:
Serializable, Iterable, Collection, List

public class TransformedList<I,O>
extends TransformedCollection<I,O>
implements List

Decorates another List to transform objects that are added.

The add and set methods are affected by this class. Thus objects must be removed or searched for using their transformed form. For example, if the transformation converts Strings to Integers, you must use the Integer form to remove objects.

This class is Serializable from Commons Collections 3.1.

Note: This class cannot support generics without breaking the Collection contract.

Since:
Commons Collections 3.0
Version:
$Revision: 1.2 $ $Date: 2005/05/23 14:42:13 $
Author:
Matt Hall, John Watkinson, Stephen Colebourne
See Also:
Serialized Form

Nested Class Summary
protected  class TransformedList.TransformedListIterator
          Inner class Iterator for the TransformedList
 
Field Summary
 
Fields inherited from class org.apache.commons.collections.collection.TransformedCollection
transformer
 
Fields inherited from class org.apache.commons.collections.collection.AbstractCollectionDecorator
collection
 
Constructor Summary
protected TransformedList(List<I> list, Transformer<? super I,? extends O> transformer)
          Constructor that wraps (not copies).
 
Method Summary
 void add(int index, Object object)
           
 boolean addAll(int index, Collection coll)
           
 void addTyped(int index, I object)
          Type-safe version of add(int, Object) (but breaks List interface).
static
<I,O> List<O>
decorate(List<I> list, Transformer<? super I,? extends O> transformer)
          Factory method to create a transforming list.
 O get(int index)
           
protected  List<O> getList()
          Gets the decorated list.
 int indexOf(Object object)
           
 int lastIndexOf(Object object)
           
 ListIterator<O> listIterator()
           
 ListIterator<O> listIterator(int i)
           
 Object remove(int index)
           
 O set(int index, Object object)
           
 O setTyped(int index, I object)
          Type-safe version of set(int, Object) (but breaks List interface).
 List<O> subList(int fromIndex, int toIndex)
           
 
Methods inherited from class org.apache.commons.collections.collection.TransformedCollection
add, addAll, addAllTyped, addTyped, decorate, transform, transform
 
Methods inherited from class org.apache.commons.collections.collection.AbstractCollectionDecorator
clear, contains, containsAll, equals, getCollection, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Constructor Detail

TransformedList

protected TransformedList(List<I> list,
                          Transformer<? super I,? extends O> transformer)
Constructor that wraps (not copies).

If there are any elements already in the list being decorated, they are NOT transformed.

Parameters:
list - the list to decorate, must not be null
transformer - the transformer to use for conversion, must not be null
Throws:
IllegalArgumentException - if list or transformer is null
Method Detail

decorate

public static <I,O> List<O> decorate(List<I> list,
                                     Transformer<? super I,? extends O> transformer)
Factory method to create a transforming list.

If there are any elements already in the list being decorated, they are NOT transformed.

Parameters:
list - the list to decorate, must not be null
transformer - the transformer to use for conversion, must not be null
Throws:
IllegalArgumentException - if list or transformer is null

getList

protected List<O> getList()
Gets the decorated list.

Returns:
the decorated list

get

public O get(int index)
Specified by:
get in interface List

indexOf

public int indexOf(Object object)
Specified by:
indexOf in interface List

lastIndexOf

public int lastIndexOf(Object object)
Specified by:
lastIndexOf in interface List

remove

public Object remove(int index)
Specified by:
remove in interface List

add

public void add(int index,
                Object object)
Specified by:
add in interface List

addTyped

public void addTyped(int index,
                     I object)
Type-safe version of add(int, Object) (but breaks List interface).


addAll

public boolean addAll(int index,
                      Collection coll)
Specified by:
addAll in interface List

listIterator

public ListIterator<O> listIterator()
Specified by:
listIterator in interface List

listIterator

public ListIterator<O> listIterator(int i)
Specified by:
listIterator in interface List

set

public O set(int index,
             Object object)
Specified by:
set in interface List

setTyped

public O setTyped(int index,
                  I object)
Type-safe version of set(int, Object) (but breaks List interface).


subList

public List<O> subList(int fromIndex,
                       int toIndex)
Specified by:
subList in interface List


Copyright © 2005-2005 Apache Software Foundation, Matt Hall, John Watkinson. All Rights Reserved.