com.pega.pegarules.pub.util
Class PRNumberFormat

java.lang.Object
  extended by com.pega.pegarules.pub.util.PerThreadCache
      extended by com.pega.pegarules.pub.util.PRNumberFormat

public class PRNumberFormat
extends PerThreadCache

PRNumberFormat wraps the ICU number formatting support with a thread-safe implementation geared to PegaRULES conventions.

See http://oss.software.ibm.com/cgi-bin/icu/lx for an page that permits one to explore the settings supplied for each locale.

Version:
$Revision: 29281 $ $Date: 2012-06-12 09:42:57 -0400 (Tue, 12 Jun 2012) $
Author:
olsok

Field Summary
static java.lang.String COPYRIGHT
           
static int CURRENCY_PRECISION
          Use digits to right of dp as specified by currency
static java.lang.String DEFAULT_CURRENCY
          locale-specific default currency format
static java.lang.String DEFAULT_DECIMAL
          locale-specific default decimal format
static java.lang.String DEFAULT_DURATION
          locale-specific default duration format
static java.lang.String DEFAULT_INTEGER
          locale-specific default integer format
static java.lang.String DEFAULT_ORDINAL
          locale-specific default ordinal format
static java.lang.String DEFAULT_PERCENT
          locale-specific default percent format
static int DEFAULT_PRECISION
          Do not set constraints on digits to right of dp.
static java.lang.String DEFAULT_SPELLOUT
          locale-specific default spellout format
static java.lang.String VERSION
           
 
Fields inherited from class com.pega.pegarules.pub.util.PerThreadCache
USE_DEFAULT_TIMEZONE, USE_DEFAULT_TIMEZONE_PRE42SP6
 
Method Summary
static java.lang.String format(java.lang.String aLocale, java.lang.String aPattern, boolean aGroupingUsed, java.lang.String aCurrency, com.pega.ibm.icu.math.BigDecimal aValue)
          Formats the number using the specified pattern and locale.
static java.lang.String format(java.lang.String aLocale, java.lang.String aPattern, boolean aGroupingUsed, java.lang.String aCurrency, double aValue)
          Formats the number using the specified pattern and locale.
static java.lang.String format(java.lang.String aLocale, java.lang.String aPattern, boolean aGroupingUsed, java.lang.String aCurrency, int aValue)
          Formats the number using the specified pattern and locale.
static java.lang.String format(java.lang.String aLocale, java.lang.String aPattern, boolean aGroupingUsed, java.lang.String aCurrency, int aDigits, com.pega.ibm.icu.math.BigDecimal aValue)
          Formats the number using the specified pattern and locale.
static java.lang.String format(java.lang.String aLocale, java.lang.String aPattern, boolean aGroupingUsed, java.lang.String aCurrency, int aDigits, double aValue)
          Formats the number using the specified pattern and locale.
static java.lang.String format(java.lang.String aLocale, java.lang.String aPattern, boolean aGroupingUsed, java.lang.String aCurrency, int aDigits, int aValue)
          Formats the number using the specified pattern and locale.
static com.pega.ibm.icu.util.Currency getCurrency(java.util.Locale aLocale, java.lang.String aCurrency)
          Retrieve the desired currency value.
static com.pega.ibm.icu.util.Currency getCurrencyByLocale(java.util.Locale aLocale)
           
static java.util.Set getCurrencyCodesForLocale(java.lang.String aLocaleName)
          Returns the ISO currency codes for the specified aLocaleName including multi-level fallback.
static boolean isCurrencyValid(java.lang.String isoCode)
          validate that a given currency name is valid.
static com.pega.ibm.icu.math.BigDecimal numberToBigDecimal(java.lang.Number aValue)
          Helper function to convert java.lang.Number to ICU BigDecimal, preserving as much accuracy as possible.
static java.lang.Number parse(java.lang.String aLocale, java.lang.String aPattern, boolean aGroupingUsed, boolean aIntegerOnly, java.lang.String aString)
          Parses the String using the specified pattern and locale as a number.
static java.lang.Number parse(java.lang.String aLocale, java.lang.String aPattern, boolean aGroupingUsed, java.lang.String aCurrency, boolean aIntegerOnly, java.lang.String aString)
          Parses the String using the specified pattern and locale as a number.
static com.pega.ibm.icu.math.BigDecimal parseLocalizedAsBigDecimal(java.lang.String aLocale, java.lang.String aString)
          Convenience method to parse a value as a BigDecimal, using localized formats
static double parseLocalizedAsDouble(java.lang.String aLocale, java.lang.String aString)
          Convenience method to parse a value as a double, using localized formats
static int parseLocalizedAsInteger(java.lang.String aLocale, java.lang.String aString)
          Convenience method to parse a value as an integer, using localized formats
 
Methods inherited from class com.pega.pegarules.pub.util.PerThreadCache
getDefaultTimeZone, getLocale, getLocaleName, getTimeZone, setDefaultTimeZone
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
See Also:
Constant Field Values

VERSION

public static final java.lang.String VERSION

DEFAULT_DECIMAL

public static final java.lang.String DEFAULT_DECIMAL
locale-specific default decimal format

See Also:
Constant Field Values

DEFAULT_INTEGER

public static final java.lang.String DEFAULT_INTEGER
locale-specific default integer format

See Also:
Constant Field Values

DEFAULT_CURRENCY

public static final java.lang.String DEFAULT_CURRENCY
locale-specific default currency format

See Also:
Constant Field Values

DEFAULT_PERCENT

public static final java.lang.String DEFAULT_PERCENT
locale-specific default percent format

See Also:
Constant Field Values

DEFAULT_DURATION

public static final java.lang.String DEFAULT_DURATION
locale-specific default duration format

See Also:
Constant Field Values

DEFAULT_ORDINAL

public static final java.lang.String DEFAULT_ORDINAL
locale-specific default ordinal format

See Also:
Constant Field Values

DEFAULT_SPELLOUT

public static final java.lang.String DEFAULT_SPELLOUT
locale-specific default spellout format

See Also:
Constant Field Values

CURRENCY_PRECISION

public static final int CURRENCY_PRECISION
Use digits to right of dp as specified by currency

See Also:
Constant Field Values

DEFAULT_PRECISION

public static final int DEFAULT_PRECISION
Do not set constraints on digits to right of dp. Note that ClipboardProperty.getDecimalPrecision() returns -1 if a precision is not specified or applicable for the property, so this value is consistent. getDecimalPrecision WILL return the precision associated with a pyCurrency qualifier, so passing in the result of getDecimalPrecison() will be ALMOST equivalent to using CURRENCY_PRECISION for such values except that CURRENCY_PRECISION will ALSO set the rounding increment associated with the currency.

See Also:
Constant Field Values
Method Detail

format

public static final java.lang.String format(java.lang.String aLocale,
                                            java.lang.String aPattern,
                                            boolean aGroupingUsed,
                                            java.lang.String aCurrency,
                                            int aValue)
Formats the number using the specified pattern and locale.

Parameters:
aLocale - locale name, if null or blank, the default locale is used
aPattern - format pattern
aGroupingUsed - true if grouping should be used
aCurrency - currency name, if null or blank, the default for the locale is used
aValue - number to convert
Returns:
formatted value

format

public static final java.lang.String format(java.lang.String aLocale,
                                            java.lang.String aPattern,
                                            boolean aGroupingUsed,
                                            java.lang.String aCurrency,
                                            int aDigits,
                                            int aValue)
Formats the number using the specified pattern and locale.

Parameters:
aLocale - locale name, if null or blank, the default locale is used
aPattern - format pattern
aGroupingUsed - true if grouping should be used
aCurrency - currency name, if null or blank, the default for the locale is used
aDigits - digits to right of decimal point
aValue - number to convert
Returns:
formatted value

format

public static final java.lang.String format(java.lang.String aLocale,
                                            java.lang.String aPattern,
                                            boolean aGroupingUsed,
                                            java.lang.String aCurrency,
                                            double aValue)
Formats the number using the specified pattern and locale.

Parameters:
aLocale - locale name, if null or blank, the default locale is used
aPattern - format pattern
aGroupingUsed - true if grouping should be used
aCurrency - currency name, if null or blank, the default for the locale is used
aValue - number to convert
Returns:
formatted value

format

public static final java.lang.String format(java.lang.String aLocale,
                                            java.lang.String aPattern,
                                            boolean aGroupingUsed,
                                            java.lang.String aCurrency,
                                            int aDigits,
                                            double aValue)
Formats the number using the specified pattern and locale.

Parameters:
aLocale - locale name, if null or blank, the default locale is used
aPattern - format pattern
aGroupingUsed - true if grouping should be used
aCurrency - currency name, if null or blank, the default for the locale is used
aDigits - digits to right of decimal point
aValue - number to convert
Returns:
formatted value

format

public static final java.lang.String format(java.lang.String aLocale,
                                            java.lang.String aPattern,
                                            boolean aGroupingUsed,
                                            java.lang.String aCurrency,
                                            com.pega.ibm.icu.math.BigDecimal aValue)
Formats the number using the specified pattern and locale.

Parameters:
aLocale - locale name, if null or blank, the default locale is used
aPattern - format pattern
aGroupingUsed - true if grouping should be used
aCurrency - currency name, if null or blank, the default for the locale is used
aValue - number to convert
Returns:
formatted value

format

public static final java.lang.String format(java.lang.String aLocale,
                                            java.lang.String aPattern,
                                            boolean aGroupingUsed,
                                            java.lang.String aCurrency,
                                            int aDigits,
                                            com.pega.ibm.icu.math.BigDecimal aValue)
Formats the number using the specified pattern and locale.

Parameters:
aLocale - locale name, if null or blank, the default locale is used
aPattern - format pattern
aGroupingUsed - true if grouping should be used
aCurrency - currency name, if null or blank, the default for the locale is used
aDigits - digits to right of decimal point
aValue - number to convert
Returns:
formatted value

parse

public static final java.lang.Number parse(java.lang.String aLocale,
                                           java.lang.String aPattern,
                                           boolean aGroupingUsed,
                                           boolean aIntegerOnly,
                                           java.lang.String aString)
Parses the String using the specified pattern and locale as a number.

Parameters:
aLocale - locale name, if null or blank, the default locale is used
aPattern - format pattern
aGroupingUsed - true if grouping should be used
aIntegerOnly - true if integer only parse desired
aString - formatted value to convert to number
Returns:
Number value
Throws:
java.lang.NumberFormatException - if the String could not be converted

parse

public static final java.lang.Number parse(java.lang.String aLocale,
                                           java.lang.String aPattern,
                                           boolean aGroupingUsed,
                                           java.lang.String aCurrency,
                                           boolean aIntegerOnly,
                                           java.lang.String aString)
Parses the String using the specified pattern and locale as a number.

Parameters:
aLocale - locale name, if null or blank, the default locale is used
aPattern - format pattern
aGroupingUsed - true if grouping should be used
aCurrency - Currency name, selects explicit currency symbols recognized.
aIntegerOnly - true if integer only parse desired
aString - formatted value to convert to number
Returns:
Number value
Throws:
java.lang.NumberFormatException - if the String could not be converted

parseLocalizedAsInteger

public static final int parseLocalizedAsInteger(java.lang.String aLocale,
                                                java.lang.String aString)
Convenience method to parse a value as an integer, using localized formats

Parameters:
aLocale - name of locale whose formats should be used
aString - String to be parsed
Returns:
int value
Throws:
java.lang.NumberFormatException - if string cannot be parsed

parseLocalizedAsDouble

public static final double parseLocalizedAsDouble(java.lang.String aLocale,
                                                  java.lang.String aString)
Convenience method to parse a value as a double, using localized formats

Parameters:
aLocale - name of locale whose formats should be used
aString - String to be parsed
Returns:
double value
Throws:
java.lang.NumberFormatException - if string cannot be parsed

parseLocalizedAsBigDecimal

public static final com.pega.ibm.icu.math.BigDecimal parseLocalizedAsBigDecimal(java.lang.String aLocale,
                                                                                java.lang.String aString)
Convenience method to parse a value as a BigDecimal, using localized formats

Parameters:
aLocale - name of locale whose formats should be used
aString - String to be parsed
Returns:
BigDecimal value
Throws:
java.lang.NumberFormatException - if string cannot be parsed

numberToBigDecimal

public static final com.pega.ibm.icu.math.BigDecimal numberToBigDecimal(java.lang.Number aValue)
Helper function to convert java.lang.Number to ICU BigDecimal, preserving as much accuracy as possible. Needed since the Number interface does not have a method to retrieve BigDecimal values.

Parameters:
aValue - Number to be converted
Returns:
BigDecimal value

getCurrency

public static final com.pega.ibm.icu.util.Currency getCurrency(java.util.Locale aLocale,
                                                               java.lang.String aCurrency)
Retrieve the desired currency value. This method avoids cloning a new instance of Currency for each request. Try to use the following, in order:
aCurrency
pxRequestor.pyBaseCurrency
aLocale's default currency
default locale's default currency

Parameters:
aLocale - Locale to be used (used if aCurrency omitted)
aCurrency - name of Currency desired
Returns:
Currency instance

getCurrencyByLocale

public static com.pega.ibm.icu.util.Currency getCurrencyByLocale(java.util.Locale aLocale)

getCurrencyCodesForLocale

public static java.util.Set getCurrencyCodesForLocale(java.lang.String aLocaleName)
Returns the ISO currency codes for the specified aLocaleName including multi-level fallback. That is, if a currency is not found in the en_US Currencies data, then the en Currencies data will be returned.

Parameters:
aLocaleName - String locale name
Returns:
Set of String objects for the ISO 4217 currency codes for the specified locale

isCurrencyValid

public static boolean isCurrencyValid(java.lang.String isoCode)
validate that a given currency name is valid.

Adapted from com.ibm.icu.util.Currency. The technique to access currency metadata is icu version specific.

Parameters:
isoCode - name of currency to validate
Returns:
true if valid


Copyright © 2012 Pegasystems Inc. All Rights Reserved.