Class StringUtils

java.lang.Object
com.tyndalehouse.step.core.utils.StringUtils

public final class StringUtils extends Object
To avoid having large libraries, we provide here a small set of methods that can be used to perform various string operations
  • Method Details

    • isEmpty

      public static boolean isEmpty(String s)
      checks for null and zero length
      Parameters:
      s - the string
      Returns:
      true if null or zero length
    • isNotEmpty

      public static boolean isNotEmpty(String s)
      Parameters:
      s - the value to test
      Returns:
      !isEmpty(s), i.e. a non-null string of length >1
    • areAnyBlank

      public static boolean areAnyBlank(String... strings)
      if any of the passed in values are blank, then returns true
      Parameters:
      strings - the list of strings to evaluate
      Returns:
      true if one or more strings are blank
    • isBlank

      public static boolean isBlank(String s)
      checks if a field is blank
      Parameters:
      s - the string to be tested
      Returns:
      true if blank (ie. only whitespace)
    • isNotBlank

      public static boolean isNotBlank(String s)
      Parameters:
      s - the string to evaluate
      Returns:
      !isBlank
    • commaSeparate

      public static String[] commaSeparate(String value)
      Uses a pre-compiled regular expression to comma separate - maybe a tad overkill
      Parameters:
      value - the string to be split up
      Returns:
      the array of strings containing the split values
    • split

      public static String[] split(String value)
      Splits by space
      Parameters:
      value - the value to split
      Returns:
      the array of split values
    • split

      public static String[] split(String value, String patternRegex)
      Parameters:
      value - the value to split
      patternRegex - the delimiter regex
      Returns:
      the array of split values
    • containsAlphaNumeric

      public static boolean containsAlphaNumeric(String s)
      Parameters:
      s - the string to evaluate
      Returns:
      true to indicate only alpha numerics have been found
    • createSet

      public static Set<String> createSet(String wordList)
      Creates a list from the String of words given, in upper case form.
      Parameters:
      wordList - the list of words as 1 String
      Returns:
      the set of words
    • createSet

      public static Set<String> createSet(String wordList, boolean removeDiacritics)
      Creates a list from the String of words given, in upper case form.
      Parameters:
      wordList - the list of words as 1 String
      removeDiacritics - remove any decoration of texts, such as accents, and the like
      Returns:
      the set of words
    • toTitleCase

      public static String toTitleCase(String input, boolean eachWord)
      Parameters:
      input - the string input
      eachWord - true to indicate each word should be put into title case
      Returns:
      the string capitalized
    • join

      public static String join(String[] strings)
      Joins strings together, separated by a comma
      Parameters:
      strings - the strings in question
      Returns:
      the concatenated version of the array
    • join

      public static String join(String[] strings, char separator)
      Joins strings together, separated by a comma
      Parameters:
      strings - the strings in question
      Returns:
      the concatenated version of the array
    • join

      public static String join(String[] strings, int startFrom)
      Joins strings together, separated by a comma
      Parameters:
      strings - the strings in question
      startFrom - whether to ignore some
      Returns:
      the concatenated version of the array
    • join

      public static String join(String[] strings, int startFrom, char separator)
    • countMatches

      public static int countMatches(String str, String sub)

      Counts how many times the substring appears in the larger String.

      A null or empty ("") String input returns 0.

       StringUtils.countMatches(null, *)       = 0
       StringUtils.countMatches("", *)         = 0
       StringUtils.countMatches("abba", null)  = 0
       StringUtils.countMatches("abba", "")    = 0
       StringUtils.countMatches("abba", "a")   = 2
       StringUtils.countMatches("abba", "ab")  = 1
       StringUtils.countMatches("abba", "xxx") = 0
       
      Parameters:
      str - the String to check, may be null
      sub - the substring to count, may be null
      Returns:
      the number of occurrences, 0 if either String is null
    • getNonNullString

      public static String getNonNullString(String value, String defaultValue)
    • cleanJSwordRestriction

      public static String cleanJSwordRestriction(String mainRange)
    • trim

      public static String trim(String input)