Package com.tyndalehouse.step.core.utils
Class StringUtils
java.lang.Object
com.tyndalehouse.step.core.utils.StringUtils
To avoid having large libraries, we provide here a small set of methods that can be used to perform various
string operations
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
areAnyBlank
(String... strings) if any of the passed in values are blank, then returns truestatic String
cleanJSwordRestriction
(String mainRange) static String[]
commaSeparate
(String value) Uses a pre-compiled regular expression to comma separate - maybe a tad overkillstatic boolean
static int
countMatches
(String str, String sub) Counts how many times the substring appears in the larger String.Creates a list from the String of words given, in upper case form.Creates a list from the String of words given, in upper case form.static String
getNonNullString
(String value, String defaultValue) static boolean
checks if a field is blankstatic boolean
checks for null and zero lengthstatic boolean
isNotBlank
(String s) static boolean
isNotEmpty
(String s) static String
Joins strings together, separated by a commastatic String
Joins strings together, separated by a commastatic String
Joins strings together, separated by a commastatic String
static String[]
Splits by spacestatic String[]
static String
toTitleCase
(String input, boolean eachWord) static String
-
Method Details
-
isEmpty
checks for null and zero length- Parameters:
s
- the string- Returns:
- true if null or zero length
-
isNotEmpty
- Parameters:
s
- the value to test- Returns:
- !isEmpty(s), i.e. a non-null string of length >1
-
areAnyBlank
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
checks if a field is blank- Parameters:
s
- the string to be tested- Returns:
- true if blank (ie. only whitespace)
-
isNotBlank
- Parameters:
s
- the string to evaluate- Returns:
- !isBlank
-
commaSeparate
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
Splits by space- Parameters:
value
- the value to split- Returns:
- the array of split values
-
split
- Parameters:
value
- the value to splitpatternRegex
- the delimiter regex- Returns:
- the array of split values
-
containsAlphaNumeric
- Parameters:
s
- the string to evaluate- Returns:
- true to indicate only alpha numerics have been found
-
createSet
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
Creates a list from the String of words given, in upper case form.- Parameters:
wordList
- the list of words as 1 StringremoveDiacritics
- remove any decoration of texts, such as accents, and the like- Returns:
- the set of words
-
toTitleCase
- Parameters:
input
- the string inputeachWord
- true to indicate each word should be put into title case- Returns:
- the string capitalized
-
join
Joins strings together, separated by a comma- Parameters:
strings
- the strings in question- Returns:
- the concatenated version of the array
-
join
Joins strings together, separated by a comma- Parameters:
strings
- the strings in question- Returns:
- the concatenated version of the array
-
join
Joins strings together, separated by a comma- Parameters:
strings
- the strings in questionstartFrom
- whether to ignore some- Returns:
- the concatenated version of the array
-
join
-
countMatches
Counts how many times the substring appears in the larger String.
A
null
or empty ("") String input returns0
.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 nullsub
- the substring to count, may be null- Returns:
- the number of occurrences, 0 if either String is
null
-
getNonNullString
-
cleanJSwordRestriction
-
trim
-