Class DefaultTypeConverter

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 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 Details

  • Constructor Details

    • DefaultTypeConverter

      public DefaultTypeConverter()
    • DefaultTypeConverter

      public DefaultTypeConverter(NumericTypeConverter numericConverter)
  • Method Details

    • convert

      public Object convert(String name, Class<?> type, String value)
      Description copied from interface: TypeConverter
      Convert a string value into an appropriately typed value
      Specified by:
      convert in interface TypeConverter
      Parameters:
      name - Option Name
      type - Target Type
      value - String Value
      Returns:
      Typed value
    • checkArguments

      public static void checkArguments(String name, Class<?> type, String value)
      Checks that the arguments are all non-null
      Parameters:
      name - Option/Argument name
      type - Target type
      value - String to convert
    • tryConvertStringConstructor

      protected final ConvertResult tryConvertStringConstructor(String name, Class<?> type, String value)
      Tries to convert the value by invoking a constructor that takes a string on the type
      Parameters:
      type - Type
      value - value
      Returns:
      Conversion result
    • tryConvertFromValueOf

      protected final ConvertResult tryConvertFromValueOf(String name, Class<?> type, String value)
      Tries to convert the value by invoking a static valueOf(String) method on the type
      Parameters:
      type - Type
      value - Value
      Returns:
      Conversion result
    • tryConvertFromString

      protected final ConvertResult tryConvertFromString(String name, Class<?> type, String value)
      Tries to convert the value by invoking a static fromString(String) method on the type
      Parameters:
      type - Type
      value - 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 the type
      Parameters:
      type - Type
      value - Value
      methodName - Name of the method to invoke
      Returns:
      Conversion Result
    • tryConvertBasicTypes

      protected final ConvertResult tryConvertBasicTypes(String name, Class<?> type, String value)
      Tries to convert the value if it is one of the common Java types
      Parameters:
      type - Type
      value - Value
      Returns:
      Conversion result
    • setNumericConverter

      public void setNumericConverter(NumericTypeConverter converter)
      Description copied from interface: TypeConverter
      Sets the numeric type converter to use, if null then default behaviour of the type converter instance (whatever that might be) will be used
      Specified by:
      setNumericConverter in interface TypeConverter
      Parameters:
      converter - Numeric type converter