net.sf.molae.pipe.genimpl
Class MapBasedList<K,E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
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
Methods inherited from class java.util.AbstractList |
add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList |
MapBasedList
public MapBasedList(Map<K,E> base,
List<K> keys)
- Constructs a new MapBasedList.
- Parameters:
base
- the underlying mapkeys
- the list of keys
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