sharkysoft.com

com.sharkysoft.printf.engine
Class IntegerFormatter

java.lang.Object
  extended bycom.sharkysoft.printf.engine.StringFormatter
      extended bycom.sharkysoft.printf.engine.NumberFormatter
          extended bycom.sharkysoft.printf.engine.IntegerFormatter

public class IntegerFormatter
extends NumberFormatter

Formats integers.

An IntegerFormatter formats integers. See NumberFormatter for a generalized discussion relating to this class.

Example: Output the contents of integer array vals, one integer per line, right-justified in a 25-character-wide field. Round each integer to 3 significant digits.

int[] vals = {2000, 34, 32768};
IntegerFormatter formatter = new IntegerFormatter();
formatter.setFieldWidth(25);
formatter.setPadChar(':'); // non-space chosen for emphasis
formatter.setAlignment(AlignmentMode.gpRight);
formatter.setSigDigits(3);
for (int i = 0; i < vals.length; ++ i)
  System.out.println(formatter.format(vals[i]));

This produces the following output:

:::::::::::::::::::::2000
:::::::::::::::::::::::34
::::::::::::::::::::32800

The formatting properties for a given instance of this class can be updated at any time, and doing so changes the way that subsequent data is formatted. For a detailed description of all formatting properties, review the documentation below and in the superclass.

Author:
Sharky

Field Summary
protected  char mcPadDigit
          Pad digit.
protected  int mnMinDigits
          Minimum digits.
 
Fields inherited from class com.sharkysoft.printf.engine.NumberFormatter
mnRadix, mnSigDigits, msNegPrefix, msNegSuffix, msPosPrefix, msPosSuffix, msZeroPrefix, msZeroSuffix, mzUpperCase
 
Fields inherited from class com.sharkysoft.printf.engine.StringFormatter
mcPadChar, mnAlignment, mnCropping, mnFieldWidth
 
Constructor Summary
IntegerFormatter()
          Default constructor.
 
Method Summary
 java.lang.String format(java.math.BigInteger ipValue)
          Renders value.
 java.lang.String format(int inValue)
          Renders value.
 java.lang.String format(long ilValue)
          Renders value.
 java.lang.String formatUnsigned(byte ibValue)
          Renders unsigned value.
 java.lang.String formatUnsigned(int inValue)
          Renders unsigned value.
 java.lang.String formatUnsigned(long ilValue)
          Renders unsigned value.
 java.lang.String formatUnsigned(short iwValue)
          Renders unsigned value.
 int getMinDigits()
          Retrieves MinDigits property.
 char getPadDigit()
          Retrieves PadDigit property.
 void setMinDigits(int inMinDigits)
          Updates MinDigits property.
 void setPadDigit(char icPadDigit)
          Updates PadDigit property.
 
Methods inherited from class com.sharkysoft.printf.engine.NumberFormatter
getNegPrefix, getNegSuffix, getPosPrefix, getPosSuffix, getRadix, getSigDigits, getUpperCase, getZeroPrefix, getZeroSuffix, setNegPrefix, setNegSuffix, setPosPrefix, setPosSuffix, setRadix, setSigDigits, setUpperCase, setZeroPrefix, setZeroSuffix
 
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

mcPadDigit

protected char mcPadDigit
Pad digit.

Details: Property PadDigit is the pad digit to use when extra digits are required because of the MinDigits property. Default value: '0'.

See Also:
getPadDigit(), setPadDigit(char)

mnMinDigits

protected int mnMinDigits
Minimum digits.

Details: Property MinDigits is the minimum number of digits to display in the formatted output. If the number isn't large enough to fill all the digits, the padding digit will be used to fill out the rest. If this property is 0, digits will only be displayed if the value being rendered is non-zero. Default value: 1.

See Also:
getMinDigits(), setMinDigits(int)
Constructor Detail

IntegerFormatter

public IntegerFormatter()
Default constructor.

Method Detail

getPadDigit

public char getPadDigit()
Retrieves PadDigit property.

Returns:
current value
See Also:
mcPadDigit

setPadDigit

public void setPadDigit(char icPadDigit)
Updates PadDigit property.

Parameters:
icPadDigit - new value
See Also:
mcPadDigit

getMinDigits

public int getMinDigits()
Retrieves MinDigits property.

Returns:
current value
See Also:
mnMinDigits

setMinDigits

public void setMinDigits(int inMinDigits)
Updates MinDigits property.

Parameters:
inMinDigits - new value
See Also:
mnMinDigits

format

public java.lang.String format(java.math.BigInteger ipValue)
Renders value.

Details: format renders the given integer value into a numeric string, formatted according to the criteria set forth in the properties.

Parameters:
ipValue - value to render
Returns:
rendered value

format

public final java.lang.String format(long ilValue)
Renders value.

Details: format renders the given integer value into a numeric string, formatted according to the criteria set forth in the properties.

Parameters:
ilValue - value to render
Returns:
rendered value

format

public final java.lang.String format(int inValue)
Renders value.

Details: format renders the given integer value into a numeric string, formatted according to the criteria set forth in the properties.

Parameters:
inValue - value to render
Returns:
rendered value

formatUnsigned

public final java.lang.String formatUnsigned(long ilValue)
Renders unsigned value.

Details: formatUnsigned renders the given integer value as a numeric string, formatted according to the criteria set forth in the properties. The integer value is interpreted as an unsigned value.

Parameters:
ilValue - value to render
Returns:
rendered value

formatUnsigned

public final java.lang.String formatUnsigned(int inValue)
Renders unsigned value.

Details: formatUnsigned renders the given integer value as a numeric string, formatted according to the criteria set forth in the properties. The integer value is interpreted as an unsigned value.

Parameters:
inValue - value to render
Returns:
rendered value

formatUnsigned

public final java.lang.String formatUnsigned(short iwValue)
Renders unsigned value.

Details: formatUnsigned renders the given integer value as a numeric string, formatted according to the criteria set forth in the properties. The integer value is interpreted as an unsigned value.

Parameters:
iwValue - value to render
Returns:
rendered value

formatUnsigned

public final java.lang.String formatUnsigned(byte ibValue)
Renders unsigned value.

Details: formatUnsigned renders the given integer value as a numeric string, formatted according to the criteria set forth in the properties. The integer value is interpreted as an unsigned value.

Parameters:
ibValue - value to render
Returns:
rendered value

sharkysoft.com

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