- java.lang.Object
-
- com.github.rvesse.airline.types.DefaultTypeConverterProvider
-
- com.github.rvesse.airline.types.DefaultTypeConverter
-
- All Implemented Interfaces:
TypeConverter,TypeConverterProvider
- Direct Known Subclasses:
ExtendedTypeConverter
public class DefaultTypeConverter extends DefaultTypeConverterProvider implements TypeConverter
The default type converterThis converter supports all the basic Java types plus types. Additionally it supports any class that defines a static
fromString(String)orvalueOf(String)method. Finally it supports any class that defines a constructor that takes a string.
-
-
Field Summary
Fields Modifier and Type Field Description private NumericTypeConverternumericConverter
-
Constructor Summary
Constructors Constructor Description DefaultTypeConverter()DefaultTypeConverter(NumericTypeConverter numericConverter)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidcheckArguments(java.lang.String name, java.lang.Class<?> type, java.lang.String value)Checks that the arguments are all non-nulljava.lang.Objectconvert(java.lang.String name, java.lang.Class<?> type, java.lang.String value)Convert a string value into an appropriately typed valuevoidsetNumericConverter(NumericTypeConverter converter)Sets the numeric type converter to use, ifnullthen default behaviour of the type converter instance (whatever that might be) will be usedprotected ConvertResulttryConvertBasicTypes(java.lang.String name, java.lang.Class<?> type, java.lang.String value)Tries to convert the value if it is one of the common Java typesprotected ConvertResulttryConvertFromString(java.lang.String name, java.lang.Class<?> type, java.lang.String value)Tries to convert the value by invoking a staticfromString(String)method on the typeprotected ConvertResulttryConvertFromValueOf(java.lang.String name, java.lang.Class<?> type, java.lang.String value)Tries to convert the value by invoking a staticvalueOf(String)method on the typeprotected ConvertResulttryConvertStringConstructor(java.lang.String name, java.lang.Class<?> type, java.lang.String value)Tries to convert the value by invoking a constructor that takes a string on the typeprotected ConvertResulttryConvertStringMethod(java.lang.String name, java.lang.Class<?> type, java.lang.String value, java.lang.String methodName)Tries to convert the value by invoking a static method on the type-
Methods inherited from class com.github.rvesse.airline.types.DefaultTypeConverterProvider
getTypeConverter, getTypeConverter
-
-
-
-
Field Detail
-
numericConverter
private NumericTypeConverter numericConverter
-
-
Constructor Detail
-
DefaultTypeConverter
public DefaultTypeConverter()
-
DefaultTypeConverter
public DefaultTypeConverter(NumericTypeConverter numericConverter)
-
-
Method Detail
-
convert
public java.lang.Object convert(java.lang.String name, java.lang.Class<?> type, java.lang.String value)Description copied from interface:TypeConverterConvert a string value into an appropriately typed value- Specified by:
convertin interfaceTypeConverter- Parameters:
name- Option Nametype- Target Typevalue- String Value- Returns:
- Typed value
-
checkArguments
public static void checkArguments(java.lang.String name, java.lang.Class<?> type, java.lang.String value)Checks that the arguments are all non-null- Parameters:
name- Option/Argument nametype- Target typevalue- String to convert
-
tryConvertStringConstructor
protected final ConvertResult tryConvertStringConstructor(java.lang.String name, java.lang.Class<?> type, java.lang.String value)
Tries to convert the value by invoking a constructor that takes a string on the type- Parameters:
type- Typevalue- value- Returns:
- Conversion result
-
tryConvertFromValueOf
protected final ConvertResult tryConvertFromValueOf(java.lang.String name, java.lang.Class<?> type, java.lang.String value)
Tries to convert the value by invoking a staticvalueOf(String)method on the type- Parameters:
type- Typevalue- Value- Returns:
- Conversion result
-
tryConvertFromString
protected final ConvertResult tryConvertFromString(java.lang.String name, java.lang.Class<?> type, java.lang.String value)
Tries to convert the value by invoking a staticfromString(String)method on the type- Parameters:
type- Typevalue- Value- Returns:
- Conversion result
-
tryConvertStringMethod
protected final ConvertResult tryConvertStringMethod(java.lang.String name, java.lang.Class<?> type, java.lang.String value, java.lang.String methodName)
Tries to convert the value by invoking a static method on the type- Parameters:
type- Typevalue- ValuemethodName- Name of the method to invoke- Returns:
- Conversion Result
-
tryConvertBasicTypes
protected final ConvertResult tryConvertBasicTypes(java.lang.String name, java.lang.Class<?> type, java.lang.String value)
Tries to convert the value if it is one of the common Java types- Parameters:
type- Typevalue- Value- Returns:
- Conversion result
-
setNumericConverter
public void setNumericConverter(NumericTypeConverter converter)
Description copied from interface:TypeConverterSets the numeric type converter to use, ifnullthen default behaviour of the type converter instance (whatever that might be) will be used- Specified by:
setNumericConverterin interfaceTypeConverter- Parameters:
converter- Numeric type converter
-
-