Class TranslatableWithContext


  • public class TranslatableWithContext
    extends Object

    Provides a specification for a list of texts to translate. This class is best suited for use cases where the input is naturally segmented and contains some segments with dynamic content (in other words, content that may change after it has been submitted to a BrailleTranslator or a BrailleFilter).

    This class has the following characteristics:

    • it applies to a list of text segments
    • style attributes apply to whole segments only
    • style attributes may span more than one instance of TranslatableWithContext
    • a segment can have a content size that is unknown when the translatable is created
    • it provides information about the context of the text segments to translate
    See Also:
    Translatable
    • Method Detail

      • from

        public static <T extends ResolvableTextTranslatableWithContext.Builder from​(List<T> list,
                                                                                      int index)

        Returns a new Translatable builder for this list. The current item is the specified index.

        Type Parameters:
        T - the type of items
        Parameters:
        list - the list
        index - the index of the current item
        Returns:
        a new context
        Throws:
        IndexOutOfBoundsException - for an illegal endpoint index value (fromIndex < 0 || toIndex > size || fromIndex > toIndex)
      • from

        public static <T extends ResolvableTextTranslatableWithContext.Builder from​(List<T> list,
                                                                                      int fromIndex,
                                                                                      int toIndex)

        Returns a new Translatable builder for this list. The current items are between the specified fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the current items list is empty, however this isn't useful in practice.)

        Type Parameters:
        T - the type of items
        Parameters:
        list - the list
        fromIndex - low endpoint (inclusive) of the current subList
        toIndex - high endpoint (exclusive) of the current subList
        Returns:
        a new context
        Throws:
        IndexOutOfBoundsException - for an illegal endpoint index value (fromIndex < 0 || toIndex > size || fromIndex > toIndex)
      • getPrecedingText

        public List<PrecedingText> getPrecedingText()
        Gets the text items in the context that preceded the current text. The preceding text may have been translated with the same translator, or it may have been translated with another translator.
        Returns:
        the preceding text items
      • getFollowingText

        public List<FollowingText> getFollowingText()
        Gets the text items in the context that follows the current text. The following text may be translated with the same translator, or it may be translated with another translator.
        Returns:
        the following text items
      • getTextToTranslate

        public List<ResolvableText> getTextToTranslate()
        Gets the text items to translate.
        Returns:
        the text to translate