| java.lang.Object java.text.Format org.openide.util.MapFormat
MapFormat | public class MapFormat extends Format (Code) | | A text format similar to MessageFormat
but using string rather than numeric keys.
You might use use this formatter like this:
MapFormat.format("Hello {name}", map);
Or to have more control over it:
Map m = new HashMap ();
m.put ("KEY", "value");
MapFormat f = new MapFormat (m);
f.setLeftBrace ("__");
f.setRightBrace ("__");
String result = f.format ("the __KEY__ here");
author: Slavek Psenicka See Also: MessageFormat |
Constructor Summary | |
public | MapFormat(Map arguments) Constructor. |
serialVersionUID | final static long serialVersionUID(Code) | | Array with to-be-skipped blocks
|
MapFormat | public MapFormat(Map arguments)(Code) | | Constructor.
For common work use format(pattern, arguments) .
Parameters: arguments - keys and values to use in the format |
format | public static String format(String pattern, Map arguments)(Code) | | Designated method. It gets the string, initializes HashFormat object
and returns converted string. It scans pattern
for {} brackets, then parses enclosed string and replaces it
with argument's get() value.
Parameters: pattern - String to be parsed. Parameters: arguments - Map with key-value pairs to replace. Formatted string |
format | public StringBuffer format(Object pat, StringBuffer result, FieldPosition fpos)(Code) | | Formats the parsed string by inserting table's values.
Parameters: pat - a string pattern Parameters: result - Buffer to be used for result. Parameters: fpos - position Formatted string |
getLeftBrace | public String getLeftBrace()(Code) | | Returns string used as left brace
|
getMap | public Map getMap()(Code) | | Returns argument map
|
getRightBrace | public String getRightBrace()(Code) | | Returns string used as right brace
|
isExactMatch | public boolean isExactMatch()(Code) | | Test whether both brackets are required in the expression.
If not, use setExactMatch(false) and formatter will ignore missing right
bracket. Advanced feature.
|
parse | public String parse(String source)(Code) | | Parses the string. Does not yet handle recursion (where
the substituted strings contain {n} references.)
New format. |
parseObject | public Object parseObject(String text, ParsePosition status)(Code) | | Parses the string. Does not yet handle recursion (where
the substituted strings contain %n references.)
|
processKey | protected Object processKey(String key)(Code) | | Returns the value for given key. Subclass may define its own beahvior of
this method. For example, if key is not defined, subclass can return
string.
Parameters: key - Key. Value for this key. |
processPattern | public String processPattern(String newPattern) throws IllegalArgumentException(Code) | | Scans the pattern and prepares internal variables.
Parameters: newPattern - String to be parsed. exception: IllegalArgumentException - if number of arguments exceeds BUFSIZE orparser found unmatched brackets (this exception should be switched offusing setExactMatch(false)). |
setExactMatch | public void setExactMatch(boolean flag)(Code) | | Specify whether both brackets are required in the expression.
If not, use setExactMatch(false) and formatter will ignore missing right
bracket. Advanced feature.
Parameters: flag - If true, formatter will ignore missing right bracket (default = false) |
setLeftBrace | public void setLeftBrace(String delimiter)(Code) | | Sets string used as left brace
Parameters: delimiter - Left brace. |
setMap | public void setMap(Map map)(Code) | | Sets argument map
This map should contain key-value pairs with key values used in
formatted string expression. If value for key was not found, formatter leave
key unchanged (except if you've set setThrowExceptionIfKeyWasNotFound(true),
then it fires IllegalArgumentException.
Parameters: map - the argument map |
setRightBrace | public void setRightBrace(String delimiter)(Code) | | Sets string used as right brace
Parameters: delimiter - Right brace. |
setThrowExceptionIfKeyWasNotFound | public void setThrowExceptionIfKeyWasNotFound(boolean flag)(Code) | | Specify whether formatter will throw exception if object for key was not found.
If given map does not contain object for key specified, it could
throw an exception. If does not throw, key is left unchanged.
Parameters: flag - If true, formatter throws IllegalArgumentException. |
willThrowExceptionIfKeyWasNotFound | public boolean willThrowExceptionIfKeyWasNotFound()(Code) | | Test whether formatter will throw exception if object for key was not found.
If given map does not contain object for key specified, it could
throw an exception. Returns true if throws. If not, key is left unchanged.
|
|
|