com.esri.arcgis.util.dataset
Class DoubleConversion

java.lang.Object
  extended by com.esri.arcgis.util.dataset.DoubleConversion

public class DoubleConversion
extends Object

Provides simple utilities to convert between double and String. To convert String to double, this class adds support for exponential format over what is available within java.text.NumberFormat.

To convert double to String, this class adds support for easily constructing a NumberFormat as well as setting fraction and integer precision parameters in a single method.


Constructor Summary
DoubleConversion()
           
 
Method Summary
static String doubleToString(boolean value)
          Converts the given Boolean to String.
static String doubleToString(double value)
          Converts a double to String using the default Locale and standard NumberFormat.
static String doubleToString(double value, int maxFractionDigits, int minFractionDigits, int maxIntegerDigits, int minIntegerDigits)
          Converts a double to String using current Locale and specified fraction and integer lengths that are used in conjunction with a NumberFormat.
static String doubleToString(double value, int maxFractionDigits, int minFractionDigits, int maxIntegerDigits, int minIntegerDigits, Locale locale)
          Converts a double to String using given Locale, fraction, and integer lengths that are used in conjunction with a NumberFormat.
static String doubleToString(long value)
          Converts a long to String
static NumberFormat getFormat(int maxFractionDigits, int minFractionDigits, int maxIntegerDigits, int minIntegerDigits, Locale locale)
          Constructs and returns a NumberFormat with given precision parameters and Locale.
static NumberFormat getScientificFormat(NumberFormat base, Locale locale)
          Constructs and returns a NumberFormat that can be used for formatting decimal values into scientific notation.
static NumberFormat getStandardFormat(Locale locale)
          Constructs a NumberFormat for given locale, using the following parameters: maxFractionDigits = 20, minFractionDigits = 1, maxIntegerDigits = 20, minIntegerDigits = 1.
static double stringToDouble(String value)
          Converts a String to a double using the standard NumberFormat with current default Locale.
static double stringToDouble(String value, double defaultValue)
          Converts a String to a double using the standard NumberFormat with current default Locale.
static double stringToDouble(String value, double defaultValue, Locale locale)
          Converts a String to a double using the standard NumberFormat with given Locale.
static double stringToDouble(String value, double defaultValue, NumberFormat format)
          Converts a String to a double using the given NumberFormat.
static double stringToDouble(String value, Locale locale)
          Converts a String to a double using the standard NumberFormat with specified locale.
static double stringToDouble(String value, NumberFormat format)
          Converts a String to a double using the specified NumberFormat.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DoubleConversion

public DoubleConversion()
Method Detail

getFormat

public static NumberFormat getFormat(int maxFractionDigits,
                                     int minFractionDigits,
                                     int maxIntegerDigits,
                                     int minIntegerDigits,
                                     Locale locale)
Constructs and returns a NumberFormat with given precision parameters and Locale.

Parameters:
maxFractionDigits - the maximum number of faction digits
minFractionDigits - the minumum number of faction digits
maxIntegerDigits - the maximum number of integer digits
minIntegerDigits - the minimum number of integer digits
locale - the locale

getStandardFormat

public static NumberFormat getStandardFormat(Locale locale)
Constructs a NumberFormat for given locale, using the following parameters:

Parameters:
locale - the locale
Returns:
the number format

getScientificFormat

public static NumberFormat getScientificFormat(NumberFormat base,
                                               Locale locale)
Constructs and returns a NumberFormat that can be used for formatting decimal values into scientific notation.

The NumberFormat will have a pattern applied that is constructed using the number of integer and fraction characters within the given NumberFormat. It is expected that the base format will be used for regular number formatting, and the format constructed by this method will be used for scientific notation when the base format is inappropriate (the number is to large or too small for the base format).

Parameters:
base - the base number format
locale - the locale
Returns:
the number format

doubleToString

public static String doubleToString(double value,
                                    int maxFractionDigits,
                                    int minFractionDigits,
                                    int maxIntegerDigits,
                                    int minIntegerDigits,
                                    Locale locale)
Converts a double to String using given Locale, fraction, and integer lengths that are used in conjunction with a NumberFormat. No grouping characters are used in this conversion.

Parameters:
value - the double to convert
maxFractionDigits - the maximum number of fraction digits
minFractionDigits - the minimum number of fraction digits
maxIntegerDigits - the maximum number of integer digits
minIntegerDigits - the minimum number of integer digits
locale - the locale
Returns:
the resulting string
See Also:
NumberFormat

doubleToString

public static String doubleToString(double value,
                                    int maxFractionDigits,
                                    int minFractionDigits,
                                    int maxIntegerDigits,
                                    int minIntegerDigits)
Converts a double to String using current Locale and specified fraction and integer lengths that are used in conjunction with a NumberFormat. No grouping characters are used in this conversion.

Parameters:
value - the double to convert
maxFractionDigits - the maximum number of fraction digits
minFractionDigits - the minimum number of fraction digits
maxIntegerDigits - the maximum number of integer digits
minIntegerDigits - the minimum number of integer digits
Returns:
the resulting string
See Also:
NumberFormat

doubleToString

public static String doubleToString(double value)
Converts a double to String using the default Locale and standard NumberFormat.

Parameters:
value - the double to convert
Returns:
the resulting string
See Also:
DoubleConversion.doubleToString(double,int,int,int,int), DoubleConversion.getStandardFormat(java.util.Locale)

doubleToString

public static String doubleToString(boolean value)
Converts the given Boolean to String.

Parameters:
value - the boolean to convert
Returns:
the resulting string

doubleToString

public static String doubleToString(long value)
Converts a long to String

Parameters:
value - the long to convert
Returns:
the resulting string

stringToDouble

public static double stringToDouble(String value,
                                    double defaultValue,
                                    NumberFormat format)
Converts a String to a double using the given NumberFormat. A default value is passed in case a ParsingException occurs.

Parameters:
value - the String value to be converted
defaultValue - the default value to use in case of parsing error
format - the NumberFormat to be used
Returns:
the double value for the given String.

stringToDouble

public static double stringToDouble(String value,
                                    double defaultValue,
                                    Locale locale)
Converts a String to a double using the standard NumberFormat with given Locale. A default value is passed in case a ParsingException occurs.

Parameters:
value - the String value to be converted
defaultValue - the default value to use in case of parsing error
locale - the Locale to be used
Returns:
the double value for the given String.

stringToDouble

public static double stringToDouble(String value)
Converts a String to a double using the standard NumberFormat with current default Locale. A default value is passed in case a ParsingException occurs.

Parameters:
value - the String value to be converted
Returns:
the double value for the given String.

stringToDouble

public static double stringToDouble(String value,
                                    double defaultValue)
Converts a String to a double using the standard NumberFormat with current default Locale. A default value is passed in case a ParsingException occurs.

Parameters:
value - the String value to be converted
defaultValue - the default value to use in case of parsing error
Returns:
the double value for the given String.

stringToDouble

public static double stringToDouble(String value,
                                    Locale locale)
                             throws ParseException
Converts a String to a double using the standard NumberFormat with specified locale. This method takes care of trailing exponential, if present.

Parameters:
value - the String value to be converted
locale - the Locale to be used when constructing standard format
Returns:
the double value for the given String
Throws:
ParseException - if parse errors occur

stringToDouble

public static double stringToDouble(String value,
                                    NumberFormat format)
                             throws ParseException
Converts a String to a double using the specified NumberFormat.

Parameters:
value - the String value to be converted
format - the NumberFormat to be used
Returns:
the double value for the given String
Throws:
ParseException - if parse errors occur