info.informatica.text.format
Class FormatPrinter

java.lang.Object
  extended by info.informatica.text.format.FormatPrinter

public class FormatPrinter
extends Object

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 m = new HashMap();
m.put("item", "15-inch monitor");
m.put("code", new Integer(11209));
m.put("price", new Double(234.92));
String formatted_output = fmt.format(m);

Author:
amengual at informatica dot info

Constructor Summary
FormatPrinter(String format)
           
FormatPrinter(String format, DecimalFormatSymbols symbols)
           
FormatPrinter(String format, DecimalFormatSymbols symbols, String nullStrText)
           
FormatPrinter(String format, String nullStrText)
           
 
Method Summary
 String format(Map<String,? extends Object> env)
          Prints the values in env according to format specifications.
 String format(Object[] array)
          Fast variant of the format method that sequentially prints the values in an array according to format specifications.
 String format(ResultSet env)
          Prints the values in env according to format specifications.
 DecimalFormatSymbols getDecimalFormatSymbols()
          Gets the decimal format symbols.
 Iterator<TemplateItem> getFormats()
           
 boolean hasArguments()
          Does this object have template arguments, or is a plain String?
 String sample()
           
 void setDecimalFormatSymbols(DecimalFormatSymbols symbols)
          Sets the decimal format symbols.
 String toString()
          Gives a String with the template items removed.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FormatPrinter

public FormatPrinter(String format)
              throws SpecParsingException
Throws:
SpecParsingException

FormatPrinter

public FormatPrinter(String format,
                     DecimalFormatSymbols symbols)
              throws SpecParsingException
Throws:
SpecParsingException

FormatPrinter

public FormatPrinter(String format,
                     String nullStrText)
              throws SpecParsingException
Parameters:
format - the format
nullStrText - The String that will substitute null values
Throws:
SpecParsingException

FormatPrinter

public FormatPrinter(String format,
                     DecimalFormatSymbols symbols,
                     String nullStrText)
              throws SpecParsingException
Parameters:
format - the format
nullStrText - The String that will substitute null values
Throws:
SpecParsingException
Method Detail

format

public String format(ResultSet env)
              throws SQLException
Prints the values in env according to format specifications.

Parameters:
env - The ResultSet used to retrieve the values
Returns:
a formatted String with the proper values printed on it
Throws:
SQLException

format

public String format(Map<String,? extends Object> env)
Prints the values in env according to format specifications.

Parameters:
env - The Map used to retrieve the values
Returns:
a formatted String with the proper values printed on it

format

public String format(Object[] array)
Fast variant of the format method that sequentially prints the values in an array according to format 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

public String sample()

getFormats

public Iterator<TemplateItem> getFormats()

hasArguments

public boolean hasArguments()
Does this object have template arguments, or is a plain String?

Returns:
true if this object has template arguments, or false if is a plain String.

setDecimalFormatSymbols

public void setDecimalFormatSymbols(DecimalFormatSymbols symbols)
Sets the decimal format symbols. The symbols are generally locale-dependent.

Parameters:
symbols - the new DecimalFormatSymbols

getDecimalFormatSymbols

public DecimalFormatSymbols getDecimalFormatSymbols()
Gets the decimal format symbols.

Returns:
the DecimalFormatSymbols

toString

public String toString()
Gives a String with the template items removed.

Overrides:
toString in class Object
Returns:
the static text part of the template.
See Also:
Object.toString()