Enum StringUtils

    • Method Detail

      • values

        public static StringUtils[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (StringUtils c : StringUtils.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static StringUtils valueOf​(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • trimChar

        public static String trimChar​(String s,
                                      char c)
      • trimOrPad

        public static String trimOrPad​(String str,
                                       int length)
        Trims or pads (with spaces) this string, so it has this exact length.
        Parameters:
        str - The string to adjust. null is treated as an empty string.
        length - The exact length to reach.
        Returns:
        The adjusted string.
      • trimOrPad

        public static String trimOrPad​(String str,
                                       int length,
                                       char padChar)
        Trims or pads this string, so it has this exact length.
        Parameters:
        str - The string to adjust. null is treated as an empty string.
        length - The exact length to reach.
        padChar - The padding character.
        Returns:
        The adjusted string.
      • trimOrLeftPad

        public static String trimOrLeftPad​(String str,
                                           int length,
                                           char padChar)
        Trims or pads this string, so it has this exact length.
        Parameters:
        str - The string to adjust. null is treated as an empty string.
        length - The exact length to reach.
        padChar - The padding character.
        Returns:
        The adjusted string.
      • leftPad

        public static String leftPad​(String original,
                                     int length,
                                     char padChar)
      • collapseWhitespace

        public static String collapseWhitespace​(String str)
        Replaces all sequences of whitespace by a single blank. Ex.: "    " -> " "
        Parameters:
        str - The string to analyse.
        Returns:
        The input string, with all whitespace collapsed.
      • left

        public static String left​(String str,
                                  int count)
        Returns the first n characters from this string, where n = count. If the string is shorter, the entire string will be returned. If the string is longer, it will be truncated.
        Parameters:
        str - The string to parse.
        count - The amount of characters to return.
        Returns:
        The first n characters from this string, where n = count.
      • replaceAll

        public static String replaceAll​(String str,
                                        String originalToken,
                                        String replacementToken)
        Replaces all occurrences of this originalToken in this string with this replacementToken.
        Parameters:
        str - The string to process.
        originalToken - The token to replace.
        replacementToken - The replacement.
        Returns:
        The transformed str.
      • hasLength

        public static boolean hasLength​(String str)
        Checks whether this string is not null and not empty.
        Parameters:
        str - The string to check.
        Returns:
        true if it has content, false if it is null or blank.
      • arrayToCommaDelimitedString

        public static String arrayToCommaDelimitedString​(Object[] strings)
        Turns this string array in one comma-delimited string.
        Parameters:
        strings - The array to process.
        Returns:
        The new comma-delimited string. An empty string if strings is empty. null if strings is null.
      • arrayToDelimitedString

        public static String arrayToDelimitedString​(String delimiter,
                                                    Object[] strings)
        Turns this string array in one delimited string.
        Parameters:
        delimiter - The delimiter to use.
        strings - The array to process.
        Returns:
        The new delimited string. An empty string if strings is empty. null if strings is null.
      • hasText

        public static boolean hasText​(String s)
        Checks whether this string isn't null and contains at least one non-blank character.
        Parameters:
        s - The string to check.
        Returns:
        true if it has text, false if not.
      • tokenizeToStringArray

        public static String[] tokenizeToStringArray​(String str,
                                                     String delimiters)
        Splits this string into an array using these delimiters.
        Parameters:
        str - The string to split.
        delimiters - The delimiters to use.
        Returns:
        The resulting array.
      • tokenizeToStringCollection

        public static List<String> tokenizeToStringCollection​(String str,
                                                              String delimiters)
        Splits this string into a collection using these delimiters.
        Parameters:
        str - The string to split.
        delimiters - The delimiters to use.
        Returns:
        The resulting array.
      • tokenizeToStringCollection

        public static List<String> tokenizeToStringCollection​(String str,
                                                              char delimiterChar,
                                                              char groupDelimiterChar)
        Splits this string into a collection using this delimiter and this group delimiter.
        Parameters:
        str - The string to split.
        delimiterChar - The delimiter to use.
        groupDelimiterChar - The character to use to delimit groups.
        Returns:
        The resulting array.
      • replace

        public static String replace​(String inString,
                                     String oldPattern,
                                     String newPattern)
        Replace all occurrences of a substring within a string with another string.
        Parameters:
        inString - String to examine
        oldPattern - String to replace
        newPattern - String to insert
        Returns:
        a String with the replacements
      • collectionToCommaDelimitedString

        public static String collectionToCommaDelimitedString​(Collection<?> collection)
        Convenience method to return a Collection as a comma-delimited String. e.g. useful for toString() implementations.
        Parameters:
        collection - the Collection to analyse
        Returns:
        The comma-delimited String.
      • collectionToDelimitedString

        public static String collectionToDelimitedString​(Collection<?> collection,
                                                         String delimiter)
        Convenience method to return a Collection as a delimited String. E.g. useful for toString() implementations.
        Parameters:
        collection - the Collection to analyse
        delimiter - The delimiter.
        Returns:
        The delimited String.
      • trimLeadingCharacter

        public static String trimLeadingCharacter​(String str,
                                                  char character)
        Trim any leading occurrence of this character from the given String.
        Parameters:
        str - the String to check.
        character - The character to trim.
        Returns:
        the trimmed String
        See Also:
        Character.isWhitespace(char)
      • startsAndEndsWith

        public static boolean startsAndEndsWith​(String str,
                                                String prefix,
                                                String... suffixes)
        Checks whether str both begins with this prefix and ends withs either of these suffixes.
        Parameters:
        str - The string to check.
        prefix - The prefix.
        suffixes - The suffixes.
        Returns:
        true if it does, false if not.
      • wrap

        public static String wrap​(String str,
                                  int lineSize)
        Wrap this string every lineSize characters.
        Parameters:
        str - The string to wrap.
        lineSize - The maximum size of each line.
        Returns:
        The wrapped string.
      • wordWrap

        public static String wordWrap​(String str,
                                      int lineSize)
        Wrap this string at the word boundary at or below lineSize characters.
        Parameters:
        str - The string to wrap.
        lineSize - The maximum size of each line.
        Returns:
        The word-wrapped string.
      • isCharAnyOf

        public static boolean isCharAnyOf​(char c,
                                          String chars)
        Checks whether this character matches any of these characters.
        Parameters:
        c - The char to check.
        chars - The chars that should match.
        Returns:
        true if it does, false if not.
      • getFileExtension

        public static String getFileExtension​(String path)