Project Wonder 2.0

er.extensions
Class ERXNumberFormatter

java.lang.Object
  extended byjava.text.Format
      extended bycom.webobjects.foundation.NSNumberFormatter
          extended byer.extensions.ERXNumberFormatter
All Implemented Interfaces:
Cloneable, Serializable

public class ERXNumberFormatter
extends NSNumberFormatter

An extension to the number formatter. It will strip out the characters '%$,' when parsing a string and can scale values by setting a pattern like (/1024=)0.00 KB which will divide the actual value by 1024 or (*60;4=)0.00 which will multiply the actual value by 60. When used for parsing, the resulting value will be scaled to a scale of 4. So when the real value is 0.0165, the display value will be 0.99 and when this is re-entered, the resulting value will again be 0.0165.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.text.Format
Format.Field
 
Field Summary
protected static String DefaultKey
           
 
Fields inherited from class com.webobjects.foundation.NSNumberFormatter
_CLASS, _CurrencyPattern, _DecimalPattern, _IntegerPattern, DefaultPattern, NSDecimalNotANumber, RoundBankers, RoundDown, RoundPlain, RoundUp
 
Constructor Summary
ERXNumberFormatter()
           
ERXNumberFormatter(String pattern)
          Public constructor
 
Method Summary
static Format defaultNumberFormatterForObject(Object object)
           
 StringBuffer format(Object value, StringBuffer buffer, FieldPosition position)
          Overridden to perform optional conversions on the value given.
static NSNumberFormatter numberFormatterForPattern(String pattern)
          Returns a shared instance for the specified pattern.
 Object parseObject(String aString)
          Strips out the ignored characters and optionally performs an operation on the value from the string to be parsed.
protected  BigDecimal performFormat(BigDecimal value)
          Override this in your subclass to provide for other operations when formatting a value.
protected  BigDecimal performParse(BigDecimal value)
          Override this in your subclass to provide for other operations when parsing a value.
protected  void setFactor(BigDecimal value)
           
 void setIgnoredChars(String value)
           
static void setNumberFormatterForPattern(NSNumberFormatter formatter, String pattern)
          Sets a shared instance for the specified pattern.
protected  void setOperator(String value)
           
 void setPattern(String pattern)
          Overridden to search the pattern for operators and factors.
protected  void setScale(Integer value)
           
static NSNumberFormatter sharedInstance()
          Returns the default shared instance
 
Methods inherited from class com.webobjects.foundation.NSNumberFormatter
allowsFloats, attributedStringForNil, attributedStringForNotANumber, attributedStringForZero, availableLocales, currencySymbol, decimalSeparator, defaultLocale, defaultLocalizesPattern, format, hasThousandSeparators, locale, localizesFormat, localizesPattern, maximum, minimum, negativeFormat, negativePattern, objectValueForString, parseObject, pattern, positiveFormat, positivePattern, roundingBehavior, setAllowsFloats, setAttributedStringForNil, setAttributedStringForNotANumber, setAttributedStringForZero, setCurrencySymbol, setDecimalSeparator, setDefaultLocale, setDefaultLocalizesPattern, setFormat, setHasThousandSeparators, setLocale, setLocalizesFormat, setLocalizesPattern, setMaximum, setMinimum, setNegativeFormat, setNegativePattern, setPositiveFormat, setPositivePattern, setRoundingBehavior, setStringForNotANumber, setStringForNull, setStringForZero, setThousandSeparator, stringForNotANumber, stringForNull, stringForObjectValue, stringForZero, thousandSeparator
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DefaultKey

protected static final String DefaultKey
See Also:
Constant Field Values
Constructor Detail

ERXNumberFormatter

public ERXNumberFormatter(String pattern)
Public constructor


ERXNumberFormatter

public ERXNumberFormatter()
Method Detail

sharedInstance

public static NSNumberFormatter sharedInstance()
Returns the default shared instance

Returns:
shared instance

defaultNumberFormatterForObject

public static Format defaultNumberFormatterForObject(Object object)
Parameters:
object -
Returns:

numberFormatterForPattern

public static NSNumberFormatter numberFormatterForPattern(String pattern)
Returns a shared instance for the specified pattern.

Returns:
shared instance of formatter

setNumberFormatterForPattern

public static void setNumberFormatterForPattern(NSNumberFormatter formatter,
                                                String pattern)
Sets a shared instance for the specified pattern.

Returns:
shared instance of formatter

setIgnoredChars

public void setIgnoredChars(String value)

setFactor

protected void setFactor(BigDecimal value)

setOperator

protected void setOperator(String value)

setScale

protected void setScale(Integer value)

setPattern

public void setPattern(String pattern)
Overridden to search the pattern for operators and factors. The pattern should be '(' . operatorChar . factor . [';' scale ] . '=)' normalFormatterString

See Also:
NSNumberFormatter.setPattern(java.lang.String)

performFormat

protected BigDecimal performFormat(BigDecimal value)
Override this in your subclass to provide for other operations when formatting a value.

Parameters:
value -
Returns:

performParse

protected BigDecimal performParse(BigDecimal value)
Override this in your subclass to provide for other operations when parsing a value.

Parameters:
value -
Returns:

parseObject

public Object parseObject(String aString)
                   throws ParseException
Strips out the ignored characters and optionally performs an operation on the value from the string to be parsed.

Parameters:
aString - to be parsed
Returns:
the parsed object
Throws:
ParseException

format

public StringBuffer format(Object value,
                           StringBuffer buffer,
                           FieldPosition position)
Overridden to perform optional conversions on the value given.

See Also:
Format.format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition)

Last updated: Do, Dez 9, 2004 • 12:46 PM CET

Copyright © 2002 – 2004 Project Wonder.