Class WeakTypeCache<T>

  • Type Parameters:
    T - the cached type

    public abstract class WeakTypeCache<T>
    extends java.lang.Object
    A weak class cache that instantiates does not a hold a strong reference to either the classloader or class.

    It creates the class specific data in two stages to avoid recursion.

    instantiate - creates the data
    generate - fills in the details

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.ClassLoader,​java.util.Map<java.lang.String,​T>> cache
      The cache
    • Constructor Summary

      Constructors 
      Constructor Description
      WeakTypeCache()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract void generate​(java.lang.Class<?> clazz, T result)
      Fill in the result
      protected abstract void generate​(java.lang.reflect.ParameterizedType type, T result)
      Fill in the result
      T get​(java.lang.reflect.Type type)
      Get the information for a type
      T get​(java.lang.String name, java.lang.ClassLoader cl)
      Get the information for a class
      protected T getClass​(java.lang.Class<?> clazz)
      Get the information for a class
      protected java.util.Map<java.lang.String,​T> getClassLoaderCache​(java.lang.ClassLoader cl)
      Get the cache for the classloader
      protected T getGenericArrayType​(java.lang.reflect.GenericArrayType type)
      Get the information for an array type
      protected T getParameterizedType​(java.lang.reflect.ParameterizedType type)
      Get the information for a parameterized type
      protected <D extends java.lang.reflect.GenericDeclaration>
      T
      getTypeVariable​(java.lang.reflect.TypeVariable<D> type)
      Get the information for a type variable
      protected T getWildcardType​(java.lang.reflect.WildcardType type)
      Get the information for a wildcard type
      protected abstract T instantiate​(java.lang.Class<?> clazz)
      Instantiate for a class
      protected abstract T instantiate​(java.lang.reflect.ParameterizedType type)
      Instantiate for a parameterized type
      protected T peek​(java.lang.Class<?> clazz)
      Peek into the cache
      protected T peek​(java.lang.reflect.ParameterizedType type)
      Peek into the cache
      protected void put​(java.lang.Class<?> clazz, T result)
      Put a result into the cache
      protected void put​(java.lang.reflect.ParameterizedType type, T result)
      Put a result into the cache
      • Methods inherited from class java.lang.Object

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

      • cache

        private java.util.Map<java.lang.ClassLoader,​java.util.Map<java.lang.String,​T>> cache
        The cache
    • Constructor Detail

      • WeakTypeCache

        public WeakTypeCache()
    • Method Detail

      • get

        public T get​(java.lang.reflect.Type type)
        Get the information for a type
        Parameters:
        type - the type
        Returns:
        the info
      • get

        public T get​(java.lang.String name,
                     java.lang.ClassLoader cl)
              throws java.lang.ClassNotFoundException
        Get the information for a class
        Parameters:
        name - the name
        cl - the classloader
        Returns:
        the info
        Throws:
        java.lang.ClassNotFoundException - when the class cannot be found
      • instantiate

        protected abstract T instantiate​(java.lang.Class<?> clazz)
        Instantiate for a class
        Parameters:
        clazz - the class
        Returns:
        the result
      • generate

        protected abstract void generate​(java.lang.Class<?> clazz,
                                         T result)
        Fill in the result
        Parameters:
        clazz - the class
        result - the result
      • instantiate

        protected abstract T instantiate​(java.lang.reflect.ParameterizedType type)
        Instantiate for a parameterized type
        Parameters:
        type - the parameterized type
        Returns:
        the result
      • generate

        protected abstract void generate​(java.lang.reflect.ParameterizedType type,
                                         T result)
        Fill in the result
        Parameters:
        type - the parameterized type
        result - the result
      • getParameterizedType

        protected T getParameterizedType​(java.lang.reflect.ParameterizedType type)
        Get the information for a parameterized type
        Parameters:
        type - the parameterized type
        Returns:
        the info
      • getWildcardType

        protected T getWildcardType​(java.lang.reflect.WildcardType type)
        Get the information for a wildcard type
        Parameters:
        type - the paremeterized type
        Returns:
        the info
      • getTypeVariable

        protected <D extends java.lang.reflect.GenericDeclaration> T getTypeVariable​(java.lang.reflect.TypeVariable<D> type)
        Get the information for a type variable
        Type Parameters:
        D - the declaration
        Parameters:
        type - the type variable
        Returns:
        the info
      • getGenericArrayType

        protected T getGenericArrayType​(java.lang.reflect.GenericArrayType type)
        Get the information for an array type
        Parameters:
        type - the array type
        Returns:
        the info
      • peek

        protected T peek​(java.lang.reflect.ParameterizedType type)
        Peek into the cache
        Parameters:
        type - the type
        Returns:
        the value
      • put

        protected void put​(java.lang.reflect.ParameterizedType type,
                           T result)
        Put a result into the cache
        Parameters:
        type - the type
        result - the value
      • getClass

        protected T getClass​(java.lang.Class<?> clazz)
        Get the information for a class
        Parameters:
        clazz - the class
        Returns:
        the info
      • peek

        protected T peek​(java.lang.Class<?> clazz)
        Peek into the cache
        Parameters:
        clazz - the class
        Returns:
        the value
      • put

        protected void put​(java.lang.Class<?> clazz,
                           T result)
        Put a result into the cache
        Parameters:
        clazz - the class
        result - the value
      • getClassLoaderCache

        protected java.util.Map<java.lang.String,​T> getClassLoaderCache​(java.lang.ClassLoader cl)
        Get the cache for the classloader
        Parameters:
        cl - the classloader
        Returns:
        the map