net.sf.molae.pipe.trafo
Class IndexTransformedList<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by net.sf.molae.pipe.trafo.IndexTransformedList<E>
All Implemented Interfaces:
Iterable<E>, Collection<E>, List<E>

public class IndexTransformedList<E>
extends AbstractList<E>

A list which permutes the elements of a base list. Permutation is described by a transformer.


Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
IndexTransformedList(List<E> base, int[] mapping)
          Constructs a IndexTransformdList object.
IndexTransformedList(List<E> base, IntTransformer transformer)
          Constructs a IndexTransformdList object.
 
Method Summary
 void clear()
          Removes all of the elements from this collection (optional operation).
 E get(int index)
          Returns the element at the specified position in this list.
 E set(int index, E element)
          Replaces the element at the specified position in this list with the specified element (optional operation).
 int size()
          Returns the number of elements in this list.
 
Methods inherited from class java.util.AbstractList
add, add, addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, 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
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

IndexTransformedList

public IndexTransformedList(List<E> base,
                            IntTransformer transformer)
Constructs a IndexTransformdList object.

Parameters:
base - the underling lists where the elements are stored.
transformer - describes the index mapping

IndexTransformedList

public IndexTransformedList(List<E> base,
                            int[] mapping)
Constructs a IndexTransformdList object.

Parameters:
base - the underling lists where the elements are stored.
mapping - describes the index mapping
Method Detail

size

public int size()
Returns the number of elements in this list.

Specified by:
size in interface Collection<E>
Specified by:
size in interface List<E>
Specified by:
size in class AbstractCollection<E>
Returns:
the number of elements in this list.

clear

public void clear()
Removes all of the elements from this collection (optional operation).

Specified by:
clear in interface Collection<E>
Specified by:
clear in interface List<E>
Overrides:
clear in class AbstractList<E>
Throws:
UnsupportedOperationException - if the clear method is not supported by the base list

get

public E get(int index)
Returns the element at the specified position in this list. This implementation returns the element at the transformed input index from the base list.

Specified by:
get in interface List<E>
Specified by:
get in class AbstractList<E>
Parameters:
index - index of element to return.
Returns:
the element at the specified position in this list.
Throws:
IndexOutOfBoundsException - if the given index is out of range (index < 0 || index >= size()).

set

public E set(int index,
             E element)
Replaces the element at the specified position in this list with the specified element (optional operation).

This implementation replaces the element at the transformed input index in the base list.

Specified by:
set in interface List<E>
Overrides:
set in class AbstractList<E>
Parameters:
index - index of element to replace.
element - element to be stored at the specified position.
Returns:
the element previously at the specified position.
Throws:
UnsupportedOperationException - if the set method is not supported by the base list.
ClassCastException - if the class of the specified element prevents it from being added to the base list.
IllegalArgumentException - if some aspect of the specified element prevents it from being added to the base list.
IndexOutOfBoundsException - if the specified index is out of range (index < 0 || index >= size()).