Package overit.geocall.util
Class TextFormat
java.lang.Object
java.text.Format
overit.geocall.util.TextFormat
- All Implemented Interfaces:
Serializable,Cloneable
The class is an extension of
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:
To use different string in output based on the input value, you must use this format:
where in braces you can use these format:
The example format:
obtain these results, varying the content of the variables:
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".
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:
"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:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class java.text.Format
Format.Field -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTextFormat(String format) Creates a TextFormat starting from a format stringTextFormat(String format, Teacher t) Creates a TextFormat starting from a format string that will be translated by theTeacher -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyPattern(String format) Sets again the pattern with the new one passed as parameterFormats the List to produce a stringformat(Object o, StringBuffer result, FieldPosition ignore) Public utility function that must not be explicitly used.Formats the List to produce a stringparseObject(String source, ParsePosition status) Not implementedExtracts the pattern of the objectprotected StringMethods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
-
Field Details
-
tokens
-
-
Constructor Details
-
TextFormat
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
Creates a TextFormat starting from a format string that will be translated by theTeacher- 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 (seeTeacher)
-
-
Method Details
-
applyPattern
Sets again the pattern with the new one passed as parameter- Parameters:
format- The new pattern string
-
format
Formats the List to produce a string- Parameters:
l- The list of objects to format- Returns:
- A formatted string
-
format
Formats the List to produce a string- Parameters:
oo- The objects to format- Returns:
- A formatted string
-
format
Public utility function that must not be explicitly used. UseFormat.format(java.lang.Object) -
toPattern
Extracts the pattern of the object- Returns:
- The string that represents the pattern of the object
-
toPattern
-
parseObject
Not implemented- Specified by:
parseObjectin classFormat- Parameters:
source- Not implementedstatus- Not implemented- Returns:
null
-