Class StringUtilities


  • public class StringUtilities
    extends java.lang.Object
    String utilities used in various filters.
    Since:
    June 1, 2007
    Author:
    Jeff Williams (jeff.williams .at. aspectsecurity.com) Aspect Security
    • Constructor Summary

      Constructors 
      Constructor Description
      StringUtilities()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean contains​(java.lang.StringBuilder input, char c)
      Returns true if the character is contained in the provided StringBuilder.
      static int getLevenshteinDistance​(java.lang.String s, java.lang.String t)
      Calculate the Edit Distance between 2 Strings as a measure of similarity.
      static boolean isEmpty​(java.lang.String str)
      Returns true if String is empty ("") or null.
      static boolean notNullOrEmpty​(java.lang.String str, boolean trim)
      Check to ensure that a String is not null or empty (after optional trimming of leading and trailing whitespace).
      static java.lang.String replaceLinearWhiteSpace​(java.lang.String input)  
      static java.lang.String replaceNull​(java.lang.String test, java.lang.String replace)
      Returns the replace value if the value of test is null, "null", or ""
      static java.lang.String stripControls​(java.lang.String input)
      Removes all unprintable characters from a string and replaces with a space.
      static char[] union​(char[]... list)
      Union multiple character arrays.
      • Methods inherited from class java.lang.Object

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

      • StringUtilities

        public StringUtilities()
    • Method Detail

      • replaceLinearWhiteSpace

        public static java.lang.String replaceLinearWhiteSpace​(java.lang.String input)
      • stripControls

        public static java.lang.String stripControls​(java.lang.String input)
        Removes all unprintable characters from a string and replaces with a space.
        Parameters:
        input -
        Returns:
        the stripped value
      • union

        public static char[] union​(char[]... list)
        Union multiple character arrays.
        Parameters:
        list - the char[]s to union
        Returns:
        the union of the char[]s
      • contains

        public static boolean contains​(java.lang.StringBuilder input,
                                       char c)
        Returns true if the character is contained in the provided StringBuilder.
        Parameters:
        input - The input
        c - The character to check for to see if input contains.
        Returns:
        True if the specified character is contained; false otherwise.
      • replaceNull

        public static java.lang.String replaceNull​(java.lang.String test,
                                                   java.lang.String replace)
        Returns the replace value if the value of test is null, "null", or ""
        Parameters:
        test - The value to test
        replace - The replacement value
        Returns:
        The correct value
      • getLevenshteinDistance

        public static int getLevenshteinDistance​(java.lang.String s,
                                                 java.lang.String t)
        Calculate the Edit Distance between 2 Strings as a measure of similarity. For example, if the strings GUMBO and GAMBOL are passed in, the edit distance is 2, since GUMBO transforms into GAMBOL by replacing the 'U' with an 'A' and adding an 'L'. Original Implementation of this algorithm by Michael Gilleland, adapted by Chas Emerick for the Apache-Commons project http://www.merriampark.com/ldjava.htm
        Parameters:
        s - The source string
        t - The target String
        Returns:
        The edit distance between the 2 strings
      • notNullOrEmpty

        public static boolean notNullOrEmpty​(java.lang.String str,
                                             boolean trim)
        Check to ensure that a String is not null or empty (after optional trimming of leading and trailing whitespace). Usually used with assertions, as in
                        assert StringUtils.notNullOrEmpty(cipherXform, true) :
                                                                        "Cipher transformation may not be null or empty!";
         
        Parameters:
        str - The String to be checked.
        trim - If true, the string is first trimmed before checking to see if it is empty, otherwise it is not.
        Returns:
        True if the string is null or empty (after possible trimming); otherwise false.
        Since:
        2.0
      • isEmpty

        public static boolean isEmpty​(java.lang.String str)
        Returns true if String is empty ("") or null.