Class StringUtilsExtensions


  • @ThreadSafe
    public class StringUtilsExtensions
    extends org.apache.commons.lang3.StringUtils
    Provides enhanced string utilities.
    Author:
    aherscu
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static String abbreviate​(String str, int maxWidth)  
      static String abbreviateMiddle​(String str, String middle, int length)  
      static String format​(String template, String pattern, String string)  
      static String format​(String template, Pattern pattern, String string)  
      static Collection<String> groups​(String pattern, String string)  
      static Collection<String> groups​(Pattern pattern, String string)
      Splits a string according to specified regular expression groups.
      static String ifExcessiveLength​(String str, int allowedLength)
      If given string has excessive length return its length.
      static String left​(String str, int length)  
      static String length​(String str)
      Formats the length of given string.
      static String length​(String str, String format)
      Formats the length of given string.
      static String prettified​(Object object)
      Returns the prettified version of an object.
      static String substring​(String s, Pattern regex)
      Extracts a substring by specified regular expression.
      static String toUnix​(String str)
      Converts Windows end-of-line to *nix end-of-line.
      • Methods inherited from class org.apache.commons.lang3.StringUtils

        abbreviate, abbreviate, abbreviate, appendIfMissing, appendIfMissingIgnoreCase, capitalize, center, center, center, chomp, chomp, chop, compare, compare, compareIgnoreCase, compareIgnoreCase, contains, contains, containsAny, containsAny, containsAny, containsAnyIgnoreCase, containsIgnoreCase, containsNone, containsNone, containsOnly, containsOnly, containsWhitespace, countMatches, countMatches, defaultIfBlank, defaultIfEmpty, defaultString, defaultString, deleteWhitespace, difference, endsWith, endsWithAny, endsWithIgnoreCase, equals, equalsAny, equalsAnyIgnoreCase, equalsIgnoreCase, firstNonBlank, firstNonEmpty, getBytes, getBytes, getCommonPrefix, getDigits, getFuzzyDistance, getIfBlank, getIfEmpty, getJaroWinklerDistance, getLevenshteinDistance, getLevenshteinDistance, indexOf, indexOf, indexOf, indexOf, indexOfAny, indexOfAny, indexOfAny, indexOfAnyBut, indexOfAnyBut, indexOfDifference, indexOfDifference, indexOfIgnoreCase, indexOfIgnoreCase, isAllBlank, isAllEmpty, isAllLowerCase, isAllUpperCase, isAlpha, isAlphanumeric, isAlphanumericSpace, isAlphaSpace, isAnyBlank, isAnyEmpty, isAsciiPrintable, isBlank, isEmpty, isMixedCase, isNoneBlank, isNoneEmpty, isNotBlank, isNotEmpty, isNumeric, isNumericSpace, isWhitespace, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, joinWith, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexOfAny, lastIndexOfIgnoreCase, lastIndexOfIgnoreCase, lastOrdinalIndexOf, leftPad, leftPad, leftPad, length, lowerCase, lowerCase, mid, normalizeSpace, ordinalIndexOf, overlay, prependIfMissing, prependIfMissingIgnoreCase, remove, remove, removeAll, removeEnd, removeEndIgnoreCase, removeFirst, removeIgnoreCase, removePattern, removeStart, removeStart, removeStartIgnoreCase, repeat, repeat, repeat, replace, replace, replaceAll, replaceChars, replaceChars, replaceEach, replaceEachRepeatedly, replaceFirst, replaceIgnoreCase, replaceIgnoreCase, replaceOnce, replaceOnceIgnoreCase, replacePattern, reverse, reverseDelimited, right, rightPad, rightPad, rightPad, rotate, split, split, split, split, splitByCharacterType, splitByCharacterTypeCamelCase, splitByWholeSeparator, splitByWholeSeparator, splitByWholeSeparatorPreserveAllTokens, splitByWholeSeparatorPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, startsWith, startsWithAny, startsWithIgnoreCase, strip, strip, stripAccents, stripAll, stripAll, stripEnd, stripStart, stripToEmpty, stripToNull, substring, substring, substringAfter, substringAfter, substringAfterLast, substringAfterLast, substringBefore, substringBefore, substringBeforeLast, substringBetween, substringBetween, substringsBetween, swapCase, toCodePoints, toEncodedString, toRootLowerCase, toRootUpperCase, toString, trim, trimToEmpty, trimToNull, truncate, truncate, uncapitalize, unwrap, unwrap, upperCase, upperCase, valueOf, wrap, wrap, wrapIfMissing, wrapIfMissing
    • Constructor Detail

      • StringUtilsExtensions

        public StringUtilsExtensions()
    • Method Detail

      • abbreviate

        public static String abbreviate​(String str,
                                        int maxWidth)
      • abbreviateMiddle

        public static String abbreviateMiddle​(String str,
                                              String middle,
                                              int length)
      • groups

        public static Collection<String> groups​(Pattern pattern,
                                                String string)
        Splits a string according to specified regular expression groups. groups("(\\d+)(\\w+)", "10FF 99GG") will return four items: "10", "FF", "99", "GG"
        Parameters:
        pattern - compiled regular expression to apply; must contain groups
        string - the string to split
        Returns:
        split string
      • ifExcessiveLength

        public static String ifExcessiveLength​(String str,
                                               int allowedLength)
        If given string has excessive length return its length.
        Parameters:
        str - the string to be processed
        allowedLength - the allowed length
        Returns:
        the length of the string as formatted by length(String)
      • left

        public static String left​(String str,
                                  int length)
      • length

        public static String length​(String str)
        Formats the length of given string.
        Parameters:
        str - the string for which to return the length
        Returns:
        the length of the string formatted as (ddd chars), where ddd is the actual length
      • length

        public static String length​(String str,
                                    String format)
        Formats the length of given string.
        Parameters:
        str - the string for which to return the length
        format - the template to use for formatting; see String.format(String, Object...)
        Returns:
        the length of the string formatted as (ddd chars), where ddd is the actual length
      • prettified

        public static String prettified​(Object object)
        Returns the prettified version of an object.
        Parameters:
        object - the object
        Returns:
        <<null>> for null, <<empty>> for object with length 0, and <<blank>> for object containing only whitespace characters according to StringUtils.isBlank(CharSequence)
      • substring

        public static String substring​(String s,
                                       Pattern regex)
        Extracts a substring by specified regular expression.
        Parameters:
        s - the string to extract from
        regex - the regular expression
        Returns:
        substring extracted; empty if no match could be found
      • toUnix

        public static String toUnix​(String str)
        Converts Windows end-of-line to *nix end-of-line.
        Parameters:
        str - the string to convert
        Returns:
        the converted string