Class StringToNumberConverter<T extends Number>

java.lang.Object
org.eclipse.core.databinding.conversion.Converter<F,T>
org.eclipse.core.internal.databinding.validation.NumberFormatConverter<Object,T>
org.eclipse.core.internal.databinding.conversion.AbstractStringToNumberConverter<T>
org.eclipse.core.databinding.conversion.text.StringToNumberConverter<T>
Type Parameters:
T - The type to which values are converted.
All Implemented Interfaces:
IConverter<Object,T>

public final class StringToNumberConverter<T extends Number> extends org.eclipse.core.internal.databinding.conversion.AbstractStringToNumberConverter<T>
Converts a String to a Number using NumberFormat.parse(...). This class is thread safe.

Note that this class does not have precise type parameters because it manually handles argument type mismatches and throws IllegalArgumentException.

The first type parameter of NumberFormatConverter is set to Object to preserve backwards compatibility, but the argument is meant to always be a String.

This class is a variant of the class with the same name in the parent package, but it uses java.text instead of com.ibm.icu.

Methods on this class that don't take an argument number format use ICU if it is available on the classpath, otherwise they use java.text.

Since:
1.9
  • Method Details

    • toInteger

      public static StringToNumberConverter<Integer> toInteger(boolean primitive)
      Parameters:
      primitive - true if the convert to type is an int
      Returns:
      to Integer converter for the default locale
    • toInteger

      public static StringToNumberConverter<Integer> toInteger(Format numberFormat, boolean primitive)
      Parameters:
      numberFormat - number format used by the converter
      primitive - true if the convert to type is an int
      Returns:
      to Integer converter with the provided numberFormat
    • toDouble

      public static StringToNumberConverter<Double> toDouble(boolean primitive)
      Parameters:
      primitive - true if the convert to type is a double
      Returns:
      to Double converter for the default locale
    • toDouble

      public static StringToNumberConverter<Double> toDouble(Format numberFormat, boolean primitive)
      Parameters:
      numberFormat - number format used by the converter
      primitive - true if the convert to type is a double
      Returns:
      to Double converter with the provided numberFormat
    • toLong

      public static StringToNumberConverter<Long> toLong(boolean primitive)
      Parameters:
      primitive - true if the convert to type is a long
      Returns:
      to Long converter for the default locale
    • toLong

      public static StringToNumberConverter<Long> toLong(Format numberFormat, boolean primitive)
      Parameters:
      numberFormat - number format used by the converter
      primitive - true if the convert to type is a long
      Returns:
      to Long converter with the provided numberFormat
    • toFloat

      public static StringToNumberConverter<Float> toFloat(boolean primitive)
      Parameters:
      primitive - true if the convert to type is a float
      Returns:
      to Float converter for the default locale
    • toFloat

      public static StringToNumberConverter<Float> toFloat(Format numberFormat, boolean primitive)
      Parameters:
      numberFormat - number format used by the converter
      primitive - true if the convert to type is a float
      Returns:
      to Float converter with the provided numberFormat
    • toBigInteger

      public static StringToNumberConverter<BigInteger> toBigInteger()
      Returns:
      to BigInteger converter for the default locale
    • toBigInteger

      public static StringToNumberConverter<BigInteger> toBigInteger(Format numberFormat)
      Parameters:
      numberFormat - number format used by the converter
      Returns:
      to BigInteger converter with the provided numberFormat
    • toBigDecimal

      public static StringToNumberConverter<BigDecimal> toBigDecimal()
      Returns:
      to BigDecimal converter for the default locale
    • toBigDecimal

      public static StringToNumberConverter<BigDecimal> toBigDecimal(Format numberFormat)
      Parameters:
      numberFormat - number format used by the converter
      Returns:
      to BigDecimal converter with the provided numberFormat
    • toShort

      public static StringToNumberConverter<Short> toShort(boolean primitive)
      Parameters:
      primitive - true if the convert to type is a short
      Returns:
      to Short converter for the default locale
    • toShort

      public static StringToNumberConverter<Short> toShort(Format numberFormat, boolean primitive)
      Parameters:
      numberFormat - number format used by the converter
      primitive - true if the convert to type is a short
      Returns:
      to Short converter with the provided numberFormat
    • toByte

      public static StringToNumberConverter<Byte> toByte(boolean primitive)
      Parameters:
      primitive - true if the convert to type is a byte
      Returns:
      to Byte converter for the default locale
    • toByte

      public static StringToNumberConverter<Byte> toByte(Format numberFormat, boolean primitive)
      Parameters:
      numberFormat - number format used by the converter
      primitive - true if the convert to type is a byte
      Returns:
      to Byte converter with the provided numberFormat