Class StringTranslator


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

      • 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 Detail

      • addToken

        public void addToken​(java.lang.String token,
                             java.lang.String translation)
        Adds a token to the list of translations
        Parameters:
        token - a token in the string to translate
        translation - the translation
        Throws:
        java.lang.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 java.lang.String translate​(java.lang.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:
        java.lang.IllegalArgumentException - if the entire string could not be translated
      • translate

        public java.lang.String translate​(java.lang.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:
        java.lang.IllegalArgumentException - if the entire string could not be translated