Class StringUtil


  • @Deprecated
    @InternalApi
    public final class StringUtil
    extends Object
    Deprecated.
    Is internal API
    A number of String-specific utility methods for use by PMD or its IDE plugins.
    Author:
    BrianRemedios
    • Method Detail

      • percentageString

        public static String percentageString​(double val,
                                              int numDecimals)
        Deprecated.
        Formats a double to a percentage, keeping numDecimal decimal places.
        Parameters:
        val - a double value between 0 and 1
        numDecimals - The number of decimal places to keep
        Returns:
        A formatted string
        Throws:
        IllegalArgumentException - if the double to format is not between 0 and 1
      • startsWithAny

        @Deprecated
        public static boolean startsWithAny​(String text,
                                            String... prefixes)
        Deprecated.
        StringUtils.startsWithAny(CharSequence, CharSequence...)
        Return whether the non-null text arg starts with any of the prefix values.
        Parameters:
        text -
        prefixes -
        Returns:
        boolean
      • isAnyOf

        public static boolean isAnyOf​(String text,
                                      String... tests)
        Deprecated.
        Returns whether the non-null text arg matches any of the test values.
        Parameters:
        text -
        tests -
        Returns:
        boolean
      • withoutPrefixes

        public static String withoutPrefixes​(String text,
                                             String... prefixes)
        Deprecated.
        Checks for the existence of any of the listed prefixes on the non-null text and removes them.
        Parameters:
        text -
        prefixes -
        Returns:
        String
      • isNotEmpty

        @Deprecated
        public static boolean isNotEmpty​(String value)
        Deprecated.
        StringUtils.isNotBlank(CharSequence)
        Parameters:
        value - String
        Returns:
        boolean
      • isEmpty

        @Deprecated
        public static boolean isEmpty​(String value)
        Deprecated.
        StringUtils.isBlank(CharSequence)
        Returns true if the value arg is either null, empty, or full of whitespace characters. More efficient that calling (string).trim().length() == 0.
        Parameters:
        value - String to test
        Returns:
        true if the value is empty, false otherwise.
      • isMissing

        @Deprecated
        public static boolean isMissing​(String value)
        Deprecated.
        StringUtils.isEmpty(CharSequence)
        Returns true if the argument is null or the empty string.
        Parameters:
        value - String to test
        Returns:
        True if the argument is null or the empty string
      • areSemanticEquals

        @Deprecated
        public static boolean areSemanticEquals​(String a,
                                                String b)
        Deprecated.
        Returns true if both strings are effectively null or whitespace, returns false otherwise if they have actual text that differs.
        Parameters:
        a -
        b -
        Returns:
        boolean
      • replaceString

        @Deprecated
        public static String replaceString​(String original,
                                           String oldString,
                                           String newString)
        Deprecated.
        StringUtils.replace(String, String, String)
        Parameters:
        original - String
        oldString - String
        newString - String
        Returns:
        String
      • appendXmlEscaped

        public static void appendXmlEscaped​(StringBuilder buf,
                                            String src,
                                            boolean supportUTF8)
        Deprecated.
        Parameters:
        buf -
        src -
        supportUTF8 - override the default setting, whether special characters should be replaced with entities ( false) or should be included as is ( true).
      • escapeWhitespace

        public static String escapeWhitespace​(Object o)
        Deprecated.
        Replace some whitespace characters so they are visually apparent.
        Parameters:
        o -
        Returns:
        String
      • replaceString

        @Deprecated
        public static String replaceString​(String original,
                                           char oldChar,
                                           String newString)
        Deprecated.
        StringUtils.replace(String, String, String) or StringUtils.replaceChars(String, char, char)
        Parameters:
        original - String
        oldChar - char
        newString - String
        Returns:
        String
      • substringsOf

        @Deprecated
        public static String[] substringsOf​(String source,
                                            char delimiter)
        Deprecated.
        StringUtils.split(String, char)
        Parses the input source using the delimiter specified. This method is much faster than using the StringTokenizer or String.split(char) approach and serves as a replacement for String.split() for JDK1.3 that doesn't have it.
        Parameters:
        source - String
        delimiter - char
        Returns:
        String[]
      • substringsOf

        @Deprecated
        public static String[] substringsOf​(String str,
                                            String separator)
        Deprecated.
        StringUtils.split(String, String)
        Much more efficient than StringTokenizer.
        Parameters:
        str - String
        separator - char
        Returns:
        String[]
      • asStringOn

        @Deprecated
        public static void asStringOn​(StringBuffer sb,
                                      Iterator<?> iter,
                                      String separator)
        Deprecated.
        StringUtils.join(Iterator, String)
        Copies the elements returned by the iterator onto the string buffer each delimited by the separator.
        Parameters:
        sb - StringBuffer
        iter - Iterator
        separator - String
      • asStringOn

        @Deprecated
        public static void asStringOn​(StringBuilder sb,
                                      Object[] items,
                                      String separator)
        Deprecated.
        StringUtils.join(Iterable, String)
        Copies the array items onto the string builder each delimited by the separator. Does nothing if the array is null or empty.
        Parameters:
        sb - StringBuilder
        items - Object[]
        separator - String
      • maxCommonLeadingWhitespaceForAll

        public static int maxCommonLeadingWhitespaceForAll​(String[] strings)
        Deprecated.
        Determine the maximum number of common leading whitespace characters the strings share in the same sequence. Useful for determining how many leading characters can be removed to shift all the text in the strings to the left without misaligning them.
        Parameters:
        strings - String[]
        Returns:
        int
      • lengthOfShortestIn

        public static int lengthOfShortestIn​(String[] strings)
        Deprecated.
        Return the length of the shortest string in the array. If the collection is empty or any one of them is null then it returns 0.
        Parameters:
        strings - String[]
        Returns:
        int
      • trimStartOn

        public static String[] trimStartOn​(String[] strings,
                                           int trimDepth)
        Deprecated.
        Trims off the leading characters off the strings up to the trimDepth specified. Returns the same strings if trimDepth = 0
        Parameters:
        strings -
        trimDepth -
        Returns:
        String[]
      • lpad

        @Deprecated
        public static String lpad​(String s,
                                  int length)
        Deprecated.
        StringUtils.leftPad(String, int)
        Left pads a string.
        Parameters:
        s - The String to pad
        length - The desired minimum length of the resulting padded String
        Returns:
        The resulting left padded String
      • isSame

        public static boolean isSame​(String s1,
                                     String s2,
                                     boolean trim,
                                     boolean ignoreCase,
                                     boolean standardizeWhitespace)
        Deprecated.
        Are the two String values the same. The Strings can be optionally trimmed before checking. The Strings can be optionally compared ignoring case. The Strings can be have embedded whitespace standardized before comparing. Two null values are treated as equal.
        Parameters:
        s1 - The first String.
        s2 - The second String.
        trim - Indicates if the Strings should be trimmed before comparison.
        ignoreCase - Indicates if the case of the Strings should ignored during comparison.
        standardizeWhitespace - Indicates if the embedded whitespace should be standardized before comparison.
        Returns:
        true if the Strings are the same, false otherwise.
      • asString

        public static String asString​(Object[] items,
                                      String separator)
        Deprecated.
        Formats all items onto a string with separators if more than one exists, return an empty string if the items are null or empty.
        Parameters:
        items - Object[]
        separator - String
        Returns:
        String
      • getEmptyStrings

        public static String[] getEmptyStrings()
        Deprecated.
        Returns an empty array of string
        Returns:
        String
      • toCamelCase

        public static String toCamelCase​(String name)
        Deprecated.
        Converts the given string to Camel case, that is, removing all spaces, and capitalising the first letter of each word except the first.

        If the first word starts with an uppercase letter, it's kept as is. This method can thus be used for Pascal case too.

        Parameters:
        name - The string to convert
        Returns:
        The string converted to Camel case
      • toCamelCase

        public static String toCamelCase​(String name,
                                         boolean forceLowerCase)
        Deprecated.
        Converts the given string to Camel case, that is, removing all spaces, and capitalising the first letter of each word except the first.

        The second parameter can be used to force the words to be converted to lowercase before capitalising. This can be useful if eg the first word contains several uppercase letters.

        Parameters:
        name - The string to convert
        forceLowerCase - Whether to force removal of all upper case letters except on word start
        Returns:
        The string converted to Camel case
      • escapeJava

        public static String escapeJava​(String str)
        Deprecated.
        Replaces unprintable characters by their escaped (or unicode escaped) equivalents in the given string