net.eduvax.util
public abstract class AStaticTranslator<T,U> extends java.lang.Object implements Translator<T,U>
Modifier and Type | Field and Description |
---|---|
private U |
_nullValue
Default value.
|
private java.util.Hashtable<T,U> |
_table
Convertion map
|
Constructor and Description |
---|
AStaticTranslator(U nullVal)
Create new static translator.
|
Modifier and Type | Method and Description |
---|---|
void |
fillTable(java.lang.String tblText,
ErrorHandler eh)
Fill table using a string definition.
|
protected abstract T |
sourceTypeFromString(java.lang.String str)
String to key convertion.
|
protected abstract U |
targetTypeFromString(java.lang.String str)
String to value convertion.
|
U |
translate(T toTranslate)
Convert T to U.
|
private U _nullValue
public AStaticTranslator(U nullVal)
nullVal
- default value to return in response of unknown
entry.protected abstract T sourceTypeFromString(java.lang.String str) throws java.lang.Exception
str
- string to convert.java.lang.Exception
protected abstract U targetTypeFromString(java.lang.String str) throws java.lang.Exception
str
- string to convert.java.lang.Exception
public void fillTable(java.lang.String tblText, ErrorHandler eh)
tblText
- Table textual description. Each table entry is
written as : source=target, separated with ';' char. Tab and
carriage return are ignored. Example
1=One; 2=Two; 3=Three; 4=Four; 5=Five
eh
- error handler to use in case of exception while
converting elements to U and T type.public U translate(T toTranslate)
Translator
translate
in interface Translator<T,U>
toTranslate
- the thing to be converted