sharkysoft.com

com.sharkysoft.printf.engine
Class NumberFormatter

java.lang.Object
  extended bycom.sharkysoft.printf.engine.StringFormatter
      extended bycom.sharkysoft.printf.engine.NumberFormatter
Direct Known Subclasses:
IntegerFormatter, RealFormatter

public abstract class NumberFormatter
extends StringFormatter

Formats numbers.

A NumberFormatter formats numbers in a field by adjusting their precision and padding them as necessary, according to criteria selected by the client. Properties control various formatting constraints, such as field width, justification style, padding characters, and so on.

Because applications that format numeric values frequently format multiple values with the same criteria, this class is designed to "remember" selected formatting properties so that the settings they can be reused with each subsequent formatting request. This approach minimizes the number of parameters that must be passed with each formatting call and results in more efficient execution for large formatting jobs.

NumberFormatter extends StringFormatter with abstract number formatting constraints that are common to IntegerFormatter and RealFormatter. This class does not actually implement any of the specific numeric formatting rules, but leaves that work to the subclasses.

Author:
Sharky
See Also:
IntegerFormatter, RealFormatter

Field Summary
protected  int mnRadix
          Radix.
protected  int mnSigDigits
          Significant digits.
protected  java.lang.String msNegPrefix
          Negative prefix.
protected  java.lang.String msNegSuffix
          Negative suffix.
protected  java.lang.String msPosPrefix
          Positive prefix.
protected  java.lang.String msPosSuffix
          Positive suffix.
protected  java.lang.String msZeroPrefix
          Zero prefix.
protected  java.lang.String msZeroSuffix
          Zero suffix.
protected  boolean mzUpperCase
          Upper case/lower case.
 
Fields inherited from class com.sharkysoft.printf.engine.StringFormatter
mcPadChar, mnAlignment, mnCropping, mnFieldWidth
 
Constructor Summary
protected NumberFormatter()
          Default constructor.
 
Method Summary
 java.lang.String getNegPrefix()
          Retrieves NegPrefix property.
 java.lang.String getNegSuffix()
          Retrieves NegSuffix property.
 java.lang.String getPosPrefix()
          Retrieves PosPrefix property.
 java.lang.String getPosSuffix()
          Retrieves PosSuffix property.
 int getRadix()
          Retrieves Radix property.
 int getSigDigits()
          Retrieves SigDigits property.
 boolean getUpperCase()
          Retrieves UpperCase property.
 java.lang.String getZeroPrefix()
          Retrieves ZeroPrefix property.
 java.lang.String getZeroSuffix()
          Retrieves ZeroSuffix property.
 void setNegPrefix(java.lang.String isNegPrefix)
          Updates NegPrefix property.
 void setNegSuffix(java.lang.String isNegSuffix)
          Updates NegSuffix property.
 void setPosPrefix(java.lang.String isPosPrefix)
          Updates PosPrefix property.
 void setPosSuffix(java.lang.String isPosSuffix)
          Updates PosSuffix property.
 void setRadix(int inRadix)
          Updates Radix property.
 void setSigDigits(int inSigDigits)
          Updates SigDigits property.
 void setUpperCase(boolean izUpperCase)
          Updates UpperCase property.
 void setZeroPrefix(java.lang.String isZeroPrefix)
          Updates ZeroPrefix property.
 void setZeroSuffix(java.lang.String isZeroSuffix)
          Updates ZeroSuffix property.
 
Methods inherited from class com.sharkysoft.printf.engine.StringFormatter
format, format, getAlignment, getCropping, getFieldWidth, getPadChar, setAlignment, setCropping, setFieldWidth, setPadChar, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mnRadix

protected int mnRadix
Radix.

Details: Property Radix is the output radix (numeric base) for stringified numbers. For example, a value of 16 indicates that the value will be represented in hexadecimal. This value may not be set to values less than 2 or greater than 36. Default value: 10.

See Also:
getRadix(), setRadix(int)

mzUpperCase

protected boolean mzUpperCase
Upper case/lower case.

Details: Property UpperCase determines whether upper or lower case letters will be used when property Radix is greater than 10. If this property is true, upper case letters will be used. If this property is false, lower case letters will be used. The default value for this property is false.

See Also:
getUpperCase(), setUpperCase(boolean)

mnSigDigits

protected int mnSigDigits
Significant digits.

Details: Property SigDigits constrains the number of significant digits to express in the output, so that the value will be rounded if necessary. Setting this value to 0 indicates that all digits are considered significant. This constraint may conflict with the MaxRightDigits property in RealFormatter. Default value: 0.

See Also:
getSigDigits(), setSigDigits(int)

msPosPrefix

protected java.lang.String msPosPrefix
Positive prefix.

Details: Property PosPrefix is the string that precedes positive values. This property may not be null. Default value: "".

See Also:
getPosPrefix(), setPosPrefix(String)

msPosSuffix

protected java.lang.String msPosSuffix
Positive suffix.

Details: Property PosSuffix is the string that follows positive values. This property may not be null. Default value: "".

See Also:
getPosSuffix(), setPosSuffix(String)

msZeroPrefix

protected java.lang.String msZeroPrefix
Zero prefix.

Details: Property ZeroPrefix is the string that precedes zero values. This property may not be null. Default value: "".

See Also:
getZeroPrefix(), setZeroPrefix(String)

msZeroSuffix

protected java.lang.String msZeroSuffix
Zero suffix.

Details: Property ZeroSuffix is the string that follows zero values. This property may not be null. Default value: "".

See Also:
getZeroSuffix(), setZeroSuffix(String)

msNegPrefix

protected java.lang.String msNegPrefix
Negative prefix.

Details: Property NegPrefix is the string that precedes negative values. This property may not be null. Default value: "-".

See Also:
getNegPrefix(), setNegPrefix(String)

msNegSuffix

protected java.lang.String msNegSuffix
Negative suffix.

Details: Property NegSuffix is the string that follows negative values. This property may not be null. Default value: "".

See Also:
getNegSuffix(), setNegSuffix(String)
Constructor Detail

NumberFormatter

protected NumberFormatter()
Default constructor.

Method Detail

getRadix

public int getRadix()
Retrieves Radix property.

Returns:
current value
See Also:
mnRadix

setRadix

public void setRadix(int inRadix)
Updates Radix property.

Parameters:
inRadix - new value
See Also:
mnRadix

getUpperCase

public boolean getUpperCase()
Retrieves UpperCase property.

Returns:
current value
See Also:
mzUpperCase

setUpperCase

public void setUpperCase(boolean izUpperCase)
Updates UpperCase property.

Parameters:
izUpperCase - new value
See Also:
mzUpperCase

getSigDigits

public int getSigDigits()
Retrieves SigDigits property.

Returns:
current value
See Also:
mnSigDigits

setSigDigits

public void setSigDigits(int inSigDigits)
Updates SigDigits property.

Parameters:
inSigDigits - new value
See Also:
mnSigDigits

getPosPrefix

public java.lang.String getPosPrefix()
Retrieves PosPrefix property.

Returns:
current value
See Also:
msPosPrefix

setPosPrefix

public void setPosPrefix(java.lang.String isPosPrefix)
Updates PosPrefix property.

Parameters:
isPosPrefix - new value
See Also:
msPosPrefix

getPosSuffix

public java.lang.String getPosSuffix()
Retrieves PosSuffix property.

Returns:
current value
See Also:
msPosSuffix

setPosSuffix

public void setPosSuffix(java.lang.String isPosSuffix)
Updates PosSuffix property.

Parameters:
isPosSuffix - new value
See Also:
msPosSuffix

getZeroPrefix

public java.lang.String getZeroPrefix()
Retrieves ZeroPrefix property.

Returns:
current value
See Also:
msZeroPrefix

setZeroPrefix

public void setZeroPrefix(java.lang.String isZeroPrefix)
Updates ZeroPrefix property.

Parameters:
isZeroPrefix - new value
See Also:
msZeroPrefix

getZeroSuffix

public java.lang.String getZeroSuffix()
Retrieves ZeroSuffix property.

Returns:
current value
See Also:
msZeroSuffix

setZeroSuffix

public void setZeroSuffix(java.lang.String isZeroSuffix)
Updates ZeroSuffix property.

Parameters:
isZeroSuffix - new value
See Also:
msZeroSuffix

getNegPrefix

public java.lang.String getNegPrefix()
Retrieves NegPrefix property.

Returns:
current value
See Also:
msNegPrefix

setNegPrefix

public void setNegPrefix(java.lang.String isNegPrefix)
Updates NegPrefix property.

Parameters:
isNegPrefix - new value
See Also:
msNegPrefix

getNegSuffix

public java.lang.String getNegSuffix()
Retrieves NegSuffix property.

Returns:
current value
See Also:
msNegSuffix

setNegSuffix

public void setNegSuffix(java.lang.String isNegSuffix)
Updates NegSuffix property.

Parameters:
isNegSuffix - new value
See Also:
msNegSuffix

sharkysoft.com

Copyright © 1997-2004 Sharkysoft (sharkysoft.com). All rights reserved.