Package org.joda.convert
Class ConstructorFromStringConverter<T>
- java.lang.Object
-
- org.joda.convert.ConstructorFromStringConverter<T>
-
- Type Parameters:
T- the type of the converter
- All Implemented Interfaces:
FromStringConverter<T>,TypedFromStringConverter<T>
final class ConstructorFromStringConverter<T> extends java.lang.Object implements TypedFromStringConverter<T>
Conversion from a string using a fromString constructor.The fromString constructor must take a single
Stringparameter.ConstructorFromStringConverter is thread-safe and immutable.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.reflect.Constructor<T>fromStringConversion from a string.
-
Constructor Summary
Constructors Constructor Description ConstructorFromStringConverter(java.lang.Class<T> cls, java.lang.reflect.Constructor<T> fromString)Creates an instance using a method and a constructor.
-
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 the specified object from aString.java.lang.Class<?>getEffectiveType()Gets the effective type that the converter works on.
-
-
-
Field Detail
-
fromString
private final java.lang.reflect.Constructor<T> fromString
Conversion from a string.
-
-
Constructor Detail
-
ConstructorFromStringConverter
ConstructorFromStringConverter(java.lang.Class<T> cls, java.lang.reflect.Constructor<T> fromString)
Creates an instance using a method and a constructor.- Parameters:
cls- the class this converts for, 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)
Description copied from interface:FromStringConverterConverts the specified object from aString.- Specified by:
convertFromStringin interfaceFromStringConverter<T>- 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:TypedFromStringConverterGets 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.- Specified by:
getEffectiveTypein interfaceTypedFromStringConverter<T>- Returns:
- the effective type
-
-