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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionFormatPrinter(String format) FormatPrinter(String format, String nullStrText) FormatPrinter(String format, DecimalFormatSymbols symbols) FormatPrinter(String format, DecimalFormatSymbols symbols, String nullStrText) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddFormattedObject(StringBuilder sb, TemplateItem item, Object o) Fast variant of theformatmethod that sequentially prints the values in anarrayaccording toformatspecifications.Prints the values inenvaccording toformatspecifications.Prints the values inenvaccording toformatspecifications.Gets the decimal format symbols.booleanDoes this object have template arguments, or is a plain String?sample()voidSets 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 inenvaccording toformatspecifications.- 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 inenvaccording toformatspecifications.- Parameters:
env- The Map used to retrieve the values- Returns:
- a formatted String with the proper values printed on it
-
format
Fast variant of theformatmethod that sequentially prints the values in anarrayaccording toformatspecifications.- 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:
trueif this object has template arguments, orfalseif 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.
-