Class Strings


  • public class Strings
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String[] EMPTY_ARRAY  
      static char SEPARATOR  
    • Constructor Summary

      Constructors 
      Constructor Description
      Strings()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String concat​(java.lang.String separator, java.util.List<java.lang.String> list)  
      static java.lang.String concat​(java.lang.String separator, java.util.List<java.lang.String> list, int skip)  
      static java.lang.String convertFromJavaString​(java.lang.String string, boolean useUnicode)
      Resolve Java control character sequences with to the actual character value.
      static java.lang.String convertToJavaString​(java.lang.String theString)
      Escapes control characters with a preceding backslash.
      static java.lang.String convertToJavaString​(java.lang.String input, boolean useUnicode)
      Escapes control characters with a preceding backslash.
      static int countLineBreaks​(java.lang.CharSequence text)
      Counts the number of line breaks.
      static int countLineBreaks​(java.lang.CharSequence text, int startInclusive, int endExclusive)
      Counts the number of line breaks.
      static int countLines​(java.lang.String text)
      Counts the number of lines where separator is assumed to be the only valid line break sequence.
      static int countLines​(java.lang.String text, char[] separator)
      Counts the number of lines where the given separator sequence is the only valid line break sequence.
      static int countLines​(java.lang.String text, char[] separator, int startInclusive, int endExclusive)
      Counts the number of lines between startInclusive and endExclusive where the given separator sequence is the only valid line break sequence.
      static java.lang.String emptyIfNull​(java.lang.String s)  
      static boolean equal​(java.lang.String literal, java.lang.String name)  
      static boolean equalsIgnoreWhitespace​(java.lang.String left, java.lang.String right)  
      static java.lang.String getLeadingWhiteSpace​(java.lang.String original)  
      static int getLevenshteinDistance​(java.lang.String from, java.lang.String to)
      Calculates the Levenshtein text edit distance copied & adapted (cost = 1) from org.eclipse.jdt.internal.ui.text.spelling.engine.DefaultPhoneticDistanceAlgorithm
      static boolean isEmpty​(java.lang.String s)  
      static java.lang.String lastToken​(java.lang.String value, java.lang.String separator)  
      static java.lang.String newLine()  
      static java.lang.String notNull​(java.lang.Object o)  
      static java.lang.String pack​(java.lang.String[] strings)  
      static java.lang.String removeLeadingWhitespace​(java.lang.String indentationString)  
      static java.lang.String skipLastToken​(java.lang.String value, java.lang.String separator)  
      static java.util.List<java.lang.String> split​(java.lang.String value, char delimiter)
      Splits a string around matches of the given delimiter character.
      static java.util.List<java.lang.String> split​(java.lang.String value, java.lang.String delimiter)
      Splits a string around matches of the given delimiter string.
      static java.lang.String toFirstLower​(java.lang.String s)  
      static java.lang.String toFirstUpper​(java.lang.String s)  
      static char toHex​(int i)  
      static java.lang.String toPlatformLineSeparator​(java.lang.CharSequence cs)  
      static <T> java.lang.String toString​(java.util.Collection<T> list, com.google.common.base.Function<T,​java.lang.String> toString, java.lang.String delim)  
      static java.lang.String toUnixLineSeparator​(java.lang.CharSequence cs)  
      static java.lang.CharSequence trimTrailingLineBreak​(java.lang.CharSequence s)
      Assumes '\r', '\n' or '\r\n' to be valid line breaks.
      static java.lang.String[] unpack​(java.lang.String packed)  
      static java.lang.String wordWrap​(java.lang.String string, int maxCharsPerLine)  
      • Methods inherited from class java.lang.Object

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

      • EMPTY_ARRAY

        public static final java.lang.String[] EMPTY_ARRAY
    • Constructor Detail

      • Strings

        public Strings()
    • Method Detail

      • equalsIgnoreWhitespace

        public static boolean equalsIgnoreWhitespace​(java.lang.String left,
                                                     java.lang.String right)
      • equal

        public static boolean equal​(java.lang.String literal,
                                    java.lang.String name)
      • notNull

        public static java.lang.String notNull​(java.lang.Object o)
      • emptyIfNull

        public static java.lang.String emptyIfNull​(java.lang.String s)
      • concat

        public static java.lang.String concat​(java.lang.String separator,
                                              java.util.List<java.lang.String> list)
      • toString

        public static <T> java.lang.String toString​(java.util.Collection<T> list,
                                                    com.google.common.base.Function<T,​java.lang.String> toString,
                                                    java.lang.String delim)
      • concat

        public static java.lang.String concat​(java.lang.String separator,
                                              java.util.List<java.lang.String> list,
                                              int skip)
      • skipLastToken

        public static java.lang.String skipLastToken​(java.lang.String value,
                                                     java.lang.String separator)
      • lastToken

        public static java.lang.String lastToken​(java.lang.String value,
                                                 java.lang.String separator)
      • toFirstUpper

        public static java.lang.String toFirstUpper​(java.lang.String s)
      • isEmpty

        public static boolean isEmpty​(java.lang.String s)
      • newLine

        public static java.lang.String newLine()
      • toPlatformLineSeparator

        public static java.lang.String toPlatformLineSeparator​(java.lang.CharSequence cs)
        Since:
        2.13
      • toUnixLineSeparator

        public static java.lang.String toUnixLineSeparator​(java.lang.CharSequence cs)
        Since:
        2.14
      • toFirstLower

        public static java.lang.String toFirstLower​(java.lang.String s)
      • convertFromJavaString

        public static java.lang.String convertFromJavaString​(java.lang.String string,
                                                             boolean useUnicode)
        Resolve Java control character sequences with to the actual character value. Optionally handle unicode escape sequences, too.
      • convertToJavaString

        public static java.lang.String convertToJavaString​(java.lang.String theString)
        Escapes control characters with a preceding backslash. Encodes special chars as unicode escape sequence. The resulting string is safe to be put into a Java string literal between the quotes.
      • convertToJavaString

        public static java.lang.String convertToJavaString​(java.lang.String input,
                                                           boolean useUnicode)
        Escapes control characters with a preceding backslash. Optionally encodes special chars as unicode escape sequence. The resulting string is safe to be put into a Java string literal between the quotes.
      • toHex

        public static char toHex​(int i)
      • split

        public static java.util.List<java.lang.String> split​(java.lang.String value,
                                                             java.lang.String delimiter)
        Splits a string around matches of the given delimiter string.

        This method works similar to String.split(String) but does not treat the delimiter as a regular expression. This makes it perform better in most cases where this feature is not necessary. Furthermore this implies that trailing empty segments will not be part of the result.

        For delimiters of length 1 it is preferred to use split(String, char) instead.

        Parameters:
        value - the string to split
        delimiter - the delimiting string (e.g. "::")
        Returns:
        the list of strings computed by splitting the string around matches of the given delimiter without trailing empty segments. Never null and the list does not contain any null values.
        Throws:
        java.lang.NullPointerException - If the value or delimiter is null
      • split

        public static java.util.List<java.lang.String> split​(java.lang.String value,
                                                             char delimiter)
        Splits a string around matches of the given delimiter character.

        This method works similar to String.split(String) but does not treat the delimiter as a regular expression. This makes it perform better in most cases where this feature is not necessary. Furthermore this implies that trailing empty segments will not be part of the result.

        Parameters:
        value - the string to split
        delimiter - the delimiting character (e.g. '.' or ':')
        Returns:
        the list of strings computed by splitting the string around matches of the given delimiter without trailing empty segments. Never null and the list does not contain any null values.
        Throws:
        java.lang.NullPointerException - If the value is null
        Since:
        2.3
        See Also:
        String.split(String)
      • pack

        public static java.lang.String pack​(java.lang.String[] strings)
        Parameters:
        strings - array of strings, may not be null and may not contain any null values.
        Throws:
        java.lang.NullPointerException - if the array of strings or any element in the array is null
      • unpack

        public static java.lang.String[] unpack​(java.lang.String packed)
      • removeLeadingWhitespace

        public static java.lang.String removeLeadingWhitespace​(java.lang.String indentationString)
      • countLineBreaks

        public static int countLineBreaks​(java.lang.CharSequence text)
        Counts the number of line breaks. Assumes '\r', '\n' or '\r\n' to be valid line breaks. This follows the semantics of the LineNumberReader.
        Since:
        2.3
      • countLineBreaks

        public static int countLineBreaks​(java.lang.CharSequence text,
                                          int startInclusive,
                                          int endExclusive)
        Counts the number of line breaks. Assumes '\r', '\n' or '\r\n' to be valid line breaks. This follows the semantics of the LineNumberReader.
        Since:
        2.9
      • trimTrailingLineBreak

        public static java.lang.CharSequence trimTrailingLineBreak​(java.lang.CharSequence s)
        Assumes '\r', '\n' or '\r\n' to be valid line breaks.
        Since:
        2.6
      • countLines

        public static int countLines​(java.lang.String text)
        Counts the number of lines where separator is assumed to be the only valid line break sequence. A string without any line separators returns 0 as the number of lines.
      • countLines

        public static int countLines​(java.lang.String text,
                                     char[] separator)
        Counts the number of lines where the given separator sequence is the only valid line break sequence. A string without any line separators returns 0 as the number of lines.
      • countLines

        public static int countLines​(java.lang.String text,
                                     char[] separator,
                                     int startInclusive,
                                     int endExclusive)
        Counts the number of lines between startInclusive and endExclusive where the given separator sequence is the only valid line break sequence. A string without any line separators in that range returns 0 as the number of lines.
        Since:
        2.9
      • getLeadingWhiteSpace

        public static java.lang.String getLeadingWhiteSpace​(java.lang.String original)
      • wordWrap

        public static java.lang.String wordWrap​(java.lang.String string,
                                                int maxCharsPerLine)
        Since:
        2.1
      • getLevenshteinDistance

        public static int getLevenshteinDistance​(java.lang.String from,
                                                 java.lang.String to)
        Calculates the Levenshtein text edit distance copied & adapted (cost = 1) from org.eclipse.jdt.internal.ui.text.spelling.engine.DefaultPhoneticDistanceAlgorithm
        Parameters:
        from - source string, may not be null
        to - target string, may not be null
        Returns:
        Levenshtein distance between from and to
        Since:
        2.27