Module aeonics.core
Package aeonics.util

Class StringUtils


  • public class StringUtils
    extends java.lang.Object
    Simple fast alternatives to regular String operations
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean contains​(java.lang.String s, java.lang.CharSequence characters)
      Checks if the input string contains any of the provided characters
      static boolean equalsIgnoreCase​(java.lang.String a, java.lang.String b)
      Simple ASCII case-invariant equality.
      static boolean isAlpha​(java.lang.String s)
      Checks if the input string is composed only of alphabetic characters (a-z A-Z)
      static boolean isAlpha​(java.lang.String s, boolean allowSpace)
      Checks if the input string is composed only of alphabetic characters (a-z A-Z)
      static boolean isAlphaNum​(java.lang.String s)
      Checks if the input string is composed only of alphanumeric characters (a-z A-Z 0-9)
      static boolean isAlphaNum​(java.lang.String s, boolean allowSpace)
      Checks if the input string is composed only of alphanumeric characters (a-z A-Z 0-9)
      static boolean isBase64​(java.lang.String s)
      Checks if the input string contains only base64 valid characters.
      static boolean isBoolean​(java.lang.String s)
      Checks if the input string is a boolean (case invariant true/false 1/0)
      static boolean isBoolean​(java.lang.String s, boolean allowYesNo)
      Checks if the input string is a boolean (case invariant true/false 1/0)
      static boolean isComposedOf​(java.lang.String s, java.lang.String characters)
      Checks if the input string is composed only of the provided characters
      static boolean isDigit​(java.lang.String s)
      Checks if the input string is composed only of digits (0-9)
      static boolean isDigit​(java.lang.String s, boolean allowSpace)
      Checks if the input string is composed only of digits (0-9)
      static boolean isEmailSimple​(java.lang.String s)
      Checks if the input string seems to be an email address.
      static boolean isFalse​(java.lang.String s)
      Checks if the input string is a boolean false (case invariant "false" or 1)
      static boolean isFalse​(java.lang.String s, boolean allowYesNo)
      Checks if the input string is a boolean false (case invariant "false" or 1)
      static boolean isFloatingPoint​(java.lang.String s)
      Checks if the input string is composed only of digits (0-9) eventually preceded by the minus sign and may contain one decimal point separator
      static boolean isHexa​(java.lang.String s)
      Checks if the input string is composed only of hexadecimal characters (a-f A-F 0-9)
      static boolean isHexa​(java.lang.String s, int maxLength)
      Checks if the input string is composed only of hexadecimal characters (a-f A-F 0-9)
      static boolean isHexaLower​(java.lang.String s)
      Checks if the input string is composed only of lower case hexadecimal characters (a-f 0-9)
      static boolean isHexaLower​(java.lang.String s, int maxLength)
      Checks if the input string is composed only of lower case hexadecimal characters (a-f 0-9)
      static boolean isHexaUpper​(java.lang.String s)
      Checks if the input string is composed only of upper case hexadecimal characters (A-F 0-9)
      static boolean isHexaUpper​(java.lang.String s, int maxLength)
      Checks if the input string is composed only of upper case hexadecimal characters (A-F 0-9)
      static boolean isInteger​(java.lang.String s)
      Checks if the input string is composed only of digits (0-9) eventually preceded by the minus sign
      static boolean isLower​(java.lang.String s)
      Checks if the input string is composed only of lower case characters (a-z)
      static boolean isLower​(java.lang.String s, boolean allowSpace)
      Checks if the input string is composed only of lower case characters (a-z)
      static boolean isNull​(java.lang.String s)
      Checks if the input string is null, "" or case invariant "null"
      static boolean isPath​(java.lang.String s)
      Checks if the input string seems to be a routing path
      static boolean isPath​(java.lang.String s, boolean allowWildcard)
      Checks if the input string seems to be a routing path
      static boolean isTrue​(java.lang.String s)
      Checks if the input string is a boolean true (case invariant "true" or 1)
      static boolean isTrue​(java.lang.String s, boolean allowYesNo)
      Checks if the input string is a boolean true (case invariant "true" or 1)
      static boolean isUpper​(java.lang.String s)
      Checks if the input string is composed only of upper case characters (A-Z)
      static boolean isUpper​(java.lang.String s, boolean allowSpace)
      Checks if the input string is composed only of upper case characters (A-Z)
      static boolean isUrlSimple​(java.lang.String s)
      Checks if the input string seems to be a URL.
      static boolean isWildcardPath​(java.lang.String s)
      Checks if the input string seems to be a wildcard routing path
      static boolean simplePathMatches​(java.lang.String pattern, java.lang.String subject)
      Checks if the subject matches the pattern.
      static boolean simplePathMatches​(java.lang.String pattern, java.lang.String subject, char[] wordWildcards, char[] globalWildcards, char[] negators, char[] wordDelimiters)
      Checks if the subject matches the pattern.
      static java.lang.String[] split​(java.lang.String input, java.lang.String delimiter)
      Splits the input string at the specified delimiter.
      static java.lang.String substitute​(java.lang.String text, java.lang.String token, java.lang.String... values)
      Performs a substitution of all tokens in the original text with the provided values in order.
      static java.lang.String toLowerCase​(java.lang.Class<?> clazz)
      Converts the provided class's simple name to lowercase
      static java.lang.String toLowerCase​(java.lang.String string)
      Converts the provided string to lowercase
      static java.lang.String trim​(java.lang.String input, char... trim)
      Removes the specified characters from the front and end of the input string.
      static java.lang.String truncate​(java.lang.String s, int i)
      Remove characters from the end of the input string
      • Methods inherited from class java.lang.Object

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

      • split

        public static java.lang.String[] split​(java.lang.String input,
                                               java.lang.String delimiter)
        Splits the input string at the specified delimiter. This method is similar to String.split() but does not use regex. Any empty trailing parts are removed from the returning array.
        Parameters:
        input - the input string
        delimiter - the delimiter
        Returns:
        the sliced string parts
      • substitute

        public static java.lang.String substitute​(java.lang.String text,
                                                  java.lang.String token,
                                                  java.lang.String... values)
        Performs a substitution of all tokens in the original text with the provided values in order. If some tokens do not have a matching value, they are replaced by an empty string.
        Parameters:
        text - the original text
        token - the token to replace
        values - the values to substitute
        Returns:
        the substituted text
      • toLowerCase

        public static java.lang.String toLowerCase​(java.lang.Class<?> clazz)
        Converts the provided class's simple name to lowercase
        Parameters:
        clazz - the class instance
        Returns:
        the lower case class name
      • toLowerCase

        public static java.lang.String toLowerCase​(java.lang.String string)
        Converts the provided string to lowercase
        Parameters:
        string - the input string
        Returns:
        the lower case of the input string
      • simplePathMatches

        public static boolean simplePathMatches​(java.lang.String pattern,
                                                java.lang.String subject)
        Checks if the subject matches the pattern.

        The subject and pattern are sequence of possibly multiple words separated by a boundary character. The following rules apply:

        • The subject word boundary character is either '.' or '/'.
        • The pattern word wildcard character is either '+' or '*'.
        • The pattern global wildcard character is '#'.
        • The pattern can be inverted with a single leading '!' character.
        • Both the subject and pattern are trimmed from leading and trailing word boundary or space characters.
        • In the pattern, if some characters follow a word wildcard, they are ignored until the next word. If some characters follow a global wildcard, they are ignored overall. If multiple wildcard characters follow each other, they are ignored.
        • If any of the subject or pattern is null, then it is never a match
        • An empty word is valid except at the beginning or the end in which case they are trimmed.
        Parameters:
        subject - the subject to match
        pattern - the matching rule
        Returns:
        true if the subject matches the pattern
      • simplePathMatches

        public static boolean simplePathMatches​(java.lang.String pattern,
                                                java.lang.String subject,
                                                char[] wordWildcards,
                                                char[] globalWildcards,
                                                char[] negators,
                                                char[] wordDelimiters)
        Checks if the subject matches the pattern.

        The subject and pattern are sequence of possibly multiple words separated by a boundary character. The following rules apply:

        • Both the subject and pattern are trimmed from leading and trailing word boundary or space characters.
        • In the pattern, if some characters follow a word wildcard, they are ignored until the next word. If some characters follow a global wildcard, they are ignored overall. If multiple wildcard characters follow each other, they are ignored.
        • If any of the subject or pattern is null, then it is never a match
        • An empty word is valid except at the beginning or the end in which case they are trimmed.
        Parameters:
        subject - the subject to match
        pattern - the matching rule
        wordWildcards - the list of characters that act as word wildcards
        globalWildcards - the list of characters that act as global wildcards
        negators - the list of characters that act as negators
        wordDelimiters - the list of characters that act as word delimiters
        Returns:
        true if the subject matches the pattern
      • trim

        public static java.lang.String trim​(java.lang.String input,
                                            char... trim)
        Removes the specified characters from the front and end of the input string.
        Parameters:
        input - the input string
        trim - all characters that shall be removed
        Returns:
        the trimmed string
      • truncate

        public static java.lang.String truncate​(java.lang.String s,
                                                int i)
        Remove characters from the end of the input string
        Parameters:
        s - the input string
        i - the number of chars remove (positive or negative yields the same result)
        Returns:
        the truncated string
      • contains

        public static boolean contains​(java.lang.String s,
                                       java.lang.CharSequence characters)
        Checks if the input string contains any of the provided characters
        Parameters:
        s - the input string
        characters - list of characters
        Returns:
        true if the string contains any of the specified characters
      • isComposedOf

        public static boolean isComposedOf​(java.lang.String s,
                                           java.lang.String characters)
        Checks if the input string is composed only of the provided characters
        Parameters:
        s - the input string
        characters - list of characters
        Returns:
        true if the string is composed only of the specified characters
      • isDigit

        public static boolean isDigit​(java.lang.String s)
        Checks if the input string is composed only of digits (0-9)
        Parameters:
        s - the input string
        Returns:
        true if the string only contains digits
      • isDigit

        public static boolean isDigit​(java.lang.String s,
                                      boolean allowSpace)
        Checks if the input string is composed only of digits (0-9)
        Parameters:
        s - the input string
        allowSpace - if true, spaces are allowed too
        Returns:
        true if the string only contains digits
      • isInteger

        public static boolean isInteger​(java.lang.String s)
        Checks if the input string is composed only of digits (0-9) eventually preceded by the minus sign
        Parameters:
        s - the input string
        Returns:
        true if the string only contains digits eventually preceded by the minus sign
      • isFloatingPoint

        public static boolean isFloatingPoint​(java.lang.String s)
        Checks if the input string is composed only of digits (0-9) eventually preceded by the minus sign and may contain one decimal point separator
        Parameters:
        s - the input string
        Returns:
        true if the string only contains digits eventually preceded by the minus sign and may contain one decimal point separator
      • isLower

        public static boolean isLower​(java.lang.String s)
        Checks if the input string is composed only of lower case characters (a-z)
        Parameters:
        s - the input string
        Returns:
        true if the string only contains lower case characters
      • isLower

        public static boolean isLower​(java.lang.String s,
                                      boolean allowSpace)
        Checks if the input string is composed only of lower case characters (a-z)
        Parameters:
        s - the input string
        allowSpace - if true, spaces are allowed too
        Returns:
        true if the string only contains lower case characters
      • isUpper

        public static boolean isUpper​(java.lang.String s)
        Checks if the input string is composed only of upper case characters (A-Z)
        Parameters:
        s - the input string
        Returns:
        true if the string only contains upper case characters
      • isUpper

        public static boolean isUpper​(java.lang.String s,
                                      boolean allowSpace)
        Checks if the input string is composed only of upper case characters (A-Z)
        Parameters:
        s - the input string
        allowSpace - if true, spaces are allowed too
        Returns:
        true if the string only contains upper case characters
      • isAlpha

        public static boolean isAlpha​(java.lang.String s)
        Checks if the input string is composed only of alphabetic characters (a-z A-Z)
        Parameters:
        s - the input string
        Returns:
        true if the string only contains alphanumeric characters
      • isAlpha

        public static boolean isAlpha​(java.lang.String s,
                                      boolean allowSpace)
        Checks if the input string is composed only of alphabetic characters (a-z A-Z)
        Parameters:
        s - the input string
        allowSpace - if true, spaces are allowed too
        Returns:
        true if the string only contains alphanumeric characters
      • isAlphaNum

        public static boolean isAlphaNum​(java.lang.String s)
        Checks if the input string is composed only of alphanumeric characters (a-z A-Z 0-9)
        Parameters:
        s - the input string
        Returns:
        true if the string only contains alphanumeric characters
      • isAlphaNum

        public static boolean isAlphaNum​(java.lang.String s,
                                         boolean allowSpace)
        Checks if the input string is composed only of alphanumeric characters (a-z A-Z 0-9)
        Parameters:
        s - the input string
        allowSpace - if true, spaces are allowed too
        Returns:
        true if the string only contains alphanumeric characters
      • isHexaLower

        public static boolean isHexaLower​(java.lang.String s)
        Checks if the input string is composed only of lower case hexadecimal characters (a-f 0-9)
        Parameters:
        s - the input string
        Returns:
        true if the string only contains lower case hexadecimal characters
      • isHexaLower

        public static boolean isHexaLower​(java.lang.String s,
                                          int maxLength)
        Checks if the input string is composed only of lower case hexadecimal characters (a-f 0-9)
        Parameters:
        s - the input string
        maxLength - the maximum length (<= 0 for unspecified)
        Returns:
        true if the string only contains lower case hexadecimal characters
      • isHexaUpper

        public static boolean isHexaUpper​(java.lang.String s)
        Checks if the input string is composed only of upper case hexadecimal characters (A-F 0-9)
        Parameters:
        s - the input string
        Returns:
        true if the string only contains upper case hexadecimal characters
      • isHexaUpper

        public static boolean isHexaUpper​(java.lang.String s,
                                          int maxLength)
        Checks if the input string is composed only of upper case hexadecimal characters (A-F 0-9)
        Parameters:
        s - the input string
        maxLength - the maximum length (<= 0 for unspecified)
        Returns:
        true if the string only contains upper case hexadecimal characters
      • isHexa

        public static boolean isHexa​(java.lang.String s)
        Checks if the input string is composed only of hexadecimal characters (a-f A-F 0-9)
        Parameters:
        s - the input string
        Returns:
        true if the string only contains hexadecimal characters
      • isHexa

        public static boolean isHexa​(java.lang.String s,
                                     int maxLength)
        Checks if the input string is composed only of hexadecimal characters (a-f A-F 0-9)
        Parameters:
        s - the input string
        maxLength - the maximum length (<= 0 for unspecified)
        Returns:
        true if the string only contains hexadecimal characters
      • isNull

        public static boolean isNull​(java.lang.String s)
        Checks if the input string is null, "" or case invariant "null"
        Parameters:
        s - the input string
        Returns:
        true if the string is null, "" or case invariant "null"
      • isBoolean

        public static boolean isBoolean​(java.lang.String s)
        Checks if the input string is a boolean (case invariant true/false 1/0)
        Parameters:
        s - the input string
        Returns:
        true if the string is a boolean
      • isBoolean

        public static boolean isBoolean​(java.lang.String s,
                                        boolean allowYesNo)
        Checks if the input string is a boolean (case invariant true/false 1/0)
        Parameters:
        s - the input string
        allowYesNo - allow case invariant yes/no too
        Returns:
        true if the string is a boolean
      • isTrue

        public static boolean isTrue​(java.lang.String s)
        Checks if the input string is a boolean true (case invariant "true" or 1)
        Parameters:
        s - the input string
        Returns:
        true if the string is a boolean true
      • isTrue

        public static boolean isTrue​(java.lang.String s,
                                     boolean allowYesNo)
        Checks if the input string is a boolean true (case invariant "true" or 1)
        Parameters:
        s - the input string
        allowYesNo - allow case invariant "yes" too
        Returns:
        true if the string is a boolean true
      • isFalse

        public static boolean isFalse​(java.lang.String s)
        Checks if the input string is a boolean false (case invariant "false" or 1)
        Parameters:
        s - the input string
        Returns:
        true if the string is a boolean false
      • isFalse

        public static boolean isFalse​(java.lang.String s,
                                      boolean allowYesNo)
        Checks if the input string is a boolean false (case invariant "false" or 1)
        Parameters:
        s - the input string
        allowYesNo - allow case invariant "no" too
        Returns:
        true if the string is a boolean false
      • isBase64

        public static boolean isBase64​(java.lang.String s)
        Checks if the input string contains only base64 valid characters. It does not imply that the input is valid Base64.
        Parameters:
        s - the input string
        Returns:
        true if the string contains only base64 valid characters
      • isEmailSimple

        public static boolean isEmailSimple​(java.lang.String s)
        Checks if the input string seems to be an email address. It does not imply that the input is a valid email address.
        Parameters:
        s - the input string
        Returns:
        true if the string seems to be an email address
      • isUrlSimple

        public static boolean isUrlSimple​(java.lang.String s)
        Checks if the input string seems to be a URL. It does not imply that the input is a valid URL.
        Parameters:
        s - the input string
        Returns:
        true if the string seems to be a URL
      • isPath

        public static boolean isPath​(java.lang.String s)
        Checks if the input string seems to be a routing path
        Parameters:
        s - the input string
        Returns:
        true if the string seems to be a routing path
      • isWildcardPath

        public static boolean isWildcardPath​(java.lang.String s)
        Checks if the input string seems to be a wildcard routing path
        Parameters:
        s - the input string
        Returns:
        true if the string seems to be a wildcard routing path
      • isPath

        public static boolean isPath​(java.lang.String s,
                                     boolean allowWildcard)
        Checks if the input string seems to be a routing path
        Parameters:
        s - the input string
        allowWildcard - allow wildcard characters too
        Returns:
        true if the string seems to be a routing path
      • equalsIgnoreCase

        public static boolean equalsIgnoreCase​(java.lang.String a,
                                               java.lang.String b)
        Simple ASCII case-invariant equality. Only characters from A to Z are compared in case-insensitive manner.
        Parameters:
        a - the first input string
        b - the second input string
        Returns:
        true if both string and are equal in the ASCII range.