Class AnnotationStringConverterFactory

  • All Implemented Interfaces:
    StringConverterFactory

    final class AnnotationStringConverterFactory
    extends java.lang.Object
    implements StringConverterFactory
    Factory for StringConverter looking up annotations.

    This class is immutable and thread-safe.

    Since:
    1.5
    • Constructor Detail

      • AnnotationStringConverterFactory

        private AnnotationStringConverterFactory()
        Restricted constructor.
    • Method Detail

      • findConverter

        public StringConverter<?> findConverter​(java.lang.Class<?> cls)
        Finds a converter by type.
        Specified by:
        findConverter in interface StringConverterFactory
        Parameters:
        cls - the type to lookup, not null
        Returns:
        the converter, null if not found
        Throws:
        java.lang.RuntimeException - (or subclass) if source code is invalid
      • findAnnotatedConverter

        private <T> StringConverter<T> findAnnotatedConverter​(java.lang.Class<T> cls)
        Finds a converter searching annotated.
        Type Parameters:
        T - the type of the converter
        Parameters:
        cls - the class to find a method for, not null
        Returns:
        the converter, not null
        Throws:
        java.lang.RuntimeException - if none found
      • findToStringMethod

        private java.lang.reflect.Method findToStringMethod​(java.lang.Class<?> cls)
        Finds the conversion method.
        Parameters:
        cls - the class to find a method for, not null
        Returns:
        the method to call, null means use toString
        Throws:
        java.lang.RuntimeException - if invalid
      • findFromStringConstructor

        private <T> MethodConstructorStringConverter<T> findFromStringConstructor​(java.lang.Class<T> cls,
                                                                                  java.lang.reflect.Method toString)
        Finds the conversion method.
        Type Parameters:
        T - the type of the converter
        Parameters:
        cls - the class to find a method for, not null
        toString - the toString method, not null
        Returns:
        the method to call, null means none found
        Throws:
        java.lang.RuntimeException - if invalid
      • findFromStringMethod

        private <T> MethodsStringConverter<T> findFromStringMethod​(java.lang.Class<T> cls,
                                                                   java.lang.reflect.Method toString,
                                                                   boolean searchSuperclasses)
        Finds the conversion method.
        Parameters:
        cls - the class to find a method for, not null
        toString - the toString method, not null
        searchSuperclasses - whether to search superclasses
        Returns:
        the method to call, null means not found
        Throws:
        java.lang.RuntimeException - if invalid
      • findFromString

        private java.lang.reflect.Method findFromString​(java.lang.Class<?> cls)
        Finds the conversion method.
        Parameters:
        cls - the class to find a method for, not null
        matched - the matched method, may be null
        Returns:
        the method to call, null means not found
        Throws:
        java.lang.RuntimeException - if invalid
      • eliminateEnumSubclass

        private java.lang.Class<?> eliminateEnumSubclass​(java.lang.Class<?> cls)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object