Class Strings


  • public class Strings
    extends java.lang.Object
    String utilities.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String asString​(double d)
      Make a minimal printable string from a double value.
      static java.lang.String asString​(java.lang.Object o)
      Make an object into a string using the typed tools here.
      static java.lang.String asString​(java.util.Collection<?> collection)
      Make a printable string from a collection using the tools here.
      static java.lang.String asString​(java.util.Map<?,​?> map)
      Make a minimal printable string value from a typed map.
      static java.lang.String c_case​(java.lang.String name)
      Format a prefixed name as c_case.
      static java.lang.String c_case​(java.lang.String prefix, java.lang.String name)
      Format a prefixed name as c_case.
      static java.lang.String c_case​(java.lang.String prefix, java.lang.String name, java.lang.String suffix)
      Format a prefixed name as c_case.
      static java.lang.String camelCase​(java.lang.String name)
      Format a name as CamelCase.
      static java.lang.String camelCase​(java.lang.String prefix, java.lang.String name)
      Format a prefixed name as camelCase.
      static java.lang.String capitalize​(java.lang.String string)  
      static int commonOverlap​(java.lang.String text1, java.lang.String text2)
      Determine if the suffix of one string is the prefix of another.
      static int commonPrefix​(java.lang.String text1, java.lang.String text2)
      Determine the common prefix of two strings
      static int commonSuffix​(java.lang.String text1, java.lang.String text2)
      Determine the common suffix of two strings
      static java.lang.String escape​(char c)
      Escape a single character.
      static java.lang.String escape​(java.lang.CharSequence string)
      Properly java-escape the string for printing to console.
      static boolean isConsolePrintable​(int cp)
      Utility to figure out if a character is printable to the console as a character.
      static boolean isInteger​(java.lang.CharSequence str)
      Check if the string is representing an integer (or long) value.
      static boolean isInteger​(java.lang.CharSequence str, int off, int len)
      Check if the string is representing an integer (or long) value.
      static boolean isNotEmpty​(java.lang.String str)  
      static boolean isNullOrEmpty​(java.lang.String str)  
      static java.lang.String join​(java.lang.String delimiter, java.lang.Object... values)
      Join set of arbitrary values with delimiter.
      static <T> java.lang.String join​(java.lang.String delimiter, java.util.Collection<T> strings)
      Join collection with delimiter.
      static java.lang.String joinP​(java.lang.String delimiter, boolean... values)
      Join array with delimiter.
      static java.lang.String joinP​(java.lang.String delimiter, char... chars)
      Join array with delimiter.
      static java.lang.String joinP​(java.lang.String delimiter, double... values)
      Join array with delimiter.
      static java.lang.String joinP​(java.lang.String delimiter, int... values)
      Join array with delimiter.
      static java.lang.String joinP​(java.lang.String delimiter, long... values)
      Join array with delimiter.
      static java.lang.String times​(java.lang.String s, int num)
      Multiply a string N times.
      static java.lang.String unescapeForEncodeUriCompatability​(java.lang.String str)
      Unescape selected chars for compatability with JavaScript's encodeURI.
      • Methods inherited from class java.lang.Object

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

      • escape

        public static java.lang.String escape​(java.lang.CharSequence string)
        Properly java-escape the string for printing to console.
        Parameters:
        string - The string to escape.
        Returns:
        The escaped string.
      • escape

        public static java.lang.String escape​(char c)
        Escape a single character. It is escaped into a string, as it may become more than one char when escaped.
        Parameters:
        c - The char to escape.
        Returns:
        The escaped char string.
      • isConsolePrintable

        public static boolean isConsolePrintable​(int cp)
        Utility to figure out if a character is printable to the console as a character. Returns false if one of:
        • The character is a control character.
        • The character is not defined.
        • The character does not have a known representation.
        Parameters:
        cp - The character unicode code point.
        Returns:
        If it is printable.
      • unescapeForEncodeUriCompatability

        public static java.lang.String unescapeForEncodeUriCompatability​(java.lang.String str)
        Unescape selected chars for compatability with JavaScript's encodeURI. In speed critical applications this could be dropped since the receiving application will certainly decode these fine. Note that this function is case-sensitive. Thus "%3f" would not be unescaped. But this is ok because it is only called with the output of URLEncoder.encode which returns uppercase hex.

        Example: "%3F" -> "?", "%24" -> "$", etc.

        Parameters:
        str - The string to escape.
        Returns:
        The escaped string.
      • join

        public static java.lang.String join​(java.lang.String delimiter,
                                            java.lang.Object... values)
        Join set of arbitrary values with delimiter.
        Parameters:
        delimiter - The delimiter.
        values - The values to join.
        Returns:
        The joined string.
      • joinP

        public static java.lang.String joinP​(java.lang.String delimiter,
                                             char... chars)
        Join array with delimiter.
        Parameters:
        delimiter - The delimiter.
        chars - The char array to join.
        Returns:
        The joined string.
      • joinP

        public static java.lang.String joinP​(java.lang.String delimiter,
                                             int... values)
        Join array with delimiter.
        Parameters:
        delimiter - The delimiter.
        values - The int array to join.
        Returns:
        The joined string.
      • joinP

        public static java.lang.String joinP​(java.lang.String delimiter,
                                             long... values)
        Join array with delimiter.
        Parameters:
        delimiter - The delimiter.
        values - The int array to join.
        Returns:
        The joined string.
      • joinP

        public static java.lang.String joinP​(java.lang.String delimiter,
                                             double... values)
        Join array with delimiter.
        Parameters:
        delimiter - The delimiter.
        values - The double array to join.
        Returns:
        The joined string.
      • joinP

        public static java.lang.String joinP​(java.lang.String delimiter,
                                             boolean... values)
        Join array with delimiter.
        Parameters:
        delimiter - The delimiter.
        values - The double array to join.
        Returns:
        The joined string.
      • join

        public static <T> java.lang.String join​(java.lang.String delimiter,
                                                java.util.Collection<T> strings)
        Join collection with delimiter.
        Type Parameters:
        T - Collection item type.
        Parameters:
        delimiter - The delimiter.
        strings - The string collection to join.
        Returns:
        The joined string.
      • isInteger

        public static boolean isInteger​(java.lang.CharSequence str)
        Check if the string is representing an integer (or long) value.
        Parameters:
        str - The string to check if is an integer.
        Returns:
        True if key is an integer.
      • isInteger

        public static boolean isInteger​(java.lang.CharSequence str,
                                        int off,
                                        int len)
        Check if the string is representing an integer (or long) value.
        Parameters:
        str - The string to check if is an integer.
        off - The offset of the string to start checking.
        len - The length / number fo chars to check.
        Returns:
        True if key is an integer.
      • times

        public static java.lang.String times​(java.lang.String s,
                                             int num)
        Multiply a string N times.
        Parameters:
        s - The string to multiply.
        num - N
        Returns:
        The result.
      • camelCase

        public static java.lang.String camelCase​(java.lang.String prefix,
                                                 java.lang.String name)
        Format a prefixed name as camelCase. The prefix is kept verbatim, while tha name is split on '_' chars, and joined with each part capitalized.
        Parameters:
        prefix - The prefix.
        name - The name to camel-case.
        Returns:
        theCamelCasedName
      • camelCase

        public static java.lang.String camelCase​(java.lang.String name)
        Format a name as CamelCase. The name is split on non-alphabet non-numeric chars, and joined with each part capitalized. This is also called PascalCase. There is in this instance no assumptions on the name itself, other than it contains some alphabet characters. Any uppercase letters in the name will be kept as uppercase, so that a CamelCase name will stay CamelCase through this call.
        Parameters:
        name - The name to camel-case.
        Returns:
        TheCamelCasedName
      • c_case

        public static java.lang.String c_case​(java.lang.String prefix,
                                              java.lang.String name,
                                              java.lang.String suffix)
        Format a prefixed name as c_case. The prefix is kept verbatim, while the name has a '_' character inserted before each upper-case letter, not including the first character. Then the whole thing is lower-cased.
        Parameters:
        prefix - The prefix.
        name - The name to c-case.
        suffix - The suffix.
        Returns:
        the_c_cased_name
      • c_case

        public static java.lang.String c_case​(java.lang.String prefix,
                                              java.lang.String name)
        Format a prefixed name as c_case. The prefix is kept verbatim, while the name has a '_' character inserted before each upper-case letter, not including the first character. Then the whole thing is lower-cased.

        Note that this will mangle upper-case abbreviations.

        Parameters:
        prefix - The prefix.
        name - The name to c-case.
        Returns:
        the_c_cased_name
      • c_case

        public static java.lang.String c_case​(java.lang.String name)
        Format a prefixed name as c_case. The prefix is kept verbatim, while the name has a '_' character inserted before each upper-case letter, not including the first character. Then the whole thing is lower-cased.

        Note that this may mangle upper-case abbreviations.

        Parameters:
        name - The name to c-case.
        Returns:
        the_c_cased_name
      • capitalize

        public static java.lang.String capitalize​(java.lang.String string)
      • asString

        public static java.lang.String asString​(double d)
        Make a minimal printable string from a double value. This method does not necessary generate a string that when parsed generates the identical number as given in. But ut should consistently generate the same string (locale independent) for the same number with reasonable accuracy.
        Parameters:
        d - The double value.
        Returns:
        The string value.
      • asString

        public static java.lang.String asString​(java.util.Collection<?> collection)
        Make a printable string from a collection using the tools here.
        Parameters:
        collection - The collection to stringify.
        Returns:
        The collection string value.
      • asString

        public static java.lang.String asString​(java.util.Map<?,​?> map)
        Make a minimal printable string value from a typed map.
        Parameters:
        map - The map to stringify.
        Returns:
        The resulting string.
      • asString

        public static java.lang.String asString​(java.lang.Object o)
        Make an object into a string using the typed tools here.
        Parameters:
        o - The object to stringify.
        Returns:
        The resulting string.
      • isNullOrEmpty

        public static boolean isNullOrEmpty​(java.lang.String str)
        Parameters:
        str - The string to check.
        Returns:
        If the string is null or empty.
      • isNotEmpty

        public static boolean isNotEmpty​(java.lang.String str)
        Parameters:
        str - The string to check.
        Returns:
        If the string is non-null and not empty.
      • commonPrefix

        public static int commonPrefix​(java.lang.String text1,
                                       java.lang.String text2)
        Determine the common prefix of two strings
        Parameters:
        text1 - First string.
        text2 - Second string.
        Returns:
        The number of characters common to the start of each string.
      • commonSuffix

        public static int commonSuffix​(java.lang.String text1,
                                       java.lang.String text2)
        Determine the common suffix of two strings
        Parameters:
        text1 - First string.
        text2 - Second string.
        Returns:
        The number of characters common to the end of each string.
      • commonOverlap

        public static int commonOverlap​(java.lang.String text1,
                                        java.lang.String text2)
        Determine if the suffix of one string is the prefix of another.
        Parameters:
        text1 - First string.
        text2 - Second string.
        Returns:
        The number of characters common to the end of the first string and the start of the second string.