| 
org.openide.util 6.8.22 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.text.Format
org.openide.util.MapFormat
public class MapFormat
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");
 
MessageFormat, 
Serialized Form| Nested Class Summary | 
|---|
| Nested classes/interfaces inherited from class java.text.Format | 
|---|
Format.Field | 
| Constructor Summary | |
|---|---|
MapFormat(Map arguments)
Constructor.  | 
|
| Method Summary | |
|---|---|
 StringBuffer | 
format(Object pat,
       StringBuffer result,
       FieldPosition fpos)
Formats the parsed string by inserting table's values.  | 
static String | 
format(String pattern,
       Map arguments)
Designated method.  | 
 String | 
getLeftBrace()
Returns string used as left brace  | 
 Map | 
getMap()
Returns argument map  | 
 String | 
getRightBrace()
Returns string used as right brace  | 
 boolean | 
isExactMatch()
Test whether both brackets are required in the expression.  | 
 String | 
parse(String source)
Parses the string.  | 
 Object | 
parseObject(String text,
            ParsePosition status)
Parses the string.  | 
protected  Object | 
processKey(String key)
Returns the value for given key.  | 
 String | 
processPattern(String newPattern)
Scans the pattern and prepares internal variables.  | 
 void | 
setExactMatch(boolean flag)
Specify whether both brackets are required in the expression.  | 
 void | 
setLeftBrace(String delimiter)
Sets string used as left brace  | 
 void | 
setMap(Map map)
Sets argument map This map should contain key-value pairs with key values used in formatted string expression.  | 
 void | 
setRightBrace(String delimiter)
Sets string used as right brace  | 
 void | 
setThrowExceptionIfKeyWasNotFound(boolean flag)
Specify whether formatter will throw exception if object for key was not found.  | 
 boolean | 
willThrowExceptionIfKeyWasNotFound()
Test whether formatter will throw exception if object for key was not found.  | 
| Methods inherited from class java.text.Format | 
|---|
clone, format, formatToCharacterIterator, parseObject | 
| Methods inherited from class java.lang.Object | 
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
|---|
public MapFormat(Map arguments)
format(pattern, arguments) .
arguments - keys and values to use in the format| Method Detail | 
|---|
public static String format(String pattern, Map arguments)
pattern
 for {} brackets, then parses enclosed string and replaces it
 with argument's  get() value.
pattern - String to be parsed.arguments - Map with key-value pairs to replace.
protected Object processKey(String key)
key - Key.
public String processPattern(String newPattern) throws IllegalArgumentException
newPattern - String to be parsed.
IllegalArgumentException - if number of arguments exceeds BUFSIZE or
 parser found unmatched brackets (this exception should be switched off
 using setExactMatch(false)).public StringBuffer format(Object pat, StringBuffer result, FieldPosition fpos)
pat - a string patternresult - Buffer to be used for result.fpos - position
public Object parseObject(String text, ParsePosition status)
parseObject in class Formatpublic String parse(String source)
public boolean willThrowExceptionIfKeyWasNotFound()
public void setThrowExceptionIfKeyWasNotFound(boolean flag)
flag - If true, formatter throws IllegalArgumentException.public boolean isExactMatch()
public void setExactMatch(boolean flag)
flag - If true, formatter will ignore missing right bracket (default = false)public String getLeftBrace()
public void setLeftBrace(String delimiter)
delimiter - Left brace.public String getRightBrace()
public void setRightBrace(String delimiter)
delimiter - Right brace.public Map getMap()
public void setMap(Map map)
map - the argument map
  | 
org.openide.util 6.8.22 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||