TUM CCSM Commons

edu.tum.cs.commons.collections
Class ClassHierarchyMap<T,V>

java.lang.Object
  extended by edu.tum.cs.commons.collections.ClassHierarchyMap<T,V>
Type Parameters:
T - This type parameter allows to specify a lower bound of the classes used as keys. If this is unnecessary, use Object.

public class ClassHierarchyMap<T,V>
extends java.lang.Object

This class provides a mapping from classes to values. The speciality of this class lies in its awareness of the class hierarchy: If no value was found this class tries to retrieve values stored for the super classes of the provided class. If values are stored for multiple super classes of the class the one value that maps to the super class closest to the provided class will be returned.

Version:
$Rev: 26283 $
Author:
Florian Deissenboeck, $Author: juergens $
Rating:
GREEN Hash: C47D9975C69CF7FBCB80888A00CE1A9F

Constructor Summary
ClassHierarchyMap()
           
 
Method Summary
 void clear()
           
 V get(java.lang.Class<?> key)
          Get value stored for a class.
 V get(T element)
          Get value stored for the declaring class of the provided element.
 java.util.List<V> getAll(java.lang.Class<?> key)
          Retrieve a list of values stored for the provided class and its super classes.
 java.util.List<V> getAll(T element)
          Get value list for the declaring class of the provided element.
 V getDeclared(java.lang.Class<?> key)
          Get value stored for this class.
 V getDeclared(T element)
          Get value stored for the declaring class of the provided element.
 boolean isEmpty()
           
 java.util.Set<java.lang.Class<? extends T>> keySet()
           
 V put(java.lang.Class<? extends T> key, V value)
          Store a key-value-pair.
 V remove(java.lang.Class<?> key)
           
 int size()
           
 java.util.Collection<V> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassHierarchyMap

public ClassHierarchyMap()
Method Detail

clear

public void clear()
See Also:
Map.clear()

get

public V get(java.lang.Class<?> key)
Get value stored for a class. If no value was found this method tries to retrieve values stored for the super classes of the provided class. If values are stored for multiple super classes of the class the one value that maps to the super class closest to the provided class will be returned.

If a key is stored for the provided class the performance of this method equals the performance of HashMap.get(Object). Otherwise its worst case performance is O(DIT(key)).

Parameters:
key - the key
Returns:
the value stored for the provided key or one if its super classes or null if no value was found.

get

public V get(T element)
Get value stored for the declaring class of the provided element.

See Also:
get(Class)

getAll

public java.util.List<V> getAll(java.lang.Class<?> key)
Retrieve a list of values stored for the provided class and its super classes. List starts with the value stored for the provided class (if present).

Returns:
the list of values or an empty list of no value was found.

getAll

public java.util.List<V> getAll(T element)
Get value list for the declaring class of the provided element.

See Also:
getAll(Class)

getDeclared

public V getDeclared(java.lang.Class<?> key)
Get value stored for this class. Unlike get(Class) this does not retrieve values stored for super classes.


getDeclared

public V getDeclared(T element)
Get value stored for the declaring class of the provided element. Unlike get(Object) this does not retrieve values stored for super classes.


isEmpty

public boolean isEmpty()
See Also:
Map.isEmpty()

keySet

public java.util.Set<java.lang.Class<? extends T>> keySet()
See Also:
Map.keySet()

put

public V put(java.lang.Class<? extends T> key,
             V value)
Store a key-value-pair.

See Also:
Map.put(Object, Object)

remove

public V remove(java.lang.Class<?> key)
See Also:
Map.remove(Object)

size

public int size()
See Also:
Map.size()

values

public java.util.Collection<V> values()
See Also:
Map.values()

TUM CCSM Commons

TUM CCSM Commons - 2.7