com.endeca.portal.format
Class NumberFormatter

java.lang.Object
  extended by com.endeca.portal.format.Formatter
      extended by com.endeca.portal.format.NumberFormatter
All Implemented Interfaces:
FormatSettings, NumberFormatSettings, java.io.Serializable

public class NumberFormatter
extends Formatter
implements NumberFormatSettings, java.io.Serializable

Formatter for formatting Number, Currency or Percentage types based on locale and format settings. If the value of a format setting is DEFAULT, the value of the format setting of its parent will be used if it is not DEFAULT. Otherwise, system default value of that format setting will be used.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.endeca.portal.format.Formatter
Formatter.FormatParseException
 
Nested classes/interfaces inherited from interface com.endeca.portal.format.NumberFormatSettings
NumberFormatSettings.DecimalPlacesMode, NumberFormatSettings.DecimalSeparator, NumberFormatSettings.FormatPattern, NumberFormatSettings.GroupingSeparator, NumberFormatSettings.IncludeCurrencySymbol, NumberFormatSettings.IncludeGroupingSeparator, NumberFormatSettings.IncludePercentageSign
 
Nested classes/interfaces inherited from interface com.endeca.portal.format.FormatSettings
FormatSettings.Type
 
Field Summary
static java.lang.String DEFAULT_CURRENCY_SYMBOL
           
static int DEFAULT_DECIMAL_PLACES
           
static NumberFormatSettings.DecimalPlacesMode DEFAULT_DECIMAL_PLACES_MODE
           
static NumberFormatSettings.DecimalSeparator DEFAULT_DECIMAL_SEPARATOR
           
static NumberFormatSettings.FormatPattern DEFAULT_FORMAT_PATTERN
           
static NumberFormatSettings.GroupingSeparator DEFAULT_GROUPINGSEPARATOR
           
static NumberFormatSettings.IncludeCurrencySymbol DEFAULT_INCLUDE_CURRENCY_SYMBOL
           
static NumberFormatSettings.IncludeGroupingSeparator DEFAULT_INCLUDE_GROUPING_SEPARATOR
           
static NumberFormatSettings.IncludePercentageSign DEFAULT_INCLUDE_PERCENTAGE_SIGN
           
static int DEFAULT_INTEGER_DECIMAL_PLACES
           
 
Fields inherited from class com.endeca.portal.format.Formatter
parentFormatSettings, type
 
Constructor Summary
NumberFormatter()
           
NumberFormatter(FormatSettings.Type type)
           
 
Method Summary
protected  void clearCachedJavaFormat()
           
protected  void createJavaFormat()
           
 java.lang.String format(double rawNumber)
           
 java.lang.String format(java.lang.String rawString)
           
protected  java.text.NumberFormat getCachedJavaFormat()
           
static java.lang.String[] getCurrencyList()
           
 java.lang.String getCurrencySymbol()
           
 int getDecimalPlaces()
           
 NumberFormatSettings.DecimalPlacesMode getDecimalPlacesMode()
           
 NumberFormatSettings.DecimalSeparator getDecimalSeparator()
           
protected static char getDecimalSeparatorChar(NumberFormatSettings.DecimalSeparator decimalSeparator)
           
 NumberFormatSettings.FormatPattern getFormatPattern()
           
 NumberFormatSettings.GroupingSeparator getGroupingSeparator()
           
protected static char getGroupingSeparatorChar(NumberFormatSettings.GroupingSeparator groupingSeparator)
           
 NumberFormatSettings.IncludeCurrencySymbol getIncludeCurrencySymbol()
           
 NumberFormatSettings.IncludeGroupingSeparator getIncludeGroupingSeparator()
           
 NumberFormatSettings.IncludePercentageSign getIncludePercentageSign()
           
 boolean getIsInteger()
           
 java.lang.String getMergedCurrencySymbol()
           
 int getMergedDecimalPlaces()
           
 NumberFormatSettings.DecimalPlacesMode getMergedDecimalPlacesMode()
           
 NumberFormatSettings.DecimalSeparator getMergedDecimalSeparator()
           
 NumberFormatSettings.FormatPattern getMergedFormatPattern()
           
 NumberFormatSettings.GroupingSeparator getMergedGroupingSeparator()
           
 NumberFormatSettings.IncludeCurrencySymbol getMergedIncludeCurrencySymbol()
           
 NumberFormatSettings.IncludeGroupingSeparator getMergedIncludeGroupingSeparator()
           
 NumberFormatSettings.IncludePercentageSign getMergedIncludePercentageSign()
           
 FormatSettings.Type getMergedType()
          Return the merged type based on the following rules: Child's type will be honored if parent is null or the parent's type is NUMBER.
protected  void initializeJavaFormat()
           
protected  void localeChanged()
          Subclasses can override this method to clear/reset some cached data that is dependent on locale, for example cached Java format.
protected  void parentFormatSettingsChanged()
          Subclasses can override this method to clear/reset some cached data that is dependent on parent format settings, for example cached Java format.
 void setCurrencySymbol(java.lang.String currencySymbol)
           
 void setDecimalPlaces(int decimalPlaces)
           
 void setDecimalPlacesMode(NumberFormatSettings.DecimalPlacesMode decimalPlacesMode)
           
 void setDecimalSeparator(NumberFormatSettings.DecimalSeparator decimalSeparator)
           
 void setFormatPattern(NumberFormatSettings.FormatPattern formatPattern)
           
 void setGroupingSeparator(NumberFormatSettings.GroupingSeparator groupingSeparator)
           
 void setIncludeCurrencySymbol(NumberFormatSettings.IncludeCurrencySymbol includeCurrencySymbol)
           
 void setIncludeGroupingSeparator(NumberFormatSettings.IncludeGroupingSeparator includeGroupingSeparator)
           
 void setIncludePercentageSign(NumberFormatSettings.IncludePercentageSign includePercentageSign)
           
 void setIsInteger(boolean isInteger)
           
 
Methods inherited from class com.endeca.portal.format.Formatter
getLocale, getParentFormatSettings, getType, loadResources, setLocale, setLocale, setParentFormatSettings, setType, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.endeca.portal.format.FormatSettings
getType, toString
 

Field Detail

DEFAULT_INCLUDE_GROUPING_SEPARATOR

public static final NumberFormatSettings.IncludeGroupingSeparator DEFAULT_INCLUDE_GROUPING_SEPARATOR

DEFAULT_DECIMAL_PLACES_MODE

public static final NumberFormatSettings.DecimalPlacesMode DEFAULT_DECIMAL_PLACES_MODE

DEFAULT_DECIMAL_PLACES

public static final int DEFAULT_DECIMAL_PLACES
See Also:
Constant Field Values

DEFAULT_INTEGER_DECIMAL_PLACES

public static final int DEFAULT_INTEGER_DECIMAL_PLACES
See Also:
Constant Field Values

DEFAULT_FORMAT_PATTERN

public static final NumberFormatSettings.FormatPattern DEFAULT_FORMAT_PATTERN

DEFAULT_DECIMAL_SEPARATOR

public static final NumberFormatSettings.DecimalSeparator DEFAULT_DECIMAL_SEPARATOR

DEFAULT_GROUPINGSEPARATOR

public static final NumberFormatSettings.GroupingSeparator DEFAULT_GROUPINGSEPARATOR

DEFAULT_CURRENCY_SYMBOL

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

DEFAULT_INCLUDE_CURRENCY_SYMBOL

public static final NumberFormatSettings.IncludeCurrencySymbol DEFAULT_INCLUDE_CURRENCY_SYMBOL

DEFAULT_INCLUDE_PERCENTAGE_SIGN

public static final NumberFormatSettings.IncludePercentageSign DEFAULT_INCLUDE_PERCENTAGE_SIGN
Constructor Detail

NumberFormatter

public NumberFormatter()

NumberFormatter

public NumberFormatter(FormatSettings.Type type)
Method Detail

getMergedType

public FormatSettings.Type getMergedType()
Return the merged type based on the following rules: Child's type will be honored if parent is null or the parent's type is NUMBER. Otherwise, if the parent's type is either CURRENCY or PERCENTAGE, parent's type will be honored.

Specified by:
getMergedType in interface NumberFormatSettings

getIsInteger

public boolean getIsInteger()
Specified by:
getIsInteger in interface NumberFormatSettings

setIsInteger

public void setIsInteger(boolean isInteger)

getDecimalPlacesMode

public NumberFormatSettings.DecimalPlacesMode getDecimalPlacesMode()
Specified by:
getDecimalPlacesMode in interface NumberFormatSettings

setDecimalPlacesMode

public void setDecimalPlacesMode(NumberFormatSettings.DecimalPlacesMode decimalPlacesMode)

getMergedDecimalPlacesMode

public NumberFormatSettings.DecimalPlacesMode getMergedDecimalPlacesMode()
Specified by:
getMergedDecimalPlacesMode in interface NumberFormatSettings

getDecimalPlaces

public int getDecimalPlaces()
Specified by:
getDecimalPlaces in interface NumberFormatSettings

setDecimalPlaces

public void setDecimalPlaces(int decimalPlaces)

getMergedDecimalPlaces

public int getMergedDecimalPlaces()
Specified by:
getMergedDecimalPlaces in interface NumberFormatSettings

getDecimalSeparator

public NumberFormatSettings.DecimalSeparator getDecimalSeparator()
Specified by:
getDecimalSeparator in interface NumberFormatSettings

setDecimalSeparator

public void setDecimalSeparator(NumberFormatSettings.DecimalSeparator decimalSeparator)

getMergedDecimalSeparator

public NumberFormatSettings.DecimalSeparator getMergedDecimalSeparator()
Specified by:
getMergedDecimalSeparator in interface NumberFormatSettings

getGroupingSeparator

public NumberFormatSettings.GroupingSeparator getGroupingSeparator()
Specified by:
getGroupingSeparator in interface NumberFormatSettings

setGroupingSeparator

public void setGroupingSeparator(NumberFormatSettings.GroupingSeparator groupingSeparator)

getMergedGroupingSeparator

public NumberFormatSettings.GroupingSeparator getMergedGroupingSeparator()
Specified by:
getMergedGroupingSeparator in interface NumberFormatSettings

getCurrencySymbol

public java.lang.String getCurrencySymbol()
Specified by:
getCurrencySymbol in interface NumberFormatSettings

setCurrencySymbol

public void setCurrencySymbol(java.lang.String currencySymbol)

getMergedCurrencySymbol

public java.lang.String getMergedCurrencySymbol()
Specified by:
getMergedCurrencySymbol in interface NumberFormatSettings

getIncludeCurrencySymbol

public NumberFormatSettings.IncludeCurrencySymbol getIncludeCurrencySymbol()
Specified by:
getIncludeCurrencySymbol in interface NumberFormatSettings

setIncludeCurrencySymbol

public void setIncludeCurrencySymbol(NumberFormatSettings.IncludeCurrencySymbol includeCurrencySymbol)

getMergedIncludeCurrencySymbol

public NumberFormatSettings.IncludeCurrencySymbol getMergedIncludeCurrencySymbol()
Specified by:
getMergedIncludeCurrencySymbol in interface NumberFormatSettings

getIncludeGroupingSeparator

public NumberFormatSettings.IncludeGroupingSeparator getIncludeGroupingSeparator()
Specified by:
getIncludeGroupingSeparator in interface NumberFormatSettings

setIncludeGroupingSeparator

public void setIncludeGroupingSeparator(NumberFormatSettings.IncludeGroupingSeparator includeGroupingSeparator)

getMergedIncludeGroupingSeparator

public NumberFormatSettings.IncludeGroupingSeparator getMergedIncludeGroupingSeparator()
Specified by:
getMergedIncludeGroupingSeparator in interface NumberFormatSettings

getFormatPattern

public NumberFormatSettings.FormatPattern getFormatPattern()
Specified by:
getFormatPattern in interface NumberFormatSettings

setFormatPattern

public void setFormatPattern(NumberFormatSettings.FormatPattern formatPattern)

getMergedFormatPattern

public NumberFormatSettings.FormatPattern getMergedFormatPattern()
Specified by:
getMergedFormatPattern in interface NumberFormatSettings

getIncludePercentageSign

public NumberFormatSettings.IncludePercentageSign getIncludePercentageSign()
Specified by:
getIncludePercentageSign in interface NumberFormatSettings

setIncludePercentageSign

public void setIncludePercentageSign(NumberFormatSettings.IncludePercentageSign includePercentageSign)

getMergedIncludePercentageSign

public NumberFormatSettings.IncludePercentageSign getMergedIncludePercentageSign()
Specified by:
getMergedIncludePercentageSign in interface NumberFormatSettings

getCachedJavaFormat

protected java.text.NumberFormat getCachedJavaFormat()

clearCachedJavaFormat

protected void clearCachedJavaFormat()

localeChanged

protected void localeChanged()
Description copied from class: Formatter
Subclasses can override this method to clear/reset some cached data that is dependent on locale, for example cached Java format.

Overrides:
localeChanged in class Formatter

parentFormatSettingsChanged

protected void parentFormatSettingsChanged()
Description copied from class: Formatter
Subclasses can override this method to clear/reset some cached data that is dependent on parent format settings, for example cached Java format.

Overrides:
parentFormatSettingsChanged in class Formatter

createJavaFormat

protected void createJavaFormat()

initializeJavaFormat

protected void initializeJavaFormat()

getDecimalSeparatorChar

protected static char getDecimalSeparatorChar(NumberFormatSettings.DecimalSeparator decimalSeparator)

getGroupingSeparatorChar

protected static char getGroupingSeparatorChar(NumberFormatSettings.GroupingSeparator groupingSeparator)

format

public java.lang.String format(java.lang.String rawString)
                        throws Formatter.FormatParseException
Specified by:
format in class Formatter
Throws:
Formatter.FormatParseException

format

public java.lang.String format(double rawNumber)

getCurrencyList

public static java.lang.String[] getCurrencyList()