Class ReflectionStringConverter<T>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Class<T> cls
      The converted class.
      (package private) TypedFromStringConverter<T> fromString
      Conversion from a string, package-scoped for testing.
      private java.lang.reflect.Method toString
      Conversion to a string.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T convertFromString​(java.lang.Class<? extends T> cls, java.lang.String str)
      Converts the specified object from a String.
      java.lang.String convertToString​(T object)
      Converts the specified object to a String.
      java.lang.Class<?> getEffectiveType()
      Gets the effective type that the converter works on.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • cls

        private final java.lang.Class<T> cls
        The converted class.
      • toString

        private final java.lang.reflect.Method toString
        Conversion to a string.
    • Constructor Detail

      • ReflectionStringConverter

        ReflectionStringConverter​(java.lang.Class<T> cls,
                                  java.lang.reflect.Method toString,
                                  TypedFromStringConverter<T> fromString)
        Creates an instance using two methods.
        Parameters:
        cls - the class this converts for, null creates a from-string converter
        toString - the toString method, not null
        fromString - the fromString converter, not null
        Throws:
        java.lang.RuntimeException - (or subclass) if the method signatures are invalid
    • Method Detail

      • convertToString

        public java.lang.String convertToString​(T object)
        Description copied from interface: ToStringConverter
        Converts the specified object to a String.
        Specified by:
        convertToString in interface ToStringConverter<T>
        Parameters:
        object - the object to convert, not null
        Returns:
        the converted string, may be null but generally not
      • convertFromString

        public T convertFromString​(java.lang.Class<? extends T> cls,
                                   java.lang.String str)
        Description copied from interface: FromStringConverter
        Converts the specified object from a String.
        Specified by:
        convertFromString in interface FromStringConverter<T>
        Parameters:
        cls - the class to convert to, not null
        str - the string to convert, not null
        Returns:
        the converted object, may be null but generally not
      • getEffectiveType

        public java.lang.Class<?> getEffectiveType()
        Description copied from interface: TypedStringConverter
        Gets the effective type that the converter works on.

        For example, if a class declares the FromString and ToString then the effective type of the converter is that class. If a subclass is queried for a converter, then the effective type is that of the superclass.

        Specified by:
        getEffectiveType in interface TypedFromStringConverter<T>
        Specified by:
        getEffectiveType in interface TypedStringConverter<T>
        Returns:
        the effective type
      • toString

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