Class FormatPrinter

java.lang.Object
io.sf.jclf.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<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 Details

  • Constructor Details

  • Method Details

    • 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 - if an error occurs accessing the ResultSet.
    • 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()
    • addFormattedObject

      protected void addFormattedObject(StringBuilder sb, TemplateItem item, Object o)
    • 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: