Package org.joda.convert
Class MethodsStringConverter<T>
- java.lang.Object
-
- org.joda.convert.ReflectionStringConverter<T>
-
- org.joda.convert.MethodsStringConverter<T>
-
- Type Parameters:
T- the type of the converter
- All Implemented Interfaces:
FromStringConverter<T>,StringConverter<T>,ToStringConverter<T>,TypedStringConverter<T>
final class MethodsStringConverter<T> extends ReflectionStringConverter<T>
Conversion to and from a string using two methods.The toString method must meet the following signature:
String anyName()on Class T.The fromString method must meet the following signature:
static T anyName(String)on any class.MethodsStringConverter is thread-safe and immutable.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Class<?>effectiveTypeEffective type.private java.lang.reflect.MethodfromStringConversion from a string.
-
Constructor Summary
Constructors Constructor Description MethodsStringConverter(java.lang.Class<T> cls, java.lang.reflect.Method toString, java.lang.reflect.Method fromString, java.lang.Class<?> effectiveType)Creates an instance using two methods.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TconvertFromString(java.lang.Class<? extends T> cls, java.lang.String str)Converts theStringto an object.java.lang.Class<?>getEffectiveType()Gets the effective type that the converter works on.-
Methods inherited from class org.joda.convert.ReflectionStringConverter
convertToString, toString
-
-
-
-
Constructor Detail
-
MethodsStringConverter
MethodsStringConverter(java.lang.Class<T> cls, java.lang.reflect.Method toString, java.lang.reflect.Method fromString, java.lang.Class<?> effectiveType)
Creates an instance using two methods.- Parameters:
cls- the class this converts for, not nulltoString- the toString method, not nullfromString- the fromString method, not null- Throws:
java.lang.RuntimeException- (or subclass) if the method signatures are invalid
-
-
Method Detail
-
convertFromString
public T convertFromString(java.lang.Class<? extends T> cls, java.lang.String str)
Converts theStringto an object.- Parameters:
cls- the class to convert to, not nullstr- 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:TypedStringConverterGets the effective type that the converter works on.For example, if a class declares the
FromStringandToStringthen 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.- Returns:
- the effective type
-
-