Class InheritableValueMap


  • public class InheritableValueMap
    extends java.lang.Object
    Associate a class and an value object and resolve the mapping through the class hierachy. For example, if a value object A is assosiated with Number class that means it is associated with the Number class and all the subclasses of object class. However, if a mapping exists for Integer, the InheritableValueMap will return the value object associated for the Integer. The stopClass controls when the InheritableValueMap stop resolving mapping and return null (when c==stopClass.getSuperClass()). The stopClass also control the hierachy of object that can be added the the map - meaning stopClass.isAssignableFrom(c) must evaluate to true when c is added as mapping key.
    Version:
    $Id: InheritableValueMap.java,v 1.3 2005/02/17 19:57:31 thlee Exp $ $Name: $
    Author:
    TiongHiang Lee (thlee@onemindsoft.org)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map _map
      the mapping *
      private java.lang.Class _stopClass
      the stop class *
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Set keySet()
      Return the key classes
      void put​(java.lang.Class c, java.lang.Object o)
      Add the mapping between the class c and the object o.
      java.lang.Object resolve​(java.lang.Class c)
      Resolve the object associated with class c
      java.util.Collection resolveAll​(java.lang.Class c)
      Resolve all the mapping that could have apply to c in class c's inheritance hierachy
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • _map

        private java.util.Map _map
        the mapping *
      • _stopClass

        private java.lang.Class _stopClass
        the stop class *
    • Constructor Detail

      • InheritableValueMap

        public InheritableValueMap()
        Use Object.class as stop class
      • InheritableValueMap

        public InheritableValueMap​(java.lang.Class stopClass)
        Parameters:
        stopClass - the stop class
    • Method Detail

      • put

        public void put​(java.lang.Class c,
                        java.lang.Object o)
        Add the mapping between the class c and the object o. The object o must be the stopClass or a subclass of the stopClass
        Parameters:
        c - the class
        o - the object
      • resolve

        public java.lang.Object resolve​(java.lang.Class c)
        Resolve the object associated with class c
        Parameters:
        c - the class
        Returns:
        the object associated with class c, or null
      • keySet

        public final java.util.Set keySet()
        Return the key classes
        Returns:
        the classes
      • resolveAll

        public java.util.Collection resolveAll​(java.lang.Class c)
        Resolve all the mapping that could have apply to c in class c's inheritance hierachy
        Parameters:
        c - the class
        Returns:
        the Collection contains all the mappings