Class StringUtil


  • public class StringUtil
    extends java.lang.Object
    Collection of string utilities.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String EMPTY_STRING  
    • Constructor Summary

      Constructors 
      Constructor Description
      StringUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String buildQualifiedReference​(java.lang.String namespace, java.lang.String value)
      Builds the qualified reference value.
      static java.lang.String doubleToString​(double d, int fNumber)
      Converts the double value to locale-independent string representation.
      static java.lang.String doubleToString​(double d, int fNumber, com.ibm.icu.util.ULocale locale)
      Converts the double value to locale-dependent string representation.
      static java.lang.String extractFileName​(java.lang.String filePathName)
      Extract file name (without path and suffix) from file name with path and suffix.
      static java.lang.String extractFileNameWithSuffix​(java.lang.String filePathName)
      Extract file name (without path but with suffix) from file name with path and suffix.
      static java.lang.String extractName​(java.lang.String qualifiedName)
      Extracts the name from the given qualified reference value.
      static java.lang.String extractNamespace​(java.lang.String qualifiedName)
      Extracts the libaray namespace from the given qualified reference value.
      static boolean isBlank​(java.lang.String str)
      Reports if a string is blank.
      static boolean isEmpty​(java.lang.String value)
      Reports if a string is empty.
      static boolean isEqual​(java.lang.String str1, java.lang.String str2)
      Returns if the two string are null or equal.
      static boolean isEqualIgnoreCase​(java.lang.String str1, java.lang.String str2)
      Returns if the two string are null or equal.
      static boolean isValidLocale​(java.lang.String locale)
      Check if the locale string is a valid locale format, with the language, country and variant separated by underbars.
      static DimensionValue parse​(java.lang.String value)
      Parses a dimension string in locale-independent way.
      static DimensionValue parseInput​(java.lang.String value, com.ibm.icu.util.ULocale locale)
      Parses a dimension string in locale-dependent way.
      static java.lang.String toRgbText​(int rgb)
      Convert an integer to an HTML RGB value.
      static java.lang.String trimQuotes​(java.lang.String value)
      Trims the quotes.
      static java.lang.String trimString​(java.lang.String value)
      Trim a string.
      • Methods inherited from class java.lang.Object

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

      • StringUtil

        public StringUtil()
    • Method Detail

      • trimString

        public static java.lang.String trimString​(java.lang.String value)
        Trim a string. Removes leading and trailing blanks. If the resulting string is empty, normalizes the string to an null string.
        Parameters:
        value - the string to trim
        Returns:
        the trimmed string, or null if the string is empty
      • toRgbText

        public static java.lang.String toRgbText​(int rgb)
        Convert an integer to an HTML RGB value. The result is of the form #hhhhhh. The input rgb integer value will be clipped into the range 0 ~ 0xFFFFFF
        Parameters:
        rgb - the integer RGB value
        Returns:
        the value as an HTML RGB string
      • isValidLocale

        public static boolean isValidLocale​(java.lang.String locale)
        Check if the locale string is a valid locale format, with the language, country and variant separated by underbars.

        The language argument is a valid ISO Language Code. . These codes are the lower-case, two-letter codes.

        The country argument is a valid ISO Country Code. These codes are the upper-case, two-letter codes.

        If the language is missing, the string should begin with an underbar. (Can't have a locale with just a variant -- the variant must accompany a valid language or country code). Examples: "en", "de_DE", "_GB", "en_US_WIN", "de__POSIX", "fr__MAC"

        Parameters:
        locale - string representing a locale
        Returns:
        true if the locale is a valid locale, false if the locale is not valid.
      • isBlank

        public static boolean isBlank​(java.lang.String str)
        Reports if a string is blank. A string is considered blank either if it is null, is an empty string, of consists entirely of white space.

        For example,

        • null, "" and " " are blank strings
        Parameters:
        str - the string to check
        Returns:
        true if the string is blank, false otherwise.
      • isEmpty

        public static boolean isEmpty​(java.lang.String value)
        Reports if a string is empty. A string is considered empty either if it is null, is an empty string.

        For example,

        • Both null and "" are empty strings
        • " " is not empty string.
        Parameters:
        value - the string to check
        Returns:
        true if the string is empty, false otherwise.
      • isEqual

        public static boolean isEqual​(java.lang.String str1,
                                      java.lang.String str2)
        Returns if the two string are null or equal. The java.lang.String#equals(String)is used to compare two strings.
        Parameters:
        str1 - the string to compare
        str2 - the string to compare
        Returns:
        true, if the two string are null, or the two string are equal with case sensitive.
      • isEqualIgnoreCase

        public static boolean isEqualIgnoreCase​(java.lang.String str1,
                                                java.lang.String str2)
        Returns if the two string are null or equal. The String.equalsIgnoreCase(String)is used to compare two strings.
        Parameters:
        str1 - the string to compare
        str2 - the string to compare
        Returns:
        true, if the two string are null, or the two string are equal with case sensitive.
      • doubleToString

        public static java.lang.String doubleToString​(double d,
                                                      int fNumber)
        Converts the double value to locale-independent string representation. This method works like Double.toString( double ), and can also handle very large number like 1.234567890E16 to "12345678900000000".
        Parameters:
        d - the double value to convert
        fNumber - the positive maximum fractional number
        Returns:
        the locale-independent string representation.
      • doubleToString

        public static java.lang.String doubleToString​(double d,
                                                      int fNumber,
                                                      com.ibm.icu.util.ULocale locale)
        Converts the double value to locale-dependent string representation.
        Parameters:
        d - the double value to convert
        fNumber - the positive maximum fractional number
        locale -
        Returns:
        the locale-dependent string representation.
      • parse

        public static DimensionValue parse​(java.lang.String value)
                                    throws PropertyValueException
        Parses a dimension string in locale-independent way. The input string must match the following:
        • null
        • [1-9][0-9]*[.[0-9]*[ ]*[in|cm|mm|pt|pc|em|ex|px|%]]
        Parameters:
        value - the dimension string to parse
        Returns:
        a dimension object representing the dimension string.
        Throws:
        PropertyValueException - if the string is not valid
      • parseInput

        public static DimensionValue parseInput​(java.lang.String value,
                                                com.ibm.icu.util.ULocale locale)
                                         throws PropertyValueException
        Parses a dimension string in locale-dependent way. The input can be in localized value. The measure part use the decimal separator from the locale. e,g. "123,456.78" for English ; "123.456,78" for German.

        The string must match the following:

        • null
        • [1-9][0-9]*[.[0-9]*[ ]*[u]], u is the one of the allowed units

        Parameters:
        value - the string to parse
        locale - the locale where the input string resides
        Returns:
        a dimension object
        Throws:
        PropertyValueException - if the string is not valid
      • extractFileName

        public static java.lang.String extractFileName​(java.lang.String filePathName)
        Extract file name (without path and suffix) from file name with path and suffix.

        For example:

        • "c:\home\abc.xml" => "abc"
        • "c:\home\abc" => "abc"
        • "/home/user/abc.xml" => "abc"
        • "/home/user/abc" => "abc"
        Parameters:
        filePathName - the file name with path and suffix
        Returns:
        the file name without path and suffix
      • extractFileNameWithSuffix

        public static java.lang.String extractFileNameWithSuffix​(java.lang.String filePathName)
        Extract file name (without path but with suffix) from file name with path and suffix.

        For example:

        • "c:\home\abc.xml" => "abc.xml"
        • "c:\home\abc" => "abc"
        • "/home/user/abc.xml" => "abc.xml"
        • "/home/user/abc" => "abc"
        Parameters:
        filePathName - the file name with path and suffix
        Returns:
        the file name without path but with suffix
      • extractNamespace

        public static java.lang.String extractNamespace​(java.lang.String qualifiedName)
        Extracts the libaray namespace from the given qualified reference value.

        For example,

        • "LibA" is extracted from "LibA.style1"
        • null is returned from "style1"
        Parameters:
        qualifiedName - the qualified reference value
        Returns:
        the library namespace
      • extractName

        public static java.lang.String extractName​(java.lang.String qualifiedName)
        Extracts the name from the given qualified reference value.

        For example,

        • "style1" is extracted from "LibA.style1"
        • "style1" is returned from "style1"
        Parameters:
        qualifiedName - the qualified reference value
        Returns:
        the name
      • buildQualifiedReference

        public static java.lang.String buildQualifiedReference​(java.lang.String namespace,
                                                               java.lang.String value)
        Builds the qualified reference value.

        For example,

        • ("LibA", "style1") => "LibA.style1"
        • (" ", "style1) => "style1"
        Parameters:
        namespace - the library namespace to indicate which library the reference is using.
        value - the actual reference value
        Returns:
        the qualified reference value
      • trimQuotes

        public static java.lang.String trimQuotes​(java.lang.String value)
        Trims the quotes.

        For example,

        • ("a.b") => a.b
        • ("a.b) => "a.b
        • (a.b") => a.b"
        Parameters:
        value - the string may have quotes
        Returns:
        the string without quotes