|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.util.formatter.LookupFormatter<T>
public class LookupFormatter<T>
A formatter implementation that uses a map to lookup values from a set of keys. A default value may be specified that is returned in case no lookup has been defined for a given key.
Field Summary | |
---|---|
private String |
defaultValue
|
private Map<T,String> |
map
|
Constructor Summary | |
---|---|
LookupFormatter()
Create a new lookup formatter |
|
LookupFormatter(Enumeration<? extends T,? extends String> in)
Create a new lookup formatter and initialise it with the key-value pairs in the given enumeration. |
|
LookupFormatter(Map<? extends T,? extends String> in)
Create a new lookup formatter and initialise it with the key-value pairs in the given map. |
Method Summary | |
---|---|
void |
clear()
Remove all registered lookup entries. |
boolean |
containsKey(Object key)
Checks if a given key has been registered. |
String |
format(T key)
Format a value by converting it to a string. |
String |
get(Object key)
Get registered lookup value for a given key |
String |
getDefaultValue()
Get the default value. |
boolean |
isEmpty()
Checks if the lookup map is empty or not. |
T |
parseString(String value)
Parse a string and return a value of the correct type. |
void |
put(T key,
String value)
Add a lookup key/value pair. |
void |
putAll(Enumeration<? extends T,? extends String> in)
Copy multiple lookup key/value pairs from an enumeration. |
void |
putAll(Map<? extends T,? extends String> in)
Copy multiple lookup key/value pairs from a map |
String |
remove(Object key)
Remove an entry from the lookup map. |
void |
setDefaultValue(String defaultValue)
Set a default value that is returned by the format(Object)
method in case no lookup has been specified for a key. |
int |
size()
Get the number of registered lookup entries. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final Map<T,String> map
private String defaultValue
Constructor Detail |
---|
public LookupFormatter()
public LookupFormatter(Map<? extends T,? extends String> in)
in
- A map object or nullpublic LookupFormatter(Enumeration<? extends T,? extends String> in)
in
- An enumeration object or nullMethod Detail |
---|
public String format(T key)
Formatter
format
in interface Formatter<T>
key
- The value to format
public T parseString(String value)
Formatter
parseString
in interface Formatter<T>
value
- The string to parse
public void setDefaultValue(String defaultValue)
format(Object)
method in case no lookup has been specified for a key.
public String getDefaultValue()
public void put(T key, String value)
key
- The keyvalue
- The value that is returned as the lookup value for the given keypublic void putAll(Map<? extends T,? extends String> in)
in
- The map to copy key/value pair frompublic void putAll(Enumeration<? extends T,? extends String> in)
in
- The enumeration to copy key/value pair frompublic boolean containsKey(Object key)
key
- The key
public String get(Object key)
key
- The key
public int size()
public boolean isEmpty()
public void clear()
public String remove(Object key)
key
- The key
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |