Class CharEscaperBuilder


  • @Beta
    @GwtCompatible
    public final class CharEscaperBuilder
    extends java.lang.Object
    Simple helper class to build a "sparse" array of objects based on the indexes that were added to it. The array will be from 0 to the maximum index given. All non-set indexes will contain null (so it's not really a sparse array, just a pseudo sparse array). The builder can also return a CharEscaper based on the generated array.
    Since:
    15.0
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  CharEscaperBuilder.CharArrayDecorator
      Simple decorator that turns an array of replacement char[]s into a CharEscaper, this results in a very fast escape method.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.Character,​java.lang.String> map  
      private int max  
    • Constructor Summary

      Constructors 
      Constructor Description
      CharEscaperBuilder()
      Construct a new sparse array builder.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      CharEscaperBuilder addEscape​(char c, java.lang.String r)
      Add a new mapping from an index to an object to the escaping.
      CharEscaperBuilder addEscapes​(char[] cs, java.lang.String r)
      Add multiple mappings at once for a particular index.
      char[][] toArray()
      Convert this builder into an array of char[]s where the maximum index is the value of the highest character that has been seen.
      Escaper toEscaper()
      Convert this builder into a char escaper which is just a decorator around the underlying array of replacement char[]s.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • map

        private final java.util.Map<java.lang.Character,​java.lang.String> map
      • max

        private int max
    • Constructor Detail

      • CharEscaperBuilder

        public CharEscaperBuilder()
        Construct a new sparse array builder.
    • Method Detail

      • addEscape

        public CharEscaperBuilder addEscape​(char c,
                                            java.lang.String r)
        Add a new mapping from an index to an object to the escaping.
      • addEscapes

        public CharEscaperBuilder addEscapes​(char[] cs,
                                             java.lang.String r)
        Add multiple mappings at once for a particular index.
      • toArray

        public char[][] toArray()
        Convert this builder into an array of char[]s where the maximum index is the value of the highest character that has been seen. The array will be sparse in the sense that any unseen index will default to null.
        Returns:
        a "sparse" array that holds the replacement mappings.
      • toEscaper

        public Escaper toEscaper()
        Convert this builder into a char escaper which is just a decorator around the underlying array of replacement char[]s.
        Returns:
        an escaper that escapes based on the underlying array.