Package org.bson.util

Class ClassMap<T>

  • Type Parameters:
    T - the type of the value in this map

    @Deprecated
    public class ClassMap<T>
    extends Object
    Deprecated.
    there is no replacement for this class

    Maps Class objects to values. A ClassMap is different from a regular Map in that get(clazz) does not only look to see if clazz is a key in the Map, but also walks the up superclass and interface graph of clazz to find matches. Derived matches of this sort are then cached in the registry so that matches are faster on future gets.

    This is a very useful class for Class based registries.

    Example:

    
     ClassMap<String> m = new ClassMap<String>();
     m.put(Animal.class, "Animal");
     m.put(Fox.class, "Fox");
     m.get(Fox.class) --> "Fox"
     m.get(Dog.class) --> "Animal"
      
    (assuming Dog.class < Animal.class)
    • Constructor Summary

      Constructors 
      Constructor Description
      ClassMap()
      Deprecated.
       
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void clear()
      Deprecated.
      As per java.util.Map, removes all of the mappings from this map (optional operation).
      T get​(Object key)
      Deprecated.
      Gets the value associated with either this Class or a superclass of this class.
      static <T> List<Class<?>> getAncestry​(Class<T> clazz)
      Deprecated.
      Helper method that walks superclass and interface graph, superclasses first, then interfaces, to compute an ancestry list.
      boolean isEmpty()
      Deprecated.
      As per java.util.Map, returns true if this map contains no key-value mappings.
      T put​(Class<?> key, T value)
      Deprecated.
      As per java.util.Map, associates the specified value with the specified key in this map.
      T remove​(Object key)
      Deprecated.
      As per java.util.Map, removes the mapping for a key from this map if it is present
      int size()
      Deprecated.
      As per java.util.Map, returns the number of key-value mappings in this map.
    • Constructor Detail

      • ClassMap

        public ClassMap()
        Deprecated.
    • Method Detail

      • getAncestry

        public static <T> List<Class<?>> getAncestry​(Class<T> clazz)
        Deprecated.
        Helper method that walks superclass and interface graph, superclasses first, then interfaces, to compute an ancestry list. Super types are visited left to right. Duplicates are removed such that no Class will appear in the list before one of its subtypes.
        Type Parameters:
        T - the type of the class modeled by this Class object.
        Parameters:
        clazz - the class to get the ancestors for
        Returns:
        a list of all the super classes of clazz, starting with the class, and ending with java.lang.Object.
      • get

        public T get​(Object key)
        Deprecated.
        Gets the value associated with either this Class or a superclass of this class. If fetching for a super class, it fetches the value for the closest superclass. Returns null if the given class and none of its superclasses are in the map.
        Parameters:
        key - a Class to get the value for
        Returns:
        the value for either this class or its nearest superclass
      • put

        public T put​(Class<?> key,
                     T value)
        Deprecated.
        As per java.util.Map, associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced by the specified value.
        Parameters:
        key - a Class key
        value - the value for this class
        Returns:
        the previous value associated with key, or null if there was no mapping for key.
        See Also:
        Map.put(Object, Object)
      • remove

        public T remove​(Object key)
        Deprecated.
        As per java.util.Map, removes the mapping for a key from this map if it is present
        Parameters:
        key - a Class key
        Returns:
        the previous value associated with key, or null if there was no mapping for key.
        See Also:
        Map.remove(Object)
      • clear

        public void clear()
        Deprecated.
        As per java.util.Map, removes all of the mappings from this map (optional operation).
        See Also:
        Map.clear()
      • size

        public int size()
        Deprecated.
        As per java.util.Map, returns the number of key-value mappings in this map. This will only return the number of keys explicitly added to the map, not any cached hierarchy keys.
        Returns:
        the size of this map
        See Also:
        Map.size()
      • isEmpty

        public boolean isEmpty()
        Deprecated.
        As per java.util.Map, returns true if this map contains no key-value mappings.
        Returns:
        true if there are no values in the map
        See Also:
        Map.isEmpty()