All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----com.roguewave.format.QuickFormat
QuickFormat format =
new QuickFormat("<tr><td> _ </td><td> _ </td><td> _ </td></tr>\n"); // javadoc bug: -->
format.nfmt(0,2).arg(1.2).arg("2.4").npic("( N)").arg(-4.8).print(System.out);
produces: <tr><td> 1.20 </td><td> 2.4 </td><td> ( 4.80) </td></tr>
Writing code to produce formatted output using the above four classes directly can require a lot of typing; the QuickFormat class is a wrapper for the other classes which provides a terser output syntax:
QuickFormat format = new QuickFormat("| ________ | ________ | ________ |").pre(2);
if(d < 0)
format.arg("").arg(-d).npic("(N)").arg(balance).println(System.out);
else
format.arg(d).arg("").npic("(N)").arg(balance).println(System.out);
The QuickFormat class interface is a mixture of C and C++ output styles:
the use of TextPicture provides the intuitive readability of
printf, while the chaining of methods is reminiscent of C++'s overloaded
shift operator (each method returns a QuickFormat object on which the subsequent
method is invoked).
A QuickFormat object is usually created using a TextPicture picture string; specifics of formatting and the subsitution of values is then done with method calls.
There are a number of arg methods which correspond to those in the TextPicture class with the exception that numeric values are formatted according to a NumericPicture object kept internally in QuickFormat objects.
A NumericFormat object is also held by QuickFormat for determining the width and precision of numeric arguments.The npic(NumericPicture nl) method can be used to substitute a new NumericPicture object for the one in use. The nfmt(int width, int precision) method changes the width and precision of the current NumericFormat in use, while pre(int precision) changes only the precision.
Note that in order to make use of the most advanced features of NumericFormat, you will have to create your own NumericFormat object separate from QuickFormat and use the NumericFormat.format(n) method to obtain a string. That string can then be use with the QuickFormat.arg(String) method.See QuickFormatExample2.java in the examples directory for yet another bank statement printer, this one based on the QuickFormat class. In the example, the NumericPicture has been modified to use parentheses for negative balances, giving as output:
---------------------------------- | Credits | Debits | Balance | ---------------------------------- | 50.00 | | 50.00 | | | 4.95 | 45.05 | | | 49.99 | (4.94) | | | 8.50 | (13.44) | | 50.00 | | 36.56 | | | 37.50 | (0.94) | ----------------------------------
public QuickFormat(String pictureString)
public QuickFormat(String textPic,
String numericPic)
public QuickFormat arg(Formattable value)
public QuickFormat arg(int value)
public QuickFormat arg(Integer value)
public QuickFormat arg(long value)
public QuickFormat arg(Long value)
public QuickFormat arg(float value)
public QuickFormat arg(Float value)
public QuickFormat arg(double value)
public QuickFormat arg(Double value)
public QuickFormat arg(String value)
public QuickFormat arg(TextAlignment textalign)
public QuickFormat npic(String numericPic)
public QuickFormat nfmt(int width,
int precision)
public QuickFormat pre(int precision)
public void print(PrintStream ps)
public void println(PrintStream ps)
public String toString()
All Packages Class Hierarchy This Package Previous Next Index