Class StringUtils


  • public class StringUtils
    extends java.lang.Object
    Utility class for string manipulation.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static @NotNull java.util.regex.Pattern PATTERN_BACKSLASH
      The pattern that matches a single backslash ("\").
      static @NotNull java.util.regex.Pattern PATTERN_COLON
      The pattern that matches a single colon (":").
      static @NotNull java.util.regex.Pattern PATTERN_COMMA
      The pattern that matches a single comma (",").
      static @NotNull java.util.regex.Pattern PATTERN_END_OF_LINE
      The pattern to match end of line characters separating lines.
      static @NotNull java.util.regex.Pattern PATTERN_EQUAL
      The pattern that matches a single equal sign ("=").
      static @NotNull java.util.regex.Pattern PATTERN_NEWLINE
      The pattern that matches a single newline ("\n").
      static @NotNull java.util.regex.Pattern PATTERN_SLASH
      The pattern that matches a single slash ("/").
      static @NotNull java.util.regex.Pattern PATTERN_SPACE
      The pattern that matches a single space.
      static @NotNull java.util.regex.Pattern PATTERN_SPACES
      The pattern that matches a non-empty sequence of spaces.
      static @NotNull java.util.regex.Pattern PATTERN_WHITESPACE
      Pattern to match whitespace excluding NL and CR.
      static @NotNull java.util.regex.Pattern PATTERN_WHITESPACE_NEWLINE
      Pattern to match whitespace including NL and CR.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static @Nullable java.lang.CharSequence diffTextString​(@NotNull java.lang.CharSequence base, @NotNull java.lang.String str, boolean ignoreValues)
      Helper function for 'diffArchText()': Looks for occurrence of the attribute 'str' in 'base' and if found, returns the full line where 'str' occurs in base.
      static @NotNull java.lang.CharSequence ensureTrailingNewline​(@NotNull java.lang.String str)
      Returns a given string which ends with a trailing newline character; empty strings remain empty.
      static @Nullable java.lang.String getAttribute​(@NotNull java.lang.CharSequence attributes, @NotNull java.lang.String attributeName)
      Returns an attribute line from a set of attribute definitions.
      static @NotNull java.lang.String removeTrailingWhitespace​(@NotNull java.lang.CharSequence str)
      Removes trailing whitespace from a string.
      static @NotNull java.lang.String removeTrailingWhitespaceFromLines​(@NotNull java.lang.CharSequence str)
      Removes trailing whitespace from all lines of a string.
      static @NotNull java.lang.String sortLines​(@NotNull java.lang.CharSequence string)
      Sorts newline separated lines in a string.
      • Methods inherited from class java.lang.Object

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

      • PATTERN_WHITESPACE

        @NotNull
        public static final @NotNull java.util.regex.Pattern PATTERN_WHITESPACE
        Pattern to match whitespace excluding NL and CR.
      • PATTERN_WHITESPACE_NEWLINE

        @NotNull
        public static final @NotNull java.util.regex.Pattern PATTERN_WHITESPACE_NEWLINE
        Pattern to match whitespace including NL and CR.
      • PATTERN_END_OF_LINE

        @NotNull
        public static final @NotNull java.util.regex.Pattern PATTERN_END_OF_LINE
        The pattern to match end of line characters separating lines.
      • PATTERN_SPACE

        @NotNull
        public static final @NotNull java.util.regex.Pattern PATTERN_SPACE
        The pattern that matches a single space.
      • PATTERN_SPACES

        @NotNull
        public static final @NotNull java.util.regex.Pattern PATTERN_SPACES
        The pattern that matches a non-empty sequence of spaces.
      • PATTERN_SLASH

        @NotNull
        public static final @NotNull java.util.regex.Pattern PATTERN_SLASH
        The pattern that matches a single slash ("/").
      • PATTERN_BACKSLASH

        @NotNull
        public static final @NotNull java.util.regex.Pattern PATTERN_BACKSLASH
        The pattern that matches a single backslash ("\").
      • PATTERN_COLON

        @NotNull
        public static final @NotNull java.util.regex.Pattern PATTERN_COLON
        The pattern that matches a single colon (":").
      • PATTERN_COMMA

        @NotNull
        public static final @NotNull java.util.regex.Pattern PATTERN_COMMA
        The pattern that matches a single comma (",").
      • PATTERN_EQUAL

        @NotNull
        public static final @NotNull java.util.regex.Pattern PATTERN_EQUAL
        The pattern that matches a single equal sign ("=").
      • PATTERN_NEWLINE

        @NotNull
        public static final @NotNull java.util.regex.Pattern PATTERN_NEWLINE
        The pattern that matches a single newline ("\n").
    • Method Detail

      • removeTrailingWhitespace

        @NotNull
        public static @NotNull java.lang.String removeTrailingWhitespace​(@NotNull
                                                                         @NotNull java.lang.CharSequence str)
        Removes trailing whitespace from a string.
        Parameters:
        str - the string
        Returns:
        the trimmed string
      • removeTrailingWhitespaceFromLines

        @NotNull
        public static @NotNull java.lang.String removeTrailingWhitespaceFromLines​(@NotNull
                                                                                  @NotNull java.lang.CharSequence str)
        Removes trailing whitespace from all lines of a string.
        Parameters:
        str - the string
        Returns:
        the trimmed string
      • ensureTrailingNewline

        @NotNull
        public static @NotNull java.lang.CharSequence ensureTrailingNewline​(@NotNull
                                                                            @NotNull java.lang.String str)
        Returns a given string which ends with a trailing newline character; empty strings remain empty. If the input strings ends in a newline character or if it is empty, it is returned; else a newline character is appended first.
        Parameters:
        str - the input string
        Returns:
        the string with a trailing newline character
      • diffTextString

        @Nullable
        public static @Nullable java.lang.CharSequence diffTextString​(@NotNull
                                                                      @NotNull java.lang.CharSequence base,
                                                                      @NotNull
                                                                      @NotNull java.lang.String str,
                                                                      boolean ignoreValues)
        Helper function for 'diffArchText()': Looks for occurrence of the attribute 'str' in 'base' and if found, returns the full line where 'str' occurs in base. Only occurrences of 'str' at the beginning of a new line are counted as valid. If not found, null is returned.
        Parameters:
        base - full text to search
        str - string (attribute) to look for
        ignoreValues - if true, lines are matched against 'str' only till the first space (" ")
        Returns:
        the text that differs
      • getAttribute

        @Nullable
        public static @Nullable java.lang.String getAttribute​(@NotNull
                                                              @NotNull java.lang.CharSequence attributes,
                                                              @NotNull
                                                              @NotNull java.lang.String attributeName)
        Returns an attribute line from a set of attribute definitions. If the set contains more than one instance of attributeName, only the first instance is returned.
        Parameters:
        attributes - the attribute set to search
        attributeName - the attribute name to search for
        Returns:
        the set of attribute value or null if the attribute was not found
      • sortLines

        @NotNull
        public static @NotNull java.lang.String sortLines​(@NotNull
                                                          @NotNull java.lang.CharSequence string)
        Sorts newline separated lines in a string.
        Parameters:
        string - the string to sort
        Returns:
        the sorted string