Class NumberTypeHandler

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.text.DecimalFormat createDecimalFormat()
      Creates a DecimalFormat for parsing and formatting the number value.
      protected abstract java.lang.Number createNumber​(java.lang.String text)
      Parses a Number from text.
      protected abstract java.lang.Number createNumber​(java.math.BigDecimal bg)
      Parses a Number from a BigDecimal.
      java.lang.String format​(java.lang.Object value)
      Formats a Number by calling toString().
      java.lang.String getPattern()
      Returns the DecimalFormat pattern to use to parse and format the number value.
      TypeHandler newInstance​(java.util.Properties properties)
      Creates a customized instance of this type handler.
      java.lang.Number parse​(java.lang.String text)
      Parses a Number from the given text.
      void setPattern​(java.lang.String pattern)
      Sets the DeimcalFormat pattern to use to parse and format the number value.
      • Methods inherited from class java.lang.Object

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

      • NumberTypeHandler

        public NumberTypeHandler()
    • Method Detail

      • parse

        public final java.lang.Number parse​(java.lang.String text)
                                     throws TypeConversionException
        Parses a Number from the given text.
        Specified by:
        parse in interface TypeHandler
        Parameters:
        text - the text to parse
        Returns:
        the parsed Number, or null if text was null or an empty string
        Throws:
        TypeConversionException - if the text is not a valid number
      • createNumber

        protected abstract java.lang.Number createNumber​(java.lang.String text)
                                                  throws java.lang.NumberFormatException
        Parses a Number from text.
        Parameters:
        text - the text to convert to a Number
        Returns:
        the parsed Number
        Throws:
        java.lang.NumberFormatException - if the text is not a valid number
      • createNumber

        protected abstract java.lang.Number createNumber​(java.math.BigDecimal bg)
                                                  throws java.lang.ArithmeticException
        Parses a Number from a BigDecimal.
        Parameters:
        bg - the BigDecimal version of the number
        Returns:
        the parsed Number
        Throws:
        java.lang.ArithmeticException - if the BigDecimal cannot be converted to the Number type supported by this handler
      • newInstance

        public TypeHandler newInstance​(java.util.Properties properties)
                                throws java.lang.IllegalArgumentException
        Description copied from interface: ConfigurableTypeHandler
        Creates a customized instance of this type handler.
        Specified by:
        newInstance in interface ConfigurableTypeHandler
        Parameters:
        properties - the properties for customizing the instance
        Returns:
        the new TypeHandler
        Throws:
        java.lang.IllegalArgumentException - if a property value is invalid
      • createDecimalFormat

        protected java.text.DecimalFormat createDecimalFormat()
        Creates a DecimalFormat for parsing and formatting the number value.
        Returns:
        the new DecimalFormat
      • format

        public java.lang.String format​(java.lang.Object value)
        Formats a Number by calling toString(). If value is null, null is returned.
        Specified by:
        format in interface TypeHandler
        Parameters:
        value - the number to format
        Returns:
        the formatted number
      • getPattern

        public java.lang.String getPattern()
        Returns the DecimalFormat pattern to use to parse and format the number value. May be null if a DecimalFormat is not used.
        Returns:
        the DeimcalFormat pattern
      • setPattern

        public void setPattern​(java.lang.String pattern)
        Sets the DeimcalFormat pattern to use to parse and format the number value. By default, the pattern is set to null and a Number subclass is used to parse and format the number value.
        Parameters:
        pattern - the DecimalFormat pattern