java.lang.Object
io.sf.jclf.text.format.FormatPrinter
Text formatting parser and printer.
This formatter emulates (not at 100%) the behavior of popular
printf
C function, adding a few extensions.
Instead of a varargs-style argument as in C, it uses a name-value Map.
Synopsis:
FormatPrinter fmt = new FormatPrinter("Cost of item number ${code,7.1d} ("${item,-40.50s}) is ${price,8.2f}.");
Map<String,Object> m = new HashMap<String,Object>();
m.put("item", "15-inch monitor");
m.put("code", Integer.valueOf(11209));
m.put("price", new Double(234.92));
String formatted_output = fmt.format(m);
-
Field Summary
-
Constructor Summary
ConstructorDescriptionFormatPrinter
(String format) FormatPrinter
(String format, String nullStrText) FormatPrinter
(String format, DecimalFormatSymbols symbols) FormatPrinter
(String format, DecimalFormatSymbols symbols, String nullStrText) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addFormattedObject
(StringBuilder sb, TemplateItem item, Object o) Fast variant of theformat
method that sequentially prints the values in anarray
according toformat
specifications.Prints the values inenv
according toformat
specifications.Prints the values inenv
according toformat
specifications.Gets the decimal format symbols.boolean
Does this object have template arguments, or is a plain String?sample()
void
Sets the decimal format symbols.toString()
Gives a String with the template items removed.
-
Field Details
-
formato
-
items
-
-
Constructor Details
-
FormatPrinter
- Throws:
SpecParsingException
-
FormatPrinter
- Throws:
SpecParsingException
-
FormatPrinter
- Parameters:
format
- the format template.nullStrText
- The String that will replace null values.- Throws:
SpecParsingException
- if a malformed template was supplied.
-
FormatPrinter
public FormatPrinter(String format, DecimalFormatSymbols symbols, String nullStrText) throws SpecParsingException - Parameters:
format
- the format template.symbols
- the DecimalFormatSymbols object used to format numbers.nullStrText
- The String that will replace null values.- Throws:
SpecParsingException
- if a malformed template was supplied.
-
-
Method Details
-
format
Prints the values inenv
according toformat
specifications.- Parameters:
env
- The ResultSet used to retrieve the values- Returns:
- a formatted String with the proper values printed on it
- Throws:
SQLException
- if an error occurs accessing the ResultSet.
-
format
Prints the values inenv
according toformat
specifications.- Parameters:
env
- The Map used to retrieve the values- Returns:
- a formatted String with the proper values printed on it
-
format
Fast variant of theformat
method that sequentially prints the values in anarray
according toformat
specifications.- Parameters:
array
- The array containing the values as found in the format.- Returns:
- a formatted String with the proper values printed on it.
-
sample
-
addFormattedObject
-
getFormats
-
hasArguments
public boolean hasArguments()Does this object have template arguments, or is a plain String?- Returns:
true
if this object has template arguments, orfalse
if is a plain String.
-
setDecimalFormatSymbols
Sets the decimal format symbols. The symbols are generally locale-dependent.- Parameters:
symbols
- the new DecimalFormatSymbols
-
getDecimalFormatSymbols
Gets the decimal format symbols.- Returns:
- the DecimalFormatSymbols
-
toString
Gives a String with the template items removed.
-