public class LookupFormatter<T> extends java.lang.Object implements Formatter<T>
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
defaultValue |
private java.util.Map<T,java.lang.String> |
map |
Constructor and Description |
---|
LookupFormatter()
Create a new lookup formatter
|
LookupFormatter(Enumeration<? extends T,? extends java.lang.String> in)
Create a new lookup formatter and initialise it with
the key-value pairs in the given enumeration.
|
LookupFormatter(java.util.Map<? extends T,? extends java.lang.String> in)
Create a new lookup formatter and initialise it with
the key-value pairs in the given map.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Remove all registered lookup entries.
|
boolean |
containsKey(java.lang.Object key)
Checks if a given key has been registered.
|
java.lang.String |
format(T key)
Format a value by converting it to a string.
|
java.lang.String |
get(java.lang.Object key)
Get registered lookup value for a given key
|
java.lang.String |
getDefaultValue()
Get the default value.
|
boolean |
isEmpty()
Checks if the lookup map is empty or not.
|
T |
parseString(java.lang.String value)
Parse a string and return a value of the correct type.
|
void |
put(T key,
java.lang.String value)
Add a lookup key/value pair.
|
void |
putAll(Enumeration<? extends T,? extends java.lang.String> in)
Copy multiple lookup key/value pairs from an enumeration.
|
void |
putAll(java.util.Map<? extends T,? extends java.lang.String> in)
Copy multiple lookup key/value pairs from a map
|
java.lang.String |
remove(java.lang.Object key)
Remove an entry from the lookup map.
|
void |
setDefaultValue(java.lang.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.
|
private final java.util.Map<T,java.lang.String> map
private java.lang.String defaultValue
public LookupFormatter()
public LookupFormatter(java.util.Map<? extends T,? extends java.lang.String> in)
in
- A map object or nullpublic LookupFormatter(Enumeration<? extends T,? extends java.lang.String> in)
in
- An enumeration object or nullpublic java.lang.String format(T key)
Formatter
public T parseString(java.lang.String value)
Formatter
parseString
in interface Formatter<T>
value
- The string to parsepublic void setDefaultValue(java.lang.String defaultValue)
format(Object)
method in case no lookup has been specified for a key.public java.lang.String getDefaultValue()
public void put(T key, java.lang.String value)
key
- The keyvalue
- The value that is returned as the lookup value for the given keypublic void putAll(java.util.Map<? extends T,? extends java.lang.String> in)
in
- The map to copy key/value pair frompublic void putAll(Enumeration<? extends T,? extends java.lang.String> in)
in
- The enumeration to copy key/value pair frompublic boolean containsKey(java.lang.Object key)
key
- The keypublic java.lang.String get(java.lang.Object key)
key
- The keypublic int size()
public boolean isEmpty()
public void clear()
public java.lang.String remove(java.lang.Object key)
key
- The key