Class MethodFromStringConverter<T>

java.lang.Object
org.joda.convert.MethodFromStringConverter<T>
Type Parameters:
T - the type of the converter
All Implemented Interfaces:
FromStringConverter<T>, TypedFromStringConverter<T>

final class MethodFromStringConverter<T> extends Object implements TypedFromStringConverter<T>
Conversion from a string using a static method.

The fromString method must meet the following signature:
static T anyName(String) on any class.

MethodFromStringConverter is thread-safe and immutable.

  • Field Details

    • fromString

      private final Method fromString
      Conversion from a string.
    • effectiveType

      private final Class<?> effectiveType
      Effective type.
  • Constructor Details

    • MethodFromStringConverter

      MethodFromStringConverter(Class<T> cls, Method fromString, Class<?> effectiveType)
      Creates an instance using two methods.
      Parameters:
      cls - the class this converts for, not null
      fromString - the fromString method, not null
      Throws:
      RuntimeException - (or subclass) if the method signatures are invalid
  • Method Details

    • convertFromString

      public T convertFromString(Class<? extends T> cls, 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 Class<?> getEffectiveType()
      Description copied from interface: TypedFromStringConverter
      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>
      Returns:
      the effective type