ariba.util.formatter
Class DoubleFormatter

java.lang.Object
  extended by ariba.util.formatter.Formatter
      extended by ariba.util.formatter.DecimalFormatterCommon
          extended by ariba.util.formatter.DoubleFormatter
All Implemented Interfaces:
Compare, StringParser

public class DoubleFormatter
extends DecimalFormatterCommon

DoubleFormatter is a subclass of Formatter which is responsible for formatting, parsing, and comparing double values and/or Double objects.


Field Summary
static java.lang.String ClassName
          Our Java class name.
 
Fields inherited from interface ariba.util.core.Compare
EqualTo, GreaterThan, LessThan
 
Constructor Summary
DoubleFormatter()
          Creates a new DoubleFormatter.
 
Method Summary
static int compareDoubles(double d1, double d2)
          Compares two double values for sorting purposes.
static int compareDoubles(java.lang.Double d1, java.lang.Double d2)
          Compares two Double objects for sorting purposes.
static java.lang.Double flexibleDoubleValue(java.lang.Object stringValue)
          Flexible conversion of a string into a Double.
 java.lang.String formatObject(java.lang.Object object, int precision, java.util.Locale locale)
          Returns a string representation of the given object in the given locale with the given precision.
static java.lang.String getCanonicalPercentSign()
           
static double getDoubleValue(java.lang.Object object)
          Returns a double value derived from the given object in the default locale.
static double getDoubleValue(java.lang.Object object, java.util.Locale locale)
          Returns a double value derived from the given object in the default locale.
static java.lang.String getLocalizedPercentSign(java.util.Locale locale)
           
static java.lang.String getStringValue(double value)
          Returns a formatted string for the given double in the default locale.
static java.lang.String getStringValue(java.lang.Double object)
          Returns a formatted string for the given Double in the default locale.
static java.lang.String getStringValue(double value, int precision)
          Returns a formatted string for the given double in the default locale.
static java.lang.String getStringValue(java.lang.Double object, int precision)
          Returns a formatted string for the given Double in the default locale.
static java.lang.String getStringValue(double value, int minPrecision, int maxPrecision)
          Returns a formatted string for the given double in the default locale.
static java.lang.String getStringValue(double value, int minPrecision, int maxPrecision, java.util.Locale locale)
          Returns a formatted string for the given double in the given locale.
static java.lang.String getStringValue(java.lang.Double object, int minPrecision, int maxPrecision, java.util.Locale locale)
          Returns a formatted string for the given Double in the given locale.
static java.lang.String getStringValue(double value, int minPrecision, int maxPrecision, java.lang.String pattern, java.util.Locale locale)
          Returns a formatted string for the given double in the given locale.
static java.lang.String getStringValue(java.lang.Double object, int minPrecision, int maxPrecision, java.lang.String pattern, java.util.Locale locale)
          Returns a formatted string for the given Double in the given locale.
static java.lang.String getStringValue(double value, int minPrecision, int maxPrecision, java.lang.String pattern, java.util.Locale locale, boolean trim)
          Returns a formatted string for the given double in the given locale.
static java.lang.String getStringValue(double value, int precision, java.util.Locale locale)
          Returns a formatted string for the given double in the given locale.
static java.lang.String getStringValue(java.lang.Double object, int precision, java.util.Locale locale)
          Returns a formatted string for the given Double in the given locale.
static java.lang.String getStringValue(double value, java.util.Locale locale)
          Returns a formatted string for the given double in the given locale.
static java.lang.String getStringValue(java.lang.Double object, java.util.Locale locale)
          Returns a formatted string for the given Double in the given locale.
 java.lang.Object getValue(java.lang.Object object, java.util.Locale locale)
          Returns a new Double derived from the given object in the given locale.
static double parseDouble(java.lang.String string)
          Tries to parse the given string as a double in the default locale.
static double parseDouble(java.lang.String string, java.util.Locale locale)
          Tries to parse the given string as a double in the given locale.
static double parseDouble(java.lang.String string, java.util.Locale locale, boolean strict)
          Tries to parse the given string as a double in the given locale.
static double parseDouble(java.lang.String string, java.lang.String pattern, java.util.Locale locale)
          Tries to parse the given string as a double in the given locale.
static double parseDouble(java.lang.String string, java.lang.String pattern, java.util.Locale locale, boolean strict)
          Tries to parse the given string as a double in the given locale.
 
Methods inherited from class ariba.util.formatter.DecimalFormatterCommon
trimString, trimString
 
Methods inherited from class ariba.util.formatter.Formatter
canFormatNulls, compare, compare, equal, equal, getFormat, getFormat, getFormatterClassForType, getFormatterForObject, getFormatterForType, getLocale, getStringValue, getStringValue, getValue, handlesNulls, isBidirectional, makeParseException, makeParseException, makeParseException, makeParseExceptionMessage, makeParseExceptionMessage, objectsAreEqual, objectsAreEqual, parse, parse, parseString, parseString, quickCompare, quickCompare, quickCompareValue, registerFormatter
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ClassName

public static final java.lang.String ClassName
Our Java class name.

See Also:
Constant Field Values
Constructor Detail

DoubleFormatter

public DoubleFormatter()
Creates a new DoubleFormatter.

Method Detail

getStringValue

public static java.lang.String getStringValue(java.lang.Double object)
Returns a formatted string for the given Double in the default locale. By default, a precision of zero is used.

Parameters:
object - the Double to format into a string
Returns:
a string representation of the Double, or empty string if the Double is null

getStringValue

public static java.lang.String getStringValue(java.lang.Double object,
                                              java.util.Locale locale)
Returns a formatted string for the given Double in the given locale. By default, a precision of zero is used. The locale parameter must be non-null.

Parameters:
object - the Double to format into a string
locale - the Locale to use for formatting
Returns:
a string representation of the Double, or empty string if the Double is null

getStringValue

public static java.lang.String getStringValue(java.lang.Double object,
                                              int precision)
Returns a formatted string for the given Double in the default locale. The precision parameter is used to determine how many fractional digits are shown.

Parameters:
object - the Double to format into a string
precision - the number of fractional digits to show
Returns:
a string representation of the Double, or empty string if the Double is null

getStringValue

public static java.lang.String getStringValue(java.lang.Double object,
                                              int precision,
                                              java.util.Locale locale)
Returns a formatted string for the given Double in the given locale. The precision parameter is used to determine how many fractional digits are shown. The locale parameter must be non-null.

Parameters:
object - the Double to format into a string
precision - the number of fractional digits to show
locale - the Locale to use for formatting
Returns:
a string representation of the Double, or empty string if the Double is null

getStringValue

public static java.lang.String getStringValue(java.lang.Double object,
                                              int minPrecision,
                                              int maxPrecision,
                                              java.util.Locale locale)
Returns a formatted string for the given Double in the given locale. The precision parameter is used to determine how many fractional digits are shown. The locale parameter must be non-null.

Parameters:
object - the Double to format into a string
minPrecision - the minimum number of fractional digits to show
maxPrecision - the maximum number of fractional digits to show
locale - the Locale to use for formatting
Returns:
a string representation of the Double, or empty string if the Double is null

getStringValue

public static java.lang.String getStringValue(java.lang.Double object,
                                              int minPrecision,
                                              int maxPrecision,
                                              java.lang.String pattern,
                                              java.util.Locale locale)
Returns a formatted string for the given Double in the given locale. The precision parameter is used to determine how many fractional digits are shown. The locale parameter must be non-null.

Parameters:
object - the Double to format into a string
minPrecision - the minimum number of fractional digits to show
maxPrecision - the maximum number of fractional digits to show
pattern - the DecimalFormat pattern to use for formatting
locale - the Locale to use for formatting
Returns:
a string representation of the Double, or empty string if the Double is null
See Also:
DecimalFormat

getStringValue

public static java.lang.String getStringValue(double value)
Returns a formatted string for the given double in the default locale. By default, a precision of zero is used.

Parameters:
value - the double to format into a string
Returns:
a string representation of the double

getStringValue

public static java.lang.String getStringValue(double value,
                                              java.util.Locale locale)
Returns a formatted string for the given double in the given locale. By default, a precision of zero is used. The locale parameter must be non-null.

Parameters:
value - the double to format into a string
locale - the Locale to use for formatting
Returns:
a string representation of the double

getStringValue

public static java.lang.String getStringValue(double value,
                                              int precision)
Returns a formatted string for the given double in the default locale. The precision parameter is used to determine how many fractional digits are shown.

Parameters:
value - the double to format into a string
precision - the number of fractional digits to show
Returns:
a string representation of the double

getStringValue

public static java.lang.String getStringValue(double value,
                                              int precision,
                                              java.util.Locale locale)
Returns a formatted string for the given double in the given locale. The precision parameter is used to determine how many fractional digits are shown. The locale parameter must be non-null.

Parameters:
value - the double to format into a string
precision - the number of fractional digits to show
locale - the Locale to use for formatting
Returns:
a string representation of the double

getStringValue

public static java.lang.String getStringValue(double value,
                                              int minPrecision,
                                              int maxPrecision)
Returns a formatted string for the given double in the default locale.

Parameters:
value - the double to format into a string
minPrecision - the minimum number of fractional digits to show
maxPrecision - the maximum number of fractional digits to show
Returns:
a string representation of the double

getStringValue

public static java.lang.String getStringValue(double value,
                                              int minPrecision,
                                              int maxPrecision,
                                              java.util.Locale locale)
Returns a formatted string for the given double in the given locale.

Parameters:
value - the double to format into a string
minPrecision - the minimum number of fractional digits to show
maxPrecision - the maximum number of fractional digits to show
locale - the Locale to use for formatting
Returns:
a string representation of the double

getStringValue

public static java.lang.String getStringValue(double value,
                                              int minPrecision,
                                              int maxPrecision,
                                              java.lang.String pattern,
                                              java.util.Locale locale)
Returns a formatted string for the given double in the given locale.

Parameters:
value - the double to format into a string
minPrecision - the minimum number of fractional digits to show
maxPrecision - the maximum number of fractional digits to show
pattern - the DecimalFormat pattern to use for formatting
locale - the Locale to use for formatting
Returns:
a string representation of the double
See Also:
DecimalFormat

getStringValue

public static java.lang.String getStringValue(double value,
                                              int minPrecision,
                                              int maxPrecision,
                                              java.lang.String pattern,
                                              java.util.Locale locale,
                                              boolean trim)
Returns a formatted string for the given double in the given locale.

Parameters:
value - the double to format into a string
minPrecision - the minimum number of fractional digits to show
maxPrecision - the maximum number of fractional digits to show
pattern - the DecimalFormat pattern to use for formatting
locale - the Locale to use for formatting
trim - true if leading and trailing zeros should be removed.
Returns:
a string representation of the double
See Also:
DecimalFormat

parseDouble

public static double parseDouble(java.lang.String string)
                          throws java.text.ParseException
Tries to parse the given string as a double in the default locale.

Parameters:
string - the string to parse as a double
Returns:
a double value derived from the string
Throws:
java.text.ParseException - if the string cannot be parsed as a double

parseDouble

public static double parseDouble(java.lang.String string,
                                 java.util.Locale locale)
                          throws java.text.ParseException
Tries to parse the given string as a double in the given locale. The locale parameter must be non-null.

Parameters:
string - the string to parse as a double
locale - the Locale to use for parsing
Returns:
a double value derived from the string
Throws:
java.text.ParseException - if the string cannot be parsed as an double

parseDouble

public static double parseDouble(java.lang.String string,
                                 java.util.Locale locale,
                                 boolean strict)
                          throws java.text.ParseException
Tries to parse the given string as a double in the given locale. The locale parameter must be non-null.

Parameters:
string - the string to parse as a double
locale - the Locale to use for parsing
Returns:
a double value derived from the string
Throws:
java.text.ParseException - if the string cannot be parsed as an double

parseDouble

public static double parseDouble(java.lang.String string,
                                 java.lang.String pattern,
                                 java.util.Locale locale)
                          throws java.text.ParseException
Tries to parse the given string as a double in the given locale. The locale parameter must be non-null.

Parameters:
string - the string to parse as a double
pattern - the DecimalFormat pattern to use for parsing
locale - the Locale to use for parsing
Returns:
a double value derived from the string
Throws:
java.text.ParseException - if the string cannot be parsed as an double
See Also:
DecimalFormat

parseDouble

public static double parseDouble(java.lang.String string,
                                 java.lang.String pattern,
                                 java.util.Locale locale,
                                 boolean strict)
                          throws java.text.ParseException
Tries to parse the given string as a double in the given locale. The locale parameter must be non-null.

Parameters:
string - the string to parse as a double
pattern - the DecimalFormat pattern to use for parsing
locale - the Locale to use for parsing
Returns:
a double value derived from the string
Throws:
java.text.ParseException - if the string cannot be parsed as an double
See Also:
DecimalFormat

getLocalizedPercentSign

public static java.lang.String getLocalizedPercentSign(java.util.Locale locale)

getCanonicalPercentSign

public static java.lang.String getCanonicalPercentSign()

getDoubleValue

public static double getDoubleValue(java.lang.Object object)
Returns a double value derived from the given object in the default locale. If the object is not a Double, it is converted to a string and parsed. Returns 0.0 if the object can't be converted to a double.

Parameters:
object - the object to convert to an double value
Returns:
a double derived from the given object

getDoubleValue

public static double getDoubleValue(java.lang.Object object,
                                    java.util.Locale locale)
Returns a double value derived from the given object in the default locale. If the object is not a Double, it is converted to a string and parsed. Returns 0.0 if the object can't be converted to a double.

Parameters:
object - the object to convert to an double value
locale - the Locale to use for conversion
Returns:
a double derived from the given object

compareDoubles

public static int compareDoubles(java.lang.Double d1,
                                 java.lang.Double d2)
Compares two Double objects for sorting purposes. Returns an int value which is less than, equal to, or greater than zero depending on whether the first object sorts before, the same, or after the second object.

Parameters:
d1 - the first Double to compare
d2 - the second Double to compare
Returns:
int value which determines how the two objects should be ordered

compareDoubles

public static int compareDoubles(double d1,
                                 double d2)
Compares two double values for sorting purposes. Returns an int value which is less than, equal to, or greater than zero depending on whether the first value sorts before, the same, or after the second value.

Parameters:
d1 - the first double to compare
d2 - the second double to compare
Returns:
int value which determines how the two values should be ordered

flexibleDoubleValue

public static java.lang.Double flexibleDoubleValue(java.lang.Object stringValue)
Flexible conversion of a string into a Double. Converts decimal format, as well as fractional format like "12 3/8 = 12.375" or "1-3/4 = 1.75". Also supports localized format: "12,3/4 = 12.75". If it cannot convert, it returns null.


formatObject

public java.lang.String formatObject(java.lang.Object object,
                                     int precision,
                                     java.util.Locale locale)
Returns a string representation of the given object in the given locale with the given precision. The object must be a non-null Double.

Parameters:
object - the Double to format into a string
precision - the number of fractional digits to show
locale - the Locale to use for formatting
Returns:
a string representation of the Double

getValue

public java.lang.Object getValue(java.lang.Object object,
                                 java.util.Locale locale)
Returns a new Double derived from the given object in the given locale. If the object is not a Double, it is converted to a string and parsed. Returns null if the object can't be parsed as a Double.

Specified by:
getValue in class Formatter
Parameters:
object - the object to convert to a Double
locale - the Locale to use for conversion (unused)
Returns:
a Double derived from the given object


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.