Class StringUtils


  • public class StringUtils
    extends java.lang.Object
    Provides static helper functions for string manipulation.
    • Constructor Summary

      Constructors 
      Constructor Description
      StringUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String capitalizeFirstLetter​(java.lang.String s)
      Convert the first letter of a string to Upper-Case.
      static boolean matchesFloatPattern​(java.lang.String string)
      Checks if the given string matches an Float pattern, i.e.
      static boolean matchesIntegerPattern​(java.lang.String string)
      Checks if the given string matches an Integer pattern, i.e.
      static int matchWildcard​(java.lang.String source, java.lang.String pattern)
      Match two Strings, considering wildcards.
      static java.lang.String toShortString​(com.google.gson.JsonElement j, int length)
      Shortens a JsonElement string representation to a given length.
      static java.lang.String toShortString​(java.lang.String s, int length)
      Shortens a string to a given length.
      • Methods inherited from class java.lang.Object

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

      • StringUtils

        public StringUtils()
    • Method Detail

      • toShortString

        public static java.lang.String toShortString​(java.lang.String s,
                                                     int length)
        Shortens a string to a given length.

        Example: converts a string "hello world" to "hello w..."

        Parameters:
        s - the string
        length - the target string length
        Returns:
        the shortened string
      • toShortString

        public static java.lang.String toShortString​(com.google.gson.JsonElement j,
                                                     int length)
        Shortens a JsonElement string representation to a given length.

        Example: converts a "{ 'foo': 'bar' }" to "{ 'foo': '..."

        Parameters:
        j - the JsonElement
        length - the target string length
        Returns:
        the shortened string
      • capitalizeFirstLetter

        public static java.lang.String capitalizeFirstLetter​(java.lang.String s)
        Convert the first letter of a string to Upper-Case.

        Example: converts "hello world" to "Hello world"

        Parameters:
        s - the string
        Returns:
        the converted string
      • matchWildcard

        public static int matchWildcard​(java.lang.String source,
                                        java.lang.String pattern)
        Match two Strings, considering wildcards.
        • if Object.equals(Object) is true -> return 0
        • if 'pattern' matches 'source' -> return value > 1; bigger values represent a better match
        • if both Strings do not match -> return -1

        Implementation note: only one wildcard is considered. Either the entire string is "*" or the wildcard is at the beginning or at the end of the pattern String. The the JUnit test for details.

        Parameters:
        source - the String to be evaluated
        pattern - the pattern String, i.e. "meter*"
        Returns:
        an integer value representing the degree of matching
      • matchesIntegerPattern

        public static boolean matchesIntegerPattern​(java.lang.String string)
        Checks if the given string matches an Integer pattern, i.e. if could be parsed to Integer/Long.
        Parameters:
        string - a string
        Returns:
        true if it matches Integer
      • matchesFloatPattern

        public static boolean matchesFloatPattern​(java.lang.String string)
        Checks if the given string matches an Float pattern, i.e. if could be parsed to Float/Double.
        Parameters:
        string - a string
        Returns:
        true if it matches Float