Class MapFormat

java.lang.Object
overit.geocall.util.MapFormat
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
PathFormat

public class MapFormat extends Object implements Serializable
The class is used to obtain a string starting from a format and a map (or a list) of fields from which extract the values that will fill the string.
These values are referenced within the format string with their key. To use the value in input as value in output, you must use this format:
"{KEY}"

To use different string in output based on the input value, you must use this format:
"{KEY{}...{}}"
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.

Here is an example: starting from this format string
String s="[{NAME{It has been filled}{| has filled}{P||John has filled}{L||Jane has filled}} the bath tub{MAT{}{ of |}}]";

creating the MapFormat in this way

MapFormat mf = new MapFormat(s,null);

and calling the method

mf.format(o);

we obtain these results, varying the content of the maps:

Examples
HashGetter o=new HashGetter(new Object[]{"NAME","Mike","MAT","water"});Mike has filled the bath tub of water
HashGetter o=new HashGetter(new Object[]{"NAME",null,"MAT","water"});It has been filled the bath tub of water
HashGetter o=new HashGetter(new Object[]{"NAME","Mike","MAT",null});Mike has filled the bath tub
HashGetter o=new HashGetter(new Object[]{"NAME","P","MAT","water"});John has filled the bath tub of water
HashGetter o=new HashGetter(new Object[]{"NAME","L"}); Jane has filled the bath tub
See Also:
  • Field Details

  • Constructor Details

    • MapFormat

      public MapFormat(String format)
      Creates a new MapFormat starting from the string passed as parameter
      Parameters:
      format - The string that defines the format
    • MapFormat

      public MapFormat(String format, Teacher teacher)
      Creates a new MapFormat starting from the string passed as parameter and sets the Teacher for the translations
      Parameters:
      format - The string that defines the format
      teacher - The Teacher that will manage the translations
  • Method Details

    • calcTokens

      protected final void calcTokens(String format)
    • format

      public String format(Map m)
      Formats the Map passed as parametrer to produce a string
      Parameters:
      m - The map of objects to format
      Returns:
      A formatted string
    • setFieldPos

      public void setFieldPos(Map fieldPos)
      Sets the field positions starting from the Map passed as parameter
      Parameters:
      fieldPos - The Map used to sets the field positions
    • setFieldPos

      public void setFieldPos(DBView dbv)
      Sets the field positions starting from the DBView passed as parameter
      Parameters:
      dbv - The DBView used to sets the field positions
    • format

      public String format(List al)
      Formats the List passed as parametrer to produce a string
      Parameters:
      al - The List of objects to format
      Returns:
      A formatted string