net.sf.molae.pipe.genimpl
Class MapBasedList<K,E>

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

public class MapBasedList<K,E>
extends AbstractList<E>

A list that is based on a map and a list of keys. The list of keys defines for every index the key of the map that corresponds to the index, so that get(i) = map.get(keys.get(index)) . In contrast to a TransformedList, modifications with set affect the map and not the list.

Since:
1.1

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
MapBasedList(Map<K,E> base, List<K> keys)
          Constructs a new MapBasedList.
 
Method Summary
 E get(int index)
           
static
<K,E> TwoWayTransformer<Map<K,E>,List<E>>
Map2ListTransformer(List<K> base)
          Creates a transformer that transforms a map into a MapBasedList.
 E remove(int index)
           
 E set(int index, E element)
           
 int size()
           
 
Methods inherited from class java.util.AbstractList
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, 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

MapBasedList

public MapBasedList(Map<K,E> base,
                    List<K> keys)
Constructs a new MapBasedList.

Parameters:
base - the underlying map
keys - the list of keys
Method Detail

size

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

get

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

set

public E set(int index,
             E element)
Specified by:
set in interface List<E>
Overrides:
set in class AbstractList<E>

remove

public E remove(int index)
Specified by:
remove in interface List<E>
Overrides:
remove in class AbstractList<E>

Map2ListTransformer

public static <K,E> TwoWayTransformer<Map<K,E>,List<E>> Map2ListTransformer(List<K> base)
Creates a transformer that transforms a map into a MapBasedList.

Parameters:
base - The key list of each of the created MapBasedLists.
Returns:
a transformer that transforms a map into a MapBasedList