Class LookupTranslator

java.lang.Object
org.apache.commons.text.translate.CharSequenceTranslator
org.apache.commons.text.translate.LookupTranslator

public class LookupTranslator
extends CharSequenceTranslator
Translates a value using a lookup table.
Since:
1.0
  • Constructor Details

    • LookupTranslator

      public LookupTranslator​(Map<CharSequence,​CharSequence> lookupMap)
      Define the lookup table to be used in translation Note that, as of Lang 3.1 (the origin of this code), the key to the lookup table is converted to a java.lang.String. This is because we need the key to support hashCode and equals(Object), allowing it to be the key for a HashMap. See LANG-882.
      Parameters:
      lookupMap - Map<CharSequence, CharSequence> table of translator mappings
  • Method Details

    • translate

      public int translate​(CharSequence input, int index, Writer out) throws IOException
      Translate a set of codepoints, represented by an int index into a CharSequence, into another set of codepoints. The number of codepoints consumed must be returned, and the only IOExceptions thrown must be from interacting with the Writer so that the top level API may reliably ignore StringWriter IOExceptions.
      Specified by:
      translate in class CharSequenceTranslator
      Parameters:
      input - CharSequence that is being translated
      index - int representing the current point of translation
      out - Writer to translate the text to
      Returns:
      int count of codepoints consumed
      Throws:
      IOException - if and only if the Writer produces an IOException