net.sf.molae.pipe.adapt
Class ListAsMap<V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by net.sf.molae.pipe.basic.AbstractMapWithSet<Integer,V>
          extended by net.sf.molae.pipe.adapt.ListAsMap<V>
All Implemented Interfaces:
Map<Integer,V>

public class ListAsMap<V>
extends AbstractMapWithSet<Integer,V>

Map view on a list. The list is seen as a map where the index is the key of each entry.

Since:
2.1

Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.molae.pipe.basic.AbstractMapWithSet
AbstractMapWithSet.EntrySet
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Method Summary
 void clear()
           
 boolean containsKey(Object key)
           
 V get(Object key)
           
protected  Iterator<Map.Entry<Integer,V>> getEntrySetIterator()
          Returns the iterator of the entry set.
static
<V> TwoWayTransformer<List<V>,Map<Integer,V>>
listToMaptransformer()
          Provides a tranformer that transforms a list into its map view.
static
<V> Map<Integer,V>
newInstance(List<V> values, boolean withNulls)
          Creates a new ListAsMap
 V put(Integer key, V value)
           
 V remove(Object key)
           
 int size()
          Returns the number of mappings in this map.
 
Methods inherited from class net.sf.molae.pipe.basic.AbstractMapWithSet
entrySet, keySet
 
Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, isEmpty, putAll, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

newInstance

public static <V> Map<Integer,V> newInstance(List<V> values,
                                             boolean withNulls)
Creates a new ListAsMap

Parameters:
values - underlying list
withNulls - if true all items of the list are incorporated in the map, if false only the non-null values.
Returns:
map view of the specified list

size

public int size()
Description copied from class: AbstractMapWithSet
Returns the number of mappings in this map. This implementation uses the iterator to count the elements.

Specified by:
size in interface Map<Integer,V>
Overrides:
size in class AbstractMapWithSet<Integer,V>
Returns:
the number of mappings in this map.

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<Integer,V>
Overrides:
containsKey in class AbstractMap<Integer,V>

get

public V get(Object key)
Specified by:
get in interface Map<Integer,V>
Overrides:
get in class AbstractMap<Integer,V>

put

public V put(Integer key,
             V value)
Specified by:
put in interface Map<Integer,V>
Overrides:
put in class AbstractMap<Integer,V>

remove

public V remove(Object key)
Specified by:
remove in interface Map<Integer,V>
Overrides:
remove in class AbstractMap<Integer,V>

clear

public void clear()
Specified by:
clear in interface Map<Integer,V>
Overrides:
clear in class AbstractMap<Integer,V>

getEntrySetIterator

protected Iterator<Map.Entry<Integer,V>> getEntrySetIterator()
Description copied from class: AbstractMapWithSet
Returns the iterator of the entry set.

Specified by:
getEntrySetIterator in class AbstractMapWithSet<Integer,V>
Returns:
the iterator of the entry set.

listToMaptransformer

public static final <V> TwoWayTransformer<List<V>,Map<Integer,V>> listToMaptransformer()
Provides a tranformer that transforms a list into its map view. Null-values in the base list are not incorporated in the map.

Returns:
the transformer