Class MethodCache


  • public class MethodCache
    extends java.lang.Object
    This class cache's method lookups. Hence first time it introspects the instance's class, while subsequent method lookups are super fast.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private TwoDHashMap<java.lang.String,​java.lang.String,​java.lang.reflect.Method> getCache
      A cache of getter methods.
      private ThreeDHashMap<java.lang.Class<?>,​java.lang.Class<?>,​java.lang.String,​java.lang.reflect.Method> setMethodsCache
      A cache of setter methods.
    • Constructor Summary

      Constructors 
      Constructor Description
      MethodCache()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.reflect.Method getGetMethod​(java.lang.Object object, java.lang.String fieldName)
      Returns the getter method for field on an object.
      <T> java.lang.reflect.Method getSetMethod​(java.lang.Object object, java.lang.String fieldName, java.lang.Class<?> argumentType)
      Returns the setter method for the field on an object.
      • Methods inherited from class java.lang.Object

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

      • setMethodsCache

        private final ThreeDHashMap<java.lang.Class<?>,​java.lang.Class<?>,​java.lang.String,​java.lang.reflect.Method> setMethodsCache
        A cache of setter methods. The three keys are the class the setter is being invoked on, the parameter type of the setter, and the variable name. The value is the setter method.
      • getCache

        private final TwoDHashMap<java.lang.String,​java.lang.String,​java.lang.reflect.Method> getCache
        A cache of getter methods. The two keys are the name of the class the getter is being invoked on, and the variable name. The value is the getter method.
    • Constructor Detail

      • MethodCache

        public MethodCache()
    • Method Detail

      • getGetMethod

        public java.lang.reflect.Method getGetMethod​(java.lang.Object object,
                                                     java.lang.String fieldName)
        Returns the getter method for field on an object.
        Parameters:
        object - the object
        fieldName - the field name
        Returns:
        the getter associated with the field on the object
        Throws:
        java.lang.NullPointerException - if object or fieldName is null
        SuperCsvReflectionException - if the getter doesn't exist or is not visible
      • getSetMethod

        public <T> java.lang.reflect.Method getSetMethod​(java.lang.Object object,
                                                         java.lang.String fieldName,
                                                         java.lang.Class<?> argumentType)
        Returns the setter method for the field on an object.
        Type Parameters:
        T - the object type
        Parameters:
        object - the object
        fieldName - the field name
        argumentType - the type to be passed to the setter
        Returns:
        the setter method associated with the field on the object
        Throws:
        java.lang.NullPointerException - if object, fieldName or fieldType is null
        SuperCsvReflectionException - if the setter doesn't exist or is not visible