Class StringUtils


  • public class StringUtils
    extends Object
    This class provides a set of string utility methods.
    Author:
    Michele Mostarda (mostarda@fbk.eu)
    • Method Detail

      • join

        public static String join​(String delimiter,
                                  String... data)
        Joins the given input sting data list using the specified delimiter.
        Parameters:
        delimiter - string delimiter.
        data - list of data to be joined.
        Returns:
        the joined string.
      • countOccurrences

        public static int countOccurrences​(String container,
                                           String content)
        Counts how many times content appears within container without string overlapping.
        Parameters:
        container - container string.
        content - content string.
        Returns:
        occurrences count.
      • countNL

        public static int countNL​(String in)
        Counts the number of NL in the given in string.
        Parameters:
        in - input string.
        Returns:
        the number of new line chars.
      • isPrefix

        public static boolean isPrefix​(String candidatePrefix,
                                       String container)
        Check whether string candidatePrefix is prefix of string container.
        Parameters:
        candidatePrefix - prefix to check
        container - container to check against
        Returns:
        true if candidatePrefix is prefix of container, false otherwise.
      • isSuffix

        public static boolean isSuffix​(String candidateSuffix,
                                       String container)
        Check whether string candidateSuffix is suffix of string container.
        Parameters:
        candidateSuffix - suffix to check
        container - container to check against
        Returns:
        true if candidateSuffix is prefix of container, false otherwise.
      • escapeDoubleQuotes

        public static String escapeDoubleQuotes​(String in)
        Escapes all the unescaped double quotes when needed.
        Parameters:
        in - input string.
        Returns:
        unescaped output.
      • escapeAsJSONString

        public static String escapeAsJSONString​(String in)
        Escapes the in string as JSON string to let it being embeddable within a string field.
        Parameters:
        in - string to be escaped.
        Returns:
        escaped string.
      • multiply

        public static String multiply​(char c,
                                      int times)
        Builds a string composed of the given char c n times.
        Parameters:
        c - char to be multiplied.
        times - number of times.
        Returns:
        the string containing the multiplied char.
      • implementJavaNaming

        public static String implementJavaNaming​(String in)
        Changes string with following convention:
        • Changes '-' -> '_'
        • remove space characters and make first letter word uppercase: 'some string' -> 'someString'
        If input string does not contains a whitespace than return unchanged.
        Parameters:
        in - an input string to convert to Java code convention
        Returns:
        the correctly formatter string as per Java spec.