public class StringTranslator
extends java.lang.Object
Modifier and Type | Class | Description |
---|---|---|
static class |
StringTranslator.MatchMode |
Defines the mode to use when matching patterns in the StringTranslator.
|
Constructor | Description |
---|---|
StringTranslator() |
Creates a new Translator with match mode set to "greedy"
|
StringTranslator(StringTranslator.MatchMode mode) |
Creates a new Translator with the match mode set to the supplied value.
|
Modifier and Type | Method | Description |
---|---|---|
void |
addToken(java.lang.String token,
java.lang.String translation) |
Adds a token to the list of translations
|
StringTranslator.MatchMode |
getMatchMode() |
Gets the current match mode
|
int |
getTokenCount() |
Gets the number of tokens in the translator
|
void |
setMatchMode(StringTranslator.MatchMode mode) |
Sets the current match mode
|
java.lang.String |
translate(java.lang.String str) |
Translates the given string with the current match mode.
|
java.lang.String |
translate(java.lang.String str,
StringTranslator.MatchMode mode) |
Translates the given string with the specified match mode
|
public StringTranslator(StringTranslator.MatchMode mode)
mode
- the mode to usepublic StringTranslator()
public void addToken(java.lang.String token, java.lang.String translation)
token
- a token in the string to translatetranslation
- the translationjava.lang.IllegalArgumentException
- if the token is already in the listpublic StringTranslator.MatchMode getMatchMode()
public void setMatchMode(StringTranslator.MatchMode mode)
mode
- the mode to use in subsequent calls to translate()public int getTokenCount()
public java.lang.String translate(java.lang.String str, StringTranslator.MatchMode mode)
str
- the string to translatemode
- the mode to usejava.lang.IllegalArgumentException
- if the entire string could not be translatedpublic java.lang.String translate(java.lang.String str)
str
- the string to translatejava.lang.IllegalArgumentException
- if the entire string could not be translated