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

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

public abstract class AdvancedClassHierarchieMap<E>
extends AbstractClassHierarchieMap<E>

This class extends AbstractClassHierarchieMap with the ability to replace elements (<E>) on recursive puts if the new element has a more general type.
Therefore an according sub-class has to implement the abstract method getClass(Object).

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

Constructor Summary
AdvancedClassHierarchieMap()
          The constructor.
AdvancedClassHierarchieMap(MapFactory<Map> mapFactory)
          The constructor.
 
Method Summary
protected abstract  Class<?> getClass(E element)
          This method gets the associated type for the given element.
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(E element)
          This method puts the given element using its associated class.
 
Methods inherited from class net.sf.mmm.util.collection.base.AbstractClassHierarchieMap
get, isAccepted, put
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AdvancedClassHierarchieMap

public AdvancedClassHierarchieMap()
The constructor.


AdvancedClassHierarchieMap

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

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

getClass

protected abstract Class<?> getClass(E element)
This method gets the associated type for the given element.

Parameters:
element - is the element for which the type is requested.
Returns:
the Class of the given element.

put

protected E put(E element)
This method puts the given element using its associated class.

Parameters:
element - is the element to put.
Returns:
the element that has been replaced or null if none has been replaced.

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.

Overrides:
isPreferable in class AbstractClassHierarchieMap<E>
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).


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