Top Description Fields Constructors Methods
org.apache.commons.text.translate

public Class LookupTranslator

extends CharSequenceTranslator
Class Inheritance
Imports
java.io.IOException, .Writer, java.util.BitSet, .HashMap, .Map, .Objects

Translates a value using a lookup table.
Since
1.0

Field Summary

Modifier and TypeField and Description
private final int
longest

The length of the longest key in the lookupMap.

private final Map<String, String>
lookupMap

The mapping to be used in translation.

private final BitSet
prefixSet

The first character of each key in the lookupMap.

private final int
shortest

The length of the shortest key in the lookupMap.

Inherited from org.apache.commons.text.translate.CharSequenceTranslator:
HEX_DIGITS

Constructor Summary

AccessConstructor and Description
public
LookupTranslator(final Map<CharSequence, CharSequence>
Map<CharSequence, CharSequence> table of translator mappings, may not be null.
lookupMap
)

Constructs the lookup table to be used in translation.

Method Summary

Modifier and TypeMethod and Description
public int
translate(final CharSequence input, final int index, final Writer writer)

Implements abstract org.apache.commons.text.translate.CharSequenceTranslator.translate.

Translate a set of code points, represented by an int index into a CharSequence, into another set of code points.

Inherited from org.apache.commons.text.translate.CharSequenceTranslator:
hextranslatetranslatewith

Field Detail

longestback to summary
private final int longest

The length of the longest key in the lookupMap.

lookupMapback to summary
private final Map<String, String> lookupMap

The mapping to be used in translation.

prefixSetback to summary
private final BitSet prefixSet

The first character of each key in the lookupMap.

shortestback to summary
private final int shortest

The length of the shortest key in the lookupMap.

Constructor Detail

LookupTranslatorback to summary
public LookupTranslator(final Map<CharSequence, CharSequence> lookupMap)

Constructs 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 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>

Map<CharSequence, CharSequence> table of translator mappings, may not be null.

Method Detail

translateback to summary
public int translate(final CharSequence input, final int index, final Writer writer) throws IOException

Implements abstract org.apache.commons.text.translate.CharSequenceTranslator.translate.

Doc from org.apache.commons.text.translate.CharSequenceTranslator.translate.

Translate a set of code points, represented by an int index into a CharSequence, into another set of code points. The number of code points 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.

Annotations
@Override
Exceptions
IOException:
if and only if the Writer produces an IOException.