Package org.eclipse.core.databinding.conversion

## 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.databinding.conversion.StringToNumberConverter<T>

Type Parameters:
  `T` - The type to which values are converted.

All Implemented Interfaces:
  `IConverter<Object,​T>`

    public class StringToNumberConverter<T extends Number>
    extends org.eclipse.core.internal.databinding.validation.NumberFormatConverter<Object,​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 compability, but the argument is meant to always be a `String`.

Since:
  1.0

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`T` `convert​(Object fromObject)` Converts the provided `fromObject` to the requested `to type`.
`static StringToNumberConverter<BigDecimal>` `toBigDecimal()`
`static StringToNumberConverter<BigDecimal>` `toBigDecimal​(com.ibm.icu.text.NumberFormat numberFormat)`
`static StringToNumberConverter<BigInteger>` `toBigInteger()`
`static StringToNumberConverter<BigInteger>` `toBigInteger​(com.ibm.icu.text.NumberFormat numberFormat)`
`static StringToNumberConverter<Byte>` `toByte​(boolean primitive)`
`static StringToNumberConverter<Byte>` `toByte​(com.ibm.icu.text.NumberFormat numberFormat, boolean primitive)`
`static StringToNumberConverter<Double>` `toDouble​(boolean primitive)`
`static StringToNumberConverter<Double>` `toDouble​(com.ibm.icu.text.NumberFormat numberFormat, boolean primitive)`
`static StringToNumberConverter<Float>` `toFloat​(boolean primitive)`
`static StringToNumberConverter<Float>` `toFloat​(com.ibm.icu.text.NumberFormat numberFormat, boolean primitive)`
`static StringToNumberConverter<Integer>` `toInteger​(boolean primitive)`
`static StringToNumberConverter<Integer>` `toInteger​(com.ibm.icu.text.NumberFormat numberFormat, boolean primitive)`
`static StringToNumberConverter<Long>` `toLong​(boolean primitive)`
`static StringToNumberConverter<Long>` `toLong​(com.ibm.icu.text.NumberFormat numberFormat, boolean primitive)`
`static StringToNumberConverter<Short>` `toShort​(boolean primitive)`
`static StringToNumberConverter<Short>` `toShort​(com.ibm.icu.text.NumberFormat numberFormat, boolean primitive)`

### Methods inherited from class org.eclipse.core.databinding.conversion.Converter

`getFromType, getToType`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### convert

    public T convert​(Object fromObject)

Converts the provided `fromObject` to the requested `to type`.

Parameters:
  `fromObject` - the object to convert, of type `IConverter.getFromType()`
Returns:
  the converted object, of type `IConverter.getToType()`
Throws:
  `IllegalArgumentException` - if the value isn't in the format required by the NumberFormat or the value is out of range for the `to type`.
  `IllegalArgumentException` - if conversion was not possible
Since:
  1.7
See Also:
  `IConverter.convert(java.lang.Object)`

#### 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​(com.ibm.icu.text.NumberFormat numberFormat,
                                                             boolean primitive)

Parameters:
  `numberFormat` -
  `primitive` -
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​(com.ibm.icu.text.NumberFormat numberFormat,
                                                           boolean primitive)

Parameters:
  `numberFormat` -
  `primitive` -
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​(com.ibm.icu.text.NumberFormat numberFormat,
                                                       boolean primitive)

Parameters:
  `numberFormat` -
  `primitive` -
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​(com.ibm.icu.text.NumberFormat numberFormat,
                                                         boolean primitive)

Parameters:
  `numberFormat` -
  `primitive` -
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​(com.ibm.icu.text.NumberFormat numberFormat)

Parameters:
  `numberFormat` -
Returns:
  to BigInteger converter with the provided numberFormat

#### toBigDecimal

    public static StringToNumberConverter<BigDecimal> toBigDecimal()

Returns:
  to BigDecimal converter for the default locale
Since:
  1.2

#### toBigDecimal

    public static StringToNumberConverter<BigDecimal> toBigDecimal​(com.ibm.icu.text.NumberFormat numberFormat)

Parameters:
  `numberFormat` -
Returns:
  to BigDecimal converter with the provided numberFormat
Since:
  1.2

#### 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
Since:
  1.2

#### toShort

    public static StringToNumberConverter<Short> toShort​(com.ibm.icu.text.NumberFormat numberFormat,
                                                         boolean primitive)

Parameters:
  `numberFormat` -
  `primitive` -
Returns:
  to Short converter with the provided numberFormat
Since:
  1.2

#### 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
Since:
  1.2

#### toByte

    public static StringToNumberConverter<Byte> toByte​(com.ibm.icu.text.NumberFormat numberFormat,
                                                       boolean primitive)

Parameters:
  `numberFormat` -
  `primitive` -
Returns:
  to Byte converter with the provided numberFormat
Since:
  1.2