net.sf.mmm.util.collection.base
Class AbstractClassHierarchieMap<E>

java.lang.Object
  extended by net.sf.mmm.util.collection.base.AbstractClassHierarchieMap<E>
Type Parameters:
E - is the generic type of the elements contained in this map.
Direct Known Subclasses:
AdvancedClassHierarchieMap, SimpleClassHierarchieMap

public abstract class AbstractClassHierarchieMap<E>
extends Object

This is the abstract base class for a simplified Map that associates elements (<E>) with Class objects.

Since:
1.0.1
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Field Summary
private  Map<Class<?>,E> classMap
           
 
Constructor Summary
AbstractClassHierarchieMap()
          The constructor.
AbstractClassHierarchieMap(MapFactory<Map> mapFactory)
          The constructor.
 
Method Summary
 E get(Class<?> type)
          This method gets the element that has been registered for the given type or a sub-type.
protected  boolean isAccepted(Class<?> type)
          This method determines whether the given type is accepted in the hierarchy.
protected  boolean isPreferable(E element, Class<?> elementType, E existing, Class<?> currentType)
          This method determines if the given element should be associated with currentType in preference to the element existing that is already registered and will be replaced according to the result of this method.
protected  E put(Class<?> type, E element)
          This method registers the given element for the given type.
private  void putRecursive(Class<?> type, E element, Class<?> elementType)
          This method performs the put recursively.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classMap

private final Map<Class<?>,E> classMap
See Also:
get(Class)
Constructor Detail

AbstractClassHierarchieMap

public AbstractClassHierarchieMap()
The constructor.


AbstractClassHierarchieMap

public AbstractClassHierarchieMap(MapFactory<Map> mapFactory)
The constructor.

Parameters:
mapFactory - is the factory used to create the internal Map.
Method Detail

get

public E get(Class<?> type)
This method gets the element that has been registered for the given type or a sub-type.

Parameters:
type - is the Class for which the associated element is requested.
Returns:
the element for the given type or null if no element is registered for the given type.

isPreferable

protected boolean isPreferable(E element,
                               Class<?> elementType,
                               E existing,
                               Class<?> currentType)
This method determines if the given element should be associated with currentType in preference to the element existing that is already registered and will be replaced according to the result of this method.

Parameters:
element - is the element to register.
elementType - is the type for which the given element is to be registered originally.
existing - is the element that has already been registered before and is associated with currentType.
currentType - is the registration type.
Returns:
true if the given element is preferable and should replace existing for currentType, false otherwise (if existing should remain associated with currentType).

put

protected E put(Class<?> type,
                E element)
This method registers the given element for the given type. Unlike a regular Map this method will also recursively put the given element for all super-classes and super-interfaces of the given type.

Parameters:
type - is the Class used as key to associate the given element.
element - is the element to put.
Returns:
the element that was associated directly with the given type and has NOW been replaced with element.
See Also:
Map.put(Object, Object)

putRecursive

private void putRecursive(Class<?> type,
                          E element,
                          Class<?> elementType)
This method performs the put recursively.

Parameters:
type - is the current Class used as key to associate the given element.
element - is the element to put.
elementType - is the the type of the original put.

isAccepted

protected boolean isAccepted(Class<?> type)
This method determines whether the given type is accepted in the hierarchy.
This implementation accepts any type. Override this method to ignore specific types (e.g. marker-interfaces).

Parameters:
type - is the Class reflecting the type to check.
Returns:
true if the given type should be accepted, false to ignore type.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.