Class TextFormat

java.lang.Object
java.text.Format
overit.geocall.util.TextFormat
All Implemented Interfaces:
Serializable, Cloneable

public class TextFormat extends Format implements Serializable
The class is an extension of Format that allows to manage null variable cases, variable prefixes and suffixes, and switches on the toString() of variables.
When setting the format, an array of objects containing the values is passed. These values are referenced within the format string with their index.
To use the value in input as value in output, you must use this format:
"{index}"

To use different string in output based on the input value, you must use this format:
"{index{}...{}}"
where in braces you can use these format:
  • rule with a specific string: "string";
  • rule with a suffix to value: "| suffix";
  • rule with a prefix to value: "prefix |";
  • transformation of a specific string based on the specific value: "value||string in output".
Pay attention: the first time using a rule indicates the case in whitch the value is null. The second time using a rule indicates a combination rule that can be also a placeholder, in case the value isn't among the other transformations.

The example format:
"[{0{Someone has filled}{| has filled}{P||Jane Doe has filled}{L||Baby Doe has filled}} the bath tub{1{}{ of |}}]"
obtain these results, varying the content of the variables:

Examples
"John Doe","water"[John Doe has filled the bath tub of water]
null,"water"[Someone has filled the bath tub of water]
"John Doe",null[John Doe has filled the bath tub]
"P","water"[Jane Doe has filled the bath tub of water]
"L"[Baby Doe has filled the bath tub]
See Also:
  • Field Details

  • Constructor Details

    • TextFormat

      public TextFormat(String format)
      Creates a TextFormat starting from a format string
      Parameters:
      format - The format string, for example:
      "[{0{Someone has filled}{| has filled}{P||Jane Doe has filled}{L||Baby Doe has filled}} the bath tub{1{}{ of |}}]"
    • TextFormat

      public TextFormat(String format, Teacher t)
      Creates a TextFormat starting from a format string that will be translated by the Teacher
      Parameters:
      format - The format string, for example:
      "[{0{Someone has filled}{| has filled}{P||Jane Doe has filled}{L||Baby Doe has filled}} the bath tub{1{}{ of |}}]"
      t - The component that manage the translations (see Teacher)
  • Method Details

    • applyPattern

      public void applyPattern(String format)
      Sets again the pattern with the new one passed as parameter
      Parameters:
      format - The new pattern string
    • format

      public String format(List l)
      Formats the List to produce a string
      Parameters:
      l - The list of objects to format
      Returns:
      A formatted string
    • format

      public String format(Object... oo)
      Formats the List to produce a string
      Parameters:
      oo - The objects to format
      Returns:
      A formatted string
    • format

      public StringBuffer format(Object o, StringBuffer result, FieldPosition ignore)
      Public utility function that must not be explicitly used. Use Format.format(java.lang.Object)
      Specified by:
      format in class Format
      Parameters:
      o - An array of objects to be formatted and substituted
      result - Where text is appended
      ignore - Input: an alignment field, if desired; output: the offsets of the alignment field
      Returns:
      The StringBuffer that contains the result of the format
    • toPattern

      public String toPattern()
      Extracts the pattern of the object
      Returns:
      The string that represents the pattern of the object
    • toPattern

      protected String toPattern(Object[] oo)
    • parseObject

      public Object parseObject(String source, ParsePosition status)
      Not implemented
      Specified by:
      parseObject in class Format
      Parameters:
      source - Not implemented
      status - Not implemented
      Returns:
      null