javautils.maps
Class ObjectToListMap

java.lang.Object
  |
  +--javautils.maps.AbstractTypedMap
        |
        +--javautils.maps.ObjectToListMap
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public final class ObjectToListMap
extends AbstractTypedMap

Map from objects to non-null List-objects. This class is designed mainly for convenience.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javautils.maps.AbstractTypedMap
map
 
Constructor Summary
ObjectToListMap()
          A new map based on HashMap.
ObjectToListMap(java.util.Collection keys)
          A new map that maps the given keys to new ArrayList-instances.
ObjectToListMap(java.util.Map map)
          A new Object->List map using the given map.
ObjectToListMap(java.util.Map aMap, java.util.Collection keys, java.lang.Class listType)
          A new Object->List map using the given map, with the specifified keys mapped to new instances of the specified list type.
 
Method Summary
 java.util.List ensuredGet(java.lang.Object key)
           return ensuredGet(key, ArrayList.class);
 java.util.List ensuredGet(java.lang.Object key, java.lang.Class listType)
          Returns the value associated with the specified key or associates a new instance of the specified List-class with the key and returns the new instance.
 java.util.List get(java.lang.Object key)
          The value associated with the specified key or null.
 java.util.List getOrEmptyUnmodifiableList(java.lang.Object key)
          The value associated with the key or an empty, unmodifiable list if no value is associated with the key.
 void put(java.lang.Object key, java.util.List value)
          Associates the key with the specified value.
 void transformListsToUnmodifiableLists()
          Makes the lists in the map unmodifiable.
protected  boolean valuePredicate(java.lang.Object value)
          True iff the value is a non null List-object.
 
Methods inherited from class javautils.maps.AbstractTypedMap
clear, clone, containsKey, isEmpty, keyIterator, keySet, remove, size, toString, unmodifiableMap, valueIterator
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ObjectToListMap

public ObjectToListMap()

A new map based on HashMap.


ObjectToListMap

public ObjectToListMap(java.util.Collection keys)

A new map that maps the given keys to new ArrayList-instances.


ObjectToListMap

public ObjectToListMap(java.util.Map aMap,
                       java.util.Collection keys,
                       java.lang.Class listType)

A new Object->List map using the given map, with the specifified keys mapped to new instances of the specified list type. The given map must not contain any null values not values that are not instances of List. The given map should also never be modified except by using the services of this class.


ObjectToListMap

public ObjectToListMap(java.util.Map map)

A new Object->List map using the given map. The given map must not contain any null values not values that are not instances of List. The given map should also never be modified except by using the services of this class.

Method Detail

valuePredicate

protected boolean valuePredicate(java.lang.Object value)

True iff the value is a non null List-object.

Specified by:
valuePredicate in class AbstractTypedMap

put

public void put(java.lang.Object key,
                java.util.List value)

Associates the key with the specified value.


get

public java.util.List get(java.lang.Object key)

The value associated with the specified key or null.


ensuredGet

public java.util.List ensuredGet(java.lang.Object key)
 return ensuredGet(key, ArrayList.class);
 


ensuredGet

public java.util.List ensuredGet(java.lang.Object key,
                                 java.lang.Class listType)

Returns the value associated with the specified key or associates a new instance of the specified List-class with the key and returns the new instance.


getOrEmptyUnmodifiableList

public java.util.List getOrEmptyUnmodifiableList(java.lang.Object key)

The value associated with the key or an empty, unmodifiable list if no value is associated with the key.


transformListsToUnmodifiableLists

public void transformListsToUnmodifiableLists()

Makes the lists in the map unmodifiable.