Package overit.geocall.util
Class MapFormat
java.lang.Object
overit.geocall.util.MapFormat
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
PathFormat
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:
To use different string in output based on the input value, you must use this format:
where in braces you can use these format:
Here is an example: starting from this format string
creating the MapFormat in this way
and calling the method
we obtain these results, varying the content of the maps:
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".
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:
| 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:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidcalcTokens(String format) Formats the List passed as parametrer to produce a stringFormats the Map passed as parametrer to produce a stringvoidsetFieldPos(Map fieldPos) Sets the field positions starting from the Map passed as parametervoidsetFieldPos(DBView dbv) Sets the field positions starting from theDBViewpassed as parameter
-
Field Details
-
_format
-
_tokens
-
_teacherDuty
-
-
Constructor Details
-
MapFormat
Creates a new MapFormat starting from the string passed as parameter- Parameters:
format- The string that defines the format
-
MapFormat
Creates a new MapFormat starting from the string passed as parameter and sets theTeacherfor the translations- Parameters:
format- The string that defines the formatteacher- TheTeacherthat will manage the translations
-
-
Method Details
-
calcTokens
-
format
Formats the Map passed as parametrer to produce a string- Parameters:
m- The map of objects to format- Returns:
- A formatted string
-
setFieldPos
Sets the field positions starting from the Map passed as parameter- Parameters:
fieldPos- The Map used to sets the field positions
-
setFieldPos
Sets the field positions starting from theDBViewpassed as parameter- Parameters:
dbv- TheDBViewused to sets the field positions
-
format
Formats the List passed as parametrer to produce a string- Parameters:
al- The List of objects to format- Returns:
- A formatted string
-