Class StringTranslator

java.lang.Object
org.daisy.braille.tools.StringTranslator

public class StringTranslator extends Object
Provides a string to string translator.
Author:
Joel HÃ¥kansson
  • Constructor Details

    • StringTranslator

      public StringTranslator(StringTranslator.MatchMode mode)
      Creates a new Translator with the match mode set to the supplied value.
      Parameters:
      mode - the mode to use
    • StringTranslator

      public StringTranslator()
      Creates a new Translator with match mode set to "greedy"
  • Method Details

    • addToken

      public void addToken(String token, String translation)
      Adds a token to the list of translations
      Parameters:
      token - a token in the string to translate
      translation - the translation
      Throws:
      IllegalArgumentException - if the token is already in the list
    • getMatchMode

      public StringTranslator.MatchMode getMatchMode()
      Gets the current match mode
      Returns:
      returns the current match mode
    • setMatchMode

      public void setMatchMode(StringTranslator.MatchMode mode)
      Sets the current match mode
      Parameters:
      mode - the mode to use in subsequent calls to translate()
    • getTokenCount

      public int getTokenCount()
      Gets the number of tokens in the translator
      Returns:
      returns the number of tokens
    • translate

      public String translate(String str, StringTranslator.MatchMode mode)
      Translates the given string with the specified match mode
      Parameters:
      str - the string to translate
      mode - the mode to use
      Returns:
      returns the translated string
      Throws:
      IllegalArgumentException - if the entire string could not be translated
    • translate

      public String translate(String str)
      Translates the given string with the current match mode. The whole string must be translatable, or the operation will fail.
      Parameters:
      str - the string to translate
      Returns:
      returns the translated string
      Throws:
      IllegalArgumentException - if the entire string could not be translated