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
-
Field Summary
Fields inherited from class org.eclipse.core.internal.databinding.conversion.AbstractStringToNumberConverter
MAX_BYTE, MAX_DOUBLE, MAX_FLOAT, MAX_INTEGER, MAX_LONG, MAX_SHORT, MIN_BYTE, MIN_DOUBLE, MIN_FLOAT, MIN_INTEGER, MIN_LONG, MIN_SHORT
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringToNumberConverter<BigDecimal>
static StringToNumberConverter<BigDecimal>
toBigDecimal
(Format numberFormat) static StringToNumberConverter<BigInteger>
static StringToNumberConverter<BigInteger>
toBigInteger
(Format numberFormat) static StringToNumberConverter<Byte>
toByte
(boolean primitive) static StringToNumberConverter<Byte>
static StringToNumberConverter<Double>
toDouble
(boolean primitive) static StringToNumberConverter<Double>
static StringToNumberConverter<Float>
toFloat
(boolean primitive) static StringToNumberConverter<Float>
static StringToNumberConverter<Integer>
toInteger
(boolean primitive) static StringToNumberConverter<Integer>
static StringToNumberConverter<Long>
toLong
(boolean primitive) static StringToNumberConverter<Long>
static StringToNumberConverter<Short>
toShort
(boolean primitive) static StringToNumberConverter<Short>
Methods inherited from class org.eclipse.core.internal.databinding.conversion.AbstractStringToNumberConverter
convert
Methods inherited from class org.eclipse.core.databinding.conversion.Converter
getFromType, getToType
-
Method Details
-
toInteger
- Parameters:
primitive
-true
if the convert to type is an int- Returns:
- to Integer converter for the default locale
-
toInteger
- Parameters:
numberFormat
- number format used by the converterprimitive
-true
if the convert to type is an int- Returns:
- to Integer converter with the provided numberFormat
-
toDouble
- Parameters:
primitive
-true
if the convert to type is a double- Returns:
- to Double converter for the default locale
-
toDouble
- Parameters:
numberFormat
- number format used by the converterprimitive
-true
if the convert to type is a double- Returns:
- to Double converter with the provided numberFormat
-
toLong
- Parameters:
primitive
-true
if the convert to type is a long- Returns:
- to Long converter for the default locale
-
toLong
- Parameters:
numberFormat
- number format used by the converterprimitive
-true
if the convert to type is a long- Returns:
- to Long converter with the provided numberFormat
-
toFloat
- Parameters:
primitive
-true
if the convert to type is a float- Returns:
- to Float converter for the default locale
-
toFloat
- Parameters:
numberFormat
- number format used by the converterprimitive
-true
if the convert to type is a float- Returns:
- to Float converter with the provided numberFormat
-
toBigInteger
- Returns:
- to BigInteger converter for the default locale
-
toBigInteger
- Parameters:
numberFormat
- number format used by the converter- Returns:
- to BigInteger converter with the provided numberFormat
-
toBigDecimal
- Returns:
- to BigDecimal converter for the default locale
-
toBigDecimal
- Parameters:
numberFormat
- number format used by the converter- Returns:
- to BigDecimal converter with the provided numberFormat
-
toShort
- Parameters:
primitive
-true
if the convert to type is a short- Returns:
- to Short converter for the default locale
-
toShort
- Parameters:
numberFormat
- number format used by the converterprimitive
-true
if the convert to type is a short- Returns:
- to Short converter with the provided numberFormat
-
toByte
- Parameters:
primitive
-true
if the convert to type is a byte- Returns:
- to Byte converter for the default locale
-
toByte
- Parameters:
numberFormat
- number format used by the converterprimitive
-true
if the convert to type is a byte- Returns:
- to Byte converter with the provided numberFormat
-