java.lang.Object
com.github.rvesse.airline.types.DefaultTypeConverterProvider
com.github.rvesse.airline.types.DefaultTypeConverter
- All Implemented Interfaces:
TypeConverter,TypeConverterProvider
- Direct Known Subclasses:
ExtendedTypeConverter
The default type converter
This converter supports all the basic Java types plus types. Additionally it supports any class that defines a static
fromString(String) or valueOf(String) method. Finally it supports any class that defines a
constructor that takes a string.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of the default type converter with the defaultNumericTypeConverterconfiguredDefaultTypeConverter(NumericTypeConverter numericConverter) Creates a new instance of the default type converter -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckArguments(String name, Class<?> type, String value) Checks that the arguments are all non-nullConvert 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 final ConvertResulttryConvertBasicTypes(String name, Class<?> type, String value) Tries to convert the value if it is one of the common Java typesprotected final <T> ConvertResulttryConvertConstructor(String name, Class<?> type, String value, Class<T> parameterType) Tries to convert the value by invoking a constructor that takes a string on the typeprotected final ConvertResulttryConvertFromString(String name, Class<?> type, String value) Tries to convert the value by invoking a staticfromString(String)method on the typeprotected final ConvertResulttryConvertFromValueOf(String name, Class<?> type, String value) Tries to convert the value by invoking a staticvalueOf(String)method on the typeprotected final ConvertResulttryConvertStringConstructor(String name, Class<?> type, String value) Tries to convert the value by invoking a constructor that takes a string on the typeprotected final ConvertResulttryConvertStringMethod(Class<?> type, String value, String methodName, Class<?> parameterType) Tries to convert the value by invoking a static method on the typeprotected final ConvertResulttryConvertStringMethod(String name, Class<?> type, String value, String methodName) Tries to convert the value by invoking a static method on theMethods inherited from class com.github.rvesse.airline.types.DefaultTypeConverterProvider
getTypeConverter, getTypeConverter
-
Field Details
-
numericConverter
-
-
Constructor Details
-
DefaultTypeConverter
public DefaultTypeConverter()Creates a new instance of the default type converter with the defaultNumericTypeConverterconfigured -
DefaultTypeConverter
Creates a new instance of the default type converter- Parameters:
numericConverter- Numeric type converter to use, ifnullthenDefaultNumericConverteris used
-
-
Method Details
-
convert
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
Checks that the arguments are all non-null- Parameters:
name- Option/Argument nametype- Target typevalue- String to convert
-
tryConvertStringConstructor
Tries to convert the value by invoking a constructor that takes a string on the typeConsiders two variants of the constructor, one which takes
Stringas its parameter type and if that doesn't exist one that takesCharSequenceas it's parameter type- Parameters:
type- Typevalue- value- Returns:
- Conversion result
-
tryConvertConstructor
protected final <T> ConvertResult tryConvertConstructor(String name, Class<?> type, String value, Class<T> parameterType) Tries to convert the value by invoking a constructor that takes a string on the type- Parameters:
type- Typevalue- value- Returns:
- Conversion result
-
tryConvertFromValueOf
Tries to convert the value by invoking a staticvalueOf(String)method on the type- Parameters:
type- Typevalue- Value- Returns:
- Conversion result
-
tryConvertFromString
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(String name, Class<?> type, String value, String methodName) Tries to convert the value by invoking a static method on theConsiders two variants of the method, one which takes
Stringas its parameter type and if that doesn't exist one that takesCharSequenceas it's parameter type- Parameters:
type- Typevalue- ValuemethodName- Name of the method to invoke- Returns:
- Conversion Result
-
tryConvertStringMethod
protected final ConvertResult tryConvertStringMethod(Class<?> type, String value, String methodName, Class<?> parameterType) 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
Tries to convert the value if it is one of the common Java types- Parameters:
type- Typevalue- Value- Returns:
- Conversion result
-
setNumericConverter
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
-