Class TextHelper


  • public final class TextHelper
    extends java.lang.Object

    This class provides various helper function related to text processing.

    The application code should not use this class directly.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String LINESEP  
      static java.util.Locale LOCALE_ROOT
      Language neutral locale.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private TextHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.StringBuilder adjustSpace​(java.lang.StringBuilder sb, int width, int curWidth)
      Given the maximum line width and current line width in sb, insert white spaces in sb to make it look more "natural".
      static <T> java.lang.String concat​(java.util.Collection<T> a, int offset, java.lang.String sep)  
      static <T> java.lang.String concat​(java.util.Collection<T> a, int offset, java.lang.String sep, java.lang.String start, java.lang.String end)  
      static <T> java.lang.String concat​(T[] a, int offset, java.lang.String sep)  
      static <T> java.lang.String concat​(T[] a, int offset, java.lang.String sep, java.lang.String start, java.lang.String end)  
      static java.util.List<java.lang.String> findPrefix​(java.util.Collection<java.lang.String> src, java.lang.String prefix)
      From src, find string whose prefix is prefix and store them in List and return it.
      static java.lang.String nonNull​(java.lang.String str)  
      static void printHelp​(java.io.PrintWriter writer, java.lang.String title, java.lang.String help, TextWidthCounter textWidthCounter, int width)  
      static java.lang.String wrap​(TextWidthCounter textWidthCounter, java.lang.String s, int width, int initialOffset, java.lang.String initialIndent, java.lang.String subsequentIndent)  
      • Methods inherited from class java.lang.Object

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

      • LOCALE_ROOT

        public static final java.util.Locale LOCALE_ROOT
        Language neutral locale.
      • LINESEP

        public static final java.lang.String LINESEP
    • Constructor Detail

      • TextHelper

        private TextHelper()
    • Method Detail

      • concat

        public static <T> java.lang.String concat​(T[] a,
                                                  int offset,
                                                  java.lang.String sep,
                                                  java.lang.String start,
                                                  java.lang.String end)
      • concat

        public static <T> java.lang.String concat​(T[] a,
                                                  int offset,
                                                  java.lang.String sep)
      • concat

        public static <T> java.lang.String concat​(java.util.Collection<T> a,
                                                  int offset,
                                                  java.lang.String sep,
                                                  java.lang.String start,
                                                  java.lang.String end)
      • concat

        public static <T> java.lang.String concat​(java.util.Collection<T> a,
                                                  int offset,
                                                  java.lang.String sep)
      • wrap

        public static java.lang.String wrap​(TextWidthCounter textWidthCounter,
                                            java.lang.String s,
                                            int width,
                                            int initialOffset,
                                            java.lang.String initialIndent,
                                            java.lang.String subsequentIndent)
      • adjustSpace

        public static java.lang.StringBuilder adjustSpace​(java.lang.StringBuilder sb,
                                                          int width,
                                                          int curWidth)
        Given the maximum line width and current line width in sb, insert white spaces in sb to make it look more "natural". The insertion points are the contiguous block of white spaces. Before the processing, leading and trailing white spaces are removed from sb.
        Parameters:
        sb - String to adjust
        width - maximum line width
        curWidth - current line width
        Returns:
        adjusted sb
      • printHelp

        public static void printHelp​(java.io.PrintWriter writer,
                                     java.lang.String title,
                                     java.lang.String help,
                                     TextWidthCounter textWidthCounter,
                                     int width)
      • nonNull

        public static java.lang.String nonNull​(java.lang.String str)
      • findPrefix

        public static java.util.List<java.lang.String> findPrefix​(java.util.Collection<java.lang.String> src,
                                                                  java.lang.String prefix)
        From src, find string whose prefix is prefix and store them in List and return it.
        Parameters:
        src - collection contains strings to inspect
        prefix - prefix
        Returns:
        List of strings matched