Class ConditionalMapper


  • public class ConditionalMapper
    extends Object
    Provides a character mapper which is activated when a specific character is encountered. The mapping continues until the sequence is interrupted by a character that is not in the map.
    • Method Detail

      • withTrigger

        public static ConditionalMapper.Builder withTrigger​(char trigger)
        Creates a new builder with the specified trigger.
        Parameters:
        trigger - the trigger
        Returns:
        returns a new builder instance
      • withTrigger

        public static ConditionalMapper.Builder withTrigger​(int trigger)
        Creates a new builder with the specified trigger.
        Parameters:
        trigger - the trigger
        Returns:
        returns a new builder instance
      • translate

        public static String translate​(String input,
                                       String replace,
                                       String with)

        Replaces in the input string occurrences of characters listed in the replace string with the character at the corresponding position in the with string.

        This method is intentionally similar to the translate XPath function.

        For example, translate( "bar", "abc", "ABC") returns the string BAr.

        If there is a character in the replace string with no character at a corresponding position in the with string (because replace is longer than with), then occurrences of that character in the input are removed.

        For example, translate( "--aaa--", "abc-", "ABC") returns "AAA".

        If a character occurs more than once in the replace string, then the last occurrence determines the replacement character. This is unlike the translate XPath function, which does the opposite.

        If the with string is longer than the second argument string, then excess characters are ignored.

        Parameters:
        input - the input
        replace - a list of characters to replace
        with - a list of new characters
        Returns:
        returns the new string
      • replace

        public String replace​(String input)
        Replaces characters in the input according to the rules of this mapper.
        Parameters:
        input - the input
        Returns:
        returns the modified string