Class DefaultTypeConverter

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void checkArguments​(java.lang.String name, java.lang.Class<?> type, java.lang.String value)
      Checks that the arguments are all non-null
      java.lang.Object convert​(java.lang.String name, java.lang.Class<?> type, java.lang.String value)
      Convert a string value into an appropriately typed value
      void setNumericConverter​(NumericTypeConverter converter)
      Sets the numeric type converter to use, if null then default behaviour of the type converter instance (whatever that might be) will be used
      protected 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
      protected <T> ConvertResult tryConvertConstructor​(java.lang.String name, java.lang.Class<?> type, java.lang.String value, java.lang.Class<T> parameterType)
      Tries to convert the value by invoking a constructor that takes a string on the type
      protected ConvertResult tryConvertFromString​(java.lang.String name, java.lang.Class<?> type, java.lang.String value)
      Tries to convert the value by invoking a static fromString(String) method on the type
      protected ConvertResult tryConvertFromValueOf​(java.lang.String name, java.lang.Class<?> type, java.lang.String value)
      Tries to convert the value by invoking a static valueOf(String) method on the type
      protected 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
      protected ConvertResult tryConvertStringMethod​(java.lang.Class<?> type, java.lang.String value, java.lang.String methodName, java.lang.Class<?> parameterType)
      Tries to convert the value by invoking a static method on the type
      protected 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultTypeConverter

        public DefaultTypeConverter()
        Creates a new instance of the default type converter with the default NumericTypeConverter configured
      • DefaultTypeConverter

        public DefaultTypeConverter​(NumericTypeConverter numericConverter)
        Creates a new instance of the default type converter
        Parameters:
        numericConverter - Numeric type converter to use, if null then DefaultNumericConverter is used
    • Method Detail

      • convert

        public java.lang.Object convert​(java.lang.String name,
                                        java.lang.Class<?> type,
                                        java.lang.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​(java.lang.String name,
                                          java.lang.Class<?> type,
                                          java.lang.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​(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

        Considers two variants of the constructor, one which takes String as its parameter type and if that doesn't exist one that takes CharSequence as it's parameter type

        Parameters:
        type - Type
        value - value
        Returns:
        Conversion result
      • tryConvertConstructor

        protected final <T> ConvertResult tryConvertConstructor​(java.lang.String name,
                                                                java.lang.Class<?> type,
                                                                java.lang.String value,
                                                                java.lang.Class<T> parameterType)
        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​(java.lang.String name,
                                                            java.lang.Class<?> type,
                                                            java.lang.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​(java.lang.String name,
                                                           java.lang.Class<?> type,
                                                           java.lang.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​(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

        Considers two variants of the method, one which takes String as its parameter type and if that doesn't exist one that takes CharSequence as it's parameter type

        Parameters:
        type - Type
        value - Value
        methodName - Name of the method to invoke
        Returns:
        Conversion Result
      • tryConvertStringMethod

        protected final ConvertResult tryConvertStringMethod​(java.lang.Class<?> type,
                                                             java.lang.String value,
                                                             java.lang.String methodName,
                                                             java.lang.Class<?> parameterType)
        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​(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 - 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