Class StringMethods
- java.lang.Object
- 
- org.apache.commons.lang3.StringUtils
- 
- io.toro.martini.StringMethods
 
 
- 
 public final class StringMethods extends StringUtils Exposes utility methods in Apachecommons-lang3'sStringUtilsclass as one-liners.
- 
- 
Field Summary- 
Fields inherited from class org.apache.commons.lang3.StringUtilsCR, EMPTY, LF, SPACE
 
- 
 - 
Constructor SummaryConstructors Constructor Description StringMethods(io.toro.properties.ToroProperties properties)
 - 
Method SummaryAll Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static StringappendPrefix(String prefix, Character separator, String body)Prepends a prefix and a separator to a string, in said order.static StringappendPrefix(String prefix, String separator, String body)Prepends a prefix and a separator to a string, in said order.static booleancontainsAny(CharSequence cs, Collection<? extends CharSequence> searchChars)Checks whether or not the provided string contains any of the substrings specified in the collection.static booleancontainsAny(CharSequence cs, Collection<? extends CharSequence> searchChars, boolean ignoreCase)Checks whether or not the provided string contains any of the substrings specified in the collection.static intcountFinds(Collection<String> strings, String regularExpression)Counts the total number of occurrences of the given regular expression in the entries.static intcountMatches(Collection<String> strings, String regularExpression)Counts the number of entries instringsmatching the regular expressionregularExpression.static Stringdecrypt(String encryptedKey)Deprecated, for removal: This API element is subject to removal in a future version.static Stringdecrypt(String encryptedText, char[] secretKey)Decrypts a Base64-encoded ciphertext using AES-GCM.static Stringellipsize(String str, int maxLength)If the provided string exceeds the provided maximum length, it will be truncated and appended with an ellipsis.static StringencloseString(String str, String startEnclosure, String endEnclosure)Return a string prepended and appended with the provided strings.static Stringencrypt(String plainKey)Deprecated, for removal: This API element is subject to removal in a future version.static Stringencrypt(String text, char[] secretKey)Encrypt a plain text using AES-GCM and encodes to Base64.static StringgenerateRandomSecretKey()Generates a random secret key and encodes it with Base64.static StringgenerateRandomSecretKey(int keySize)Generates a random secret key with a specific key size and encodes it with Base64.static StringgetEnclosedString(String str, String startEnclosure, String endEnclosure, boolean retainEnclosedChar)Get the substring in between two substrings.static booleanhasAMatch(String string, Collection<String> regularExpressions)Check if the given string matches any of the given regular expressions.static StringhumanReadableByteCount(long bytes)static StringhumanReadableByteCount(long bytes, boolean si)Convert provided bytes in words.static Stringimplode(Object val, String separator)Create a string concatenation of the elements of a string array orListof objects.static booleanisEnclosed(String str, String startEnclosure, String endEnclosure)Checks whether or not a string begins and ends with certain substrings.static Stringjoin(Object[] array, String separator, boolean trimElement)Joins the elements of the provided array into a single string containing the provided array of elements.static Stringjoin(String[] strArr, String charSeparator, Function<String,String> entryTransformer)Joins the elements of the provided array into a single string containing the provided array of elements.static StringmartiniPackageJoin(Collection<MartiniPackage> col, String separator)Get the names of the provided packages, and concatenate them into a single string.static StringremoveEnclosingString(String str, String startEnclosure, String endEnclosure)Strip any of a set of characters from the beginning and end of a string.static String[]split(String str, String regex)Splits this string around matches of the given regular expression Note: This method was overridden to prevent accidental usage ofStringUtils.split(String, String)overString.split(String)when used as a one-liner.static StringsplitCamelCase(String s)UsesplitByCharacterTypeCamelCaseto split a given string into tokens and concatenates these tokens via a space.static booleanstartsWithAnyIgnoreCase(CharSequence string, CharSequence... searchStrings)Checks ifstringstarts with any of the items insearchStrings, regardless of letter case.static Stringsubstitute(Object tokenisedObject)Substitutes variables within the given source object with Martini application properties and system property values.static booleansubstituteAsBoolean(Object tokenisedObject)Usessubstitute(Object)to substitute variables in the source object, then checks whether or not the result is equal to true (case insensitive).static intsubstituteAsInt(Object tokenisedObject)Usessubstitute(Object)to substitute variables in the source object, but attempts to parse the result as anint.static intsubstituteAsInt(Object tokenisedObject, int defaultValue)Usessubstitute(Object)to substitute variables in the source object, but attempts to parse the result as anint.static String[]toArray(Object object)Get theString[]representation of the provided object.static String[]tokenizeToStringArray(String str, String delimiter, boolean trimTokens, boolean ignoreEmptyTokens, boolean retainDelimiter)Split the provided string into an array, using the givendelimiteras an indicator of where to split.static String[]tokenizeToStringArray(String str, String delimiter, boolean trimTokens, boolean ignoreEmptyTokens, boolean retainDelimiter, int max)Split the provided string into an array with a maximum length ofmax, using the givendelimiteras an indicator of where to split.static String[]transformEntry(String[] strArr, @NotNull Function<String,String> entryTransformer)Transform each element in the array using the provided function, and then return the transformed array.static StringtrimLeadingChar(String str, String character)Trim a leading substring.static StringtrimTrailingChar(String str, String character)Trim a trailing substring.- 
Methods inherited from class org.apache.commons.lang3.StringUtilsabbreviate, abbreviate, abbreviateMiddle, appendIfMissing, appendIfMissingIgnoreCase, capitalize, center, center, center, chomp, chomp, chop, compare, compare, compareIgnoreCase, compareIgnoreCase, contains, contains, containsAny, containsAny, containsAny, containsIgnoreCase, containsNone, containsNone, containsOnly, containsOnly, containsWhitespace, countMatches, countMatches, defaultIfBlank, defaultIfEmpty, defaultString, defaultString, deleteWhitespace, difference, endsWith, endsWithAny, endsWithIgnoreCase, equals, equalsAny, equalsAnyIgnoreCase, equalsIgnoreCase, getCommonPrefix, getFuzzyDistance, getJaroWinklerDistance, getLevenshteinDistance, getLevenshteinDistance, indexOf, indexOf, indexOf, indexOf, indexOfAny, indexOfAny, indexOfAny, indexOfAnyBut, indexOfAnyBut, indexOfDifference, indexOfDifference, indexOfIgnoreCase, indexOfIgnoreCase, isAllLowerCase, isAllUpperCase, isAlpha, isAlphanumeric, isAlphanumericSpace, isAlphaSpace, isAnyBlank, isAnyEmpty, isAsciiPrintable, isBlank, isEmpty, isNoneBlank, isNoneEmpty, isNotBlank, isNotEmpty, isNumeric, isNumericSpace, isWhitespace, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, joinWith, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexOfAny, lastIndexOfIgnoreCase, lastIndexOfIgnoreCase, lastOrdinalIndexOf, left, leftPad, leftPad, leftPad, length, lowerCase, lowerCase, mid, normalizeSpace, ordinalIndexOf, overlay, prependIfMissing, prependIfMissingIgnoreCase, remove, remove, removeAll, removeEnd, removeEndIgnoreCase, removeFirst, removeIgnoreCase, removePattern, removeStart, removeStartIgnoreCase, repeat, repeat, repeat, replace, replace, replaceAll, replaceChars, replaceChars, replaceEach, replaceEachRepeatedly, replaceFirst, replaceIgnoreCase, replaceIgnoreCase, replaceOnce, replaceOnceIgnoreCase, replacePattern, reverse, reverseDelimited, right, rightPad, rightPad, rightPad, rotate, split, split, split, splitByCharacterType, splitByCharacterTypeCamelCase, splitByWholeSeparator, splitByWholeSeparator, splitByWholeSeparatorPreserveAllTokens, splitByWholeSeparatorPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, startsWith, startsWithAny, startsWithIgnoreCase, strip, strip, stripAccents, stripAll, stripAll, stripEnd, stripStart, stripToEmpty, stripToNull, substring, substring, substringAfter, substringAfterLast, substringBefore, substringBeforeLast, substringBetween, substringBetween, substringsBetween, swapCase, toEncodedString, toString, trim, trimToEmpty, trimToNull, truncate, truncate, uncapitalize, upperCase, upperCase, wrap, wrap, wrapIfMissing, wrapIfMissing
 
- 
 
- 
- 
- 
Method Detail- 
humanReadableByteCountpublic static String humanReadableByteCount(long bytes) 
 - 
humanReadableByteCountpublic static String humanReadableByteCount(long bytes, boolean si) Convert provided bytes in words.- Parameters:
- bytes- bytes to
- si- whether or not to use SI unit format
- Returns:
- human readable byte count
- Since:
- 1.0
 
 - 
splitCamelCasepublic static String splitCamelCase(String s) Use splitByCharacterTypeCamelCaseto split a given string into tokens and concatenates these tokens via a space.Example usages: StringMethods.splitCamelCase(null) = null StringMethods.splitCamelCase("") = "" StringMethods.splitCamelCase("ab de fg") = "ab de fg" StringMethods.splitCamelCase("ab de fg") = "ab de fg" StringMethods.splitCamelCase("ab:cd:ef") = "ab: cd: ef" StringMethods.splitCamelCase("number5") = "number 5" StringMethods.splitCamelCase("fooBar") = "foo Bar" StringMethods.splitCamelCase("foo200Bar") = "foo 200 Bar" StringMethods.splitCamelCase("ASFRules") = "ASF Rules"- Parameters:
- s- the string to split
- Returns:
- null, if the string to split is- null; otherwise, the split string
- Since:
- 1.0
 
 - 
generateRandomSecretKeypublic static String generateRandomSecretKey() Generates a random secret key and encodes it with Base64. This is to be used as a parameter forencrypt(String, char[])anddecrypt(String, char[])one-liners. The number of bits is determined by the maximum allowed key length of the JVM and AES.- Since:
- 2.0
 
 - 
generateRandomSecretKeypublic static String generateRandomSecretKey(int keySize) Generates a random secret key with a specific key size and encodes it with Base64. This is to be used as a parameter forencrypt(String, char[])anddecrypt(String, char[])one-liners.- Since:
- 2.0
 
 - 
encryptpublic static String encrypt(String text, char[] secretKey) Encrypt a plain text using AES-GCM and encodes to Base64. The encryption algorithm makes use of a Base64 secret key (can be generated usinggenerateRandomSecretKey()) and a random initialization vector (IV) that is prepended on the ciphertext.- Parameters:
- text- text to encrypt
- secretKey- a base64-encoded secret text; unencoded text must be 128, 192, or 256 bits
- Returns:
- a Base64-encoded ciphertext
- Since:
- 2.0
 
 - 
encrypt@Deprecated(since="1.0", forRemoval=true) public static String encrypt(String plainKey) throws RuntimeException Deprecated, for removal: This API element is subject to removal in a future version.Encrypt the plain text password.- Parameters:
- plainKey- the password
- Returns:
- the encrypted password
- Throws:
- RuntimeException- if an error occurs
- Since:
- 1.0
 
 - 
decryptpublic static String decrypt(String encryptedText, char[] secretKey) Decrypts a Base64-encoded ciphertext using AES-GCM. The decryption algorithm makes use of the Base64 secret key that was used during encryption and expects a initialization vector (IV) prefix on the ciphertext.- Parameters:
- encryptedText- the encrypted text
- secretKey- the secret text used on encryption
- Returns:
- the unencrypted text
- Since:
- 2.0
 
 - 
decrypt@Deprecated(since="1.0", forRemoval=true) public static String decrypt(String encryptedKey) Deprecated, for removal: This API element is subject to removal in a future version.Decrypt the encrypted password.- Parameters:
- encryptedKey- the encrypted password
- Returns:
- the plain text password
- Throws:
- ToroRuntimeException- if an error occurs
- Since:
- 1.0
 
 - 
implodepublic static String implode(Object val, String separator) Create a string concatenation of the elements of a string array or Listof objects. null elements are excluded from the concatenation.Object.toString()will be called to get the string representation of each element.See examples here: StringUtils.join(Object[], String).- Parameters:
- val- the array or- Listto concatenate
- separator- the character to use in between elements when concatenating
- Returns:
- concatenated string;
     val.toString()ifvalis neither aString[]norList
- Since:
- 1.0
 
 - 
tokenizeToStringArraypublic static String[] tokenizeToStringArray(String str, String delimiter, boolean trimTokens, boolean ignoreEmptyTokens, boolean retainDelimiter) Split the provided string into an array, using the given delimiteras an indicator of where to split.Example usages: StringMethods.tokenizeToStringArray(null, ":", false, false, false) = null StringMethods.tokenizeToStringArray("ab:cd:ef", null, false, false, false) = null StringMethods.tokenizeToStringArray(" ab : cd : ef ", ":", true, false, false) = ["ab", "cd", "ef"] StringMethods.tokenizeToStringArray("ab: :cd::ef", ":", false, true, false) = ["ab", " ", "cd", "ef"] StringMethods.tokenizeToStringArray("ab: :cd::ef", ":", false, false, false) = ["ab", " ", "cd", "", "ef"] StringMethods.tokenizeToStringArray("ab:cd:ef", ":", false, false, true) = ["ab", ":", "cd", ":", "ef"]- Parameters:
- str- the string to split
- delimiter- indicates where to split- str
- trimTokens- when set to true, trailing whitespaces are removed from every element
- ignoreEmptyTokens- when set to true, empty elements (- "") are removed from the array
- retainDelimiter- when set to true,- delimiters in the array will be retained (such that they belong in their own array index)
- Returns:
- an array of parsed strings, null if strordelimiteris null
- Since:
- 1.0
 
 - 
tokenizeToStringArraypublic static String[] tokenizeToStringArray(String str, String delimiter, boolean trimTokens, boolean ignoreEmptyTokens, boolean retainDelimiter, int max) Split the provided string into an array with a maximum length of max, using the givendelimiteras an indicator of where to split.Example usages: StringMethods.tokenizeToStringArray(null, ":", false, false, false, 0) = null StringMethods.tokenizeToStringArray("ab:cd:ef", null, false, false, false, 0) = null StringMethods.tokenizeToStringArray(" ab : cd : ef ", ":", true, false, false, 0) = ["ab", "cd", "ef"] StringMethods.tokenizeToStringArray("ab: :cd::ef", ":", false, true, false, 0) = ["ab", " ", "cd", "ef"] StringMethods.tokenizeToStringArray("ab: :cd::ef", ":", false, false, false, 0) = ["ab", " ", "cd", "", "ef"] StringMethods.tokenizeToStringArray("ab:cd:ef", ":", false, false, true, 0) = ["ab", ":", "cd", ":", "ef"] StringMethods.tokenizeToStringArray("ab:cd:ef", ":", false, false, false, 2) = ["ab", "cd:ef"]- Parameters:
- str- the string to split
- delimiter- indicates where to split- str
- trimTokens- when set to true, trailing whitespaces are removed from every element
- ignoreEmptyTokens- when set to true, empty elements (- "") are removed from the array
- retainDelimiter- when set to true,- delimiters in the array will be retained (such that they belong in their own array index)
- max- the maximum number of elements to include in the array; a zero or negative value implies no limit
- Returns:
- an array of parsed strings, null if strordelimiteris null
- Since:
- 1.0
 
 - 
removeEnclosingStringpublic static String removeEnclosingString(String str, String startEnclosure, String endEnclosure) Strip any of a set of characters from the beginning and end of a string. Example usages: StringMethods.removeEnclosingString(null, "*", "/") = null StringMethods.removeEnclosingString("", "*", "/") = "" StringMethods.removeEnclosingString("abc", "", "c") = "ab" StringMethods.removeEnclosingString("abc", "a", "") = "bc" StringMethods.removeEnclosingString("abc", null, null) = "abc" StringMethods.removeEnclosingString(" abc", null, "c") = "ab" StringMethods.removeEnclosingString("abc ", "a", null) = "bc" StringMethods.removeEnclosingString("abc ", null, "") = "abc " StringMethods.removeEnclosingString(" abc", "", null) = " abc" StringMethods.removeEnclosingString(" abc ", null, null) = "abc" StringMethods.removeEnclosingString(" yxabc", "xyz", "cde") = " yxab"- Parameters:
- str- the string to remove characters from, may be null
- startEnclosure- the characters to remove at the beginning of the string; a null value means leading whitespace characters will be removed
- endEnclosure- the characters to remove at the end of the string a null value means trailing whitespace characters will be removed
- Returns:
- the stripped string, null if stris null
 
 - 
encloseStringpublic static String encloseString(String str, String startEnclosure, String endEnclosure) Return a string prepended and appended with the provided strings. Example usages: StringMethods.encloseString(null, "lettuce", "cheese") = null StringMethods.encloseString("patty", "lettuce", "cheese") = "lettucepattycheese" StringMethods.encloseString("patty", null, "cheese") = "pattycheese" StringMethods.encloseString("patty", "lettuce", null) = "lettucepatty" StringMethods.encloseString("patty", "", null) = "patty" StringMethods.encloseString("patty", null, "") = "patty"- Parameters:
- str- the string to enclose
- startEnclosure- the string to prepend to- str
- endEnclosure- the string to append- str
- Returns:
- enclosed string
 
 - 
isEnclosedpublic static boolean isEnclosed(String str, String startEnclosure, String endEnclosure) Checks whether or not a string begins and ends with certain substrings. Example usages: StringMethods.isEnclosed(null, "lettuce", "cheese") = false StringMethods.isEnclosed(null, null, null) = true StringMethods.isEnclosed("lettucepattycheese", "lettuce", "cheese") = true StringMethods.isEnclosed(" lettucepattycheese", "lettuce", "cheese") = true StringMethods.isEnclosed("lettucepattycheese ", "lettuce", "cheese") = true StringMethods.isEnclosed("nullpattycheese", null, "cheese") = false StringMethods.isEnclosed("lettucepattynull", "lettuce", null) = false- Parameters:
- str- the string to check; can be null
- startEnclosure- the substring that- strmust begin with
- endEnclosure- the substring that- strmust end with
- Returns:
- true if strbeings withstartEnclosureand ends withendEnclosure; false otherwise
 
 - 
getEnclosedStringpublic static String getEnclosedString(String str, String startEnclosure, String endEnclosure, boolean retainEnclosedChar) Get the substring in between two substrings. Example usages: StringMethods.getEnclosedString(null, "lettuce", "cheese", false) = null StringMethods.getEnclosedString("thelettucepattycheeseend", "tomato", "cheese", false) = null StringMethods.getEnclosedString("thelettucepattycheeseend", "lettuce", "mustard", false) = null StringMethods.getEnclosedString("thelettucepattycheeseend", "lettuce", "cheese", false) = "patty" StringMethods.getEnclosedString("thelettucepattycheeseend", "lettuce", "cheese", true) = "lettucepattycheese"- Parameters:
- str- the string to extract the substring from, may be null
- startEnclosure- the substring preceding the enclosed string
- endEnclosure- the substring succeeding the enclosed string
- retainEnclosedChar- flag determining whether or not to strip the provided substrings in the returned result
- Returns:
- the stripped string; null if stris null;
- Throws:
- IllegalArgumentException- when either- startEnclosureor- endEnclosureis null
 
 - 
trimTrailingCharpublic static String trimTrailingChar(String str, String character) Trim a trailing substring. Example usages: StringMethods.trimTrailingChar(null, "aac") = null StringMethods.trimTrailingChar("aabbccabbaacaacaac", "aac") = aabbccabb StringMethods.trimTrailingChar("aabbccabbaacaacaac", "abc") = aabbccabbaacaacaac StringMethods.trimTrailingChar("aabbccabbaacaacaacccccc", "aac") = aabbccabbaacaacaacccccc StringMethods.trimTrailingChar("aabbccabbaacaacaacccccc", "ac") = aabbccabbaacaacaacccccc StringMethods.trimTrailingChar("aabbccabbaacaacaacccccc", "c") = aabbccabbaacaacaa StringMethods.trimTrailingChar("aabbccabbaacaacaacccccc", null) = aabbccabbaacaacaacccccc StringMethods.trimTrailingChar("aabbccabbaacaanullcaacccccc", null) = aabbccabbaacaanullcaacccccc StringMethods.trimTrailingChar("aabbccabbaacaanullcaaccccccnullnull", null) = aabbccabbaacaanullcaaccccccnullnull StringMethods.trimTrailingChar("aabbccabbaacaanullcaaccccccnullllll", null) = aabbccabbaacaanullcaaccccccnullllll- Parameters:
- str- the string to trim
- character- the trailing substring to trim
- Returns:
- the trimmed string
 
 - 
trimLeadingCharpublic static String trimLeadingChar(String str, String character) Trim a leading substring. Example usages: StringMethods.trimLeadingChar(null, "aac") = null StringMethods.trimLeadingChar("aacaacaacaabbccabb", "aac") = aabbccabb StringMethods.trimLeadingChar("aaccccccaacaacaabbccabb", "aac") = cccccaacaacaabbccabb StringMethods.trimLeadingChar("aaccccccaacaacaabbccabb", "ac") = aaccccccaacaacaabbccabb StringMethods.trimLeadingChar("aaccccccaacaacaabbccabb", "a") = ccccccaacaacaabbccabb StringMethods.trimLeadingChar("aaccccccaacaacaabbccabb", null) = aaccccccaacaacaabbccabb StringMethods.trimLeadingChar("aabbccabbaacaanullcaacccccc", null) = aabbccabbaacaanullcaacccccc StringMethods.trimLeadingChar("nullnullaabbccabbaacaanullcaacccccc", null) = nullnullaabbccabbaacaanullcaacccccc StringMethods.trimLeadingChar("nullllllaabbccabbaacaanullcaacccccc", null) = nullllllaabbccabbaacaanullcaacccccc- Parameters:
- str- the string to trim
- character- the leading substring to trim
- Returns:
- the trimmed string
 
 - 
ellipsizepublic static String ellipsize(String str, int maxLength) If the provided string exceeds the provided maximum length, it will be truncated and appended with an ellipsis. This method will truncate an additional 3 characters aside from the maximum allowed length for the ellipses (which takes up 3 characters) to ensure the returned string is no more than the provided maximum length.- Parameters:
- str- the string to ellipsize
- maxLength- the maximum length of the string before an
- Returns:
- ellipsized string
- Throws:
- IllegalArgumentException- if- maxLengthis less than 3
 
 - 
martiniPackageJoinpublic static String martiniPackageJoin(Collection<MartiniPackage> col, String separator) Get the names of the provided packages, and concatenate them into a single string.- Parameters:
- col- collection of packages
- separator- the separator character to use
- Returns:
- concatenated names of packages; null if collection of packages is null
 
 - 
containsAnypublic static boolean containsAny(CharSequence cs, Collection<? extends CharSequence> searchChars) Checks whether or not the provided string contains any of the substrings specified in the collection. Search is case-sensitive.- Parameters:
- cs- the string to check
- searchChars- the substrings to look for
- Returns:
- true if cscontains any items fromsearchChars; false otherwise
 
 - 
containsAnypublic static boolean containsAny(CharSequence cs, Collection<? extends CharSequence> searchChars, boolean ignoreCase) Checks whether or not the provided string contains any of the substrings specified in the collection.- Parameters:
- cs- the string to check
- searchChars- the substrings to look for
- ignoreCase- set to false if search is case sensitive; true if not
- Returns:
- true if cscontains any items fromsearchChars; false otherwise
 
 - 
appendPrefixpublic static String appendPrefix(String prefix, String separator, String body) Prepends a prefix and a separator to a string, in said order. Ifseparatoris null, then the four-character string null is appended after the prefix.- Parameters:
- prefix- the prefix to use
- separator- the separator to use
- body- the string to prepend
- Returns:
- prefix + separator + body
 
 - 
appendPrefixpublic static String appendPrefix(String prefix, Character separator, String body) Prepends a prefix and a separator to a string, in said order. Ifseparatoris null, then the four-character string null is appended after the prefix.- Parameters:
- prefix- the prefix to use
- separator- the separator to use
- body- the string to prepend
- Returns:
- prefix + separator + body
- Throws:
- NullPointerException- if- separatoris null
 
 - 
joinpublic static String join(Object[] array, String separator, boolean trimElement) Joins the elements of the provided array into a single string containing the provided array of elements. No delimiter is added before or after the list. A null separator is the same as an empty string (""). Null objects or empty strings within the array are represented by empty strings.- Parameters:
- array- - the array of values to join together, may be null
- separator- - the separator character to use, null treated as ""
- trimElement- whether or not to trim whitespaces around each element's string representation
- Returns:
- the joined string, null if null array input
 
 - 
joinpublic static String join(String[] strArr, String charSeparator, Function<String,String> entryTransformer) Joins the elements of the provided array into a single string containing the provided array of elements. No delimiter is added before or after the list. A null separator is the same as an empty string (""). Null objects or empty strings within the array are represented by empty strings.- Parameters:
- strArr- the array of values to join together, may be null
- charSeparator- the separator to use when concatenating
- entryTransformer- the function to apply to each element before concatenation
- Returns:
- the joined string, null if null array input
 
 - 
toArraypublic static String[] toArray(Object object) Get theString[]representation of the provided object. If the object is aCollection, then its equivalentString[]is returned. If the object is aString, then an array of its substring separated by , will be returned. If the object is already aString[], then the same array passed in will be returned. If the object is none of these types, then null is returned.- Parameters:
- object- object to convert to array
- Returns:
- String[]representation of the object
 
 - 
startsWithAnyIgnoreCasepublic static boolean startsWithAnyIgnoreCase(CharSequence string, CharSequence... searchStrings) Checks if stringstarts with any of the items insearchStrings, regardless of letter case.StringUtils.startsWithAnyIgnoreCase("ABCD", ["AB", "xy"]) = true StringUtils.startsWithAnyIgnoreCase("ABCD", ["ab", "xy"]) = true StringUtils.startsWithAnyIgnoreCase("abcd", ["gh", "xy"]) = false StringUtils.startsWithAnyIgnoreCase("abcd", null) = false StringUtils.startsWithAnyIgnoreCase("", ["abc", ""]) = true StringUtils.startsWithAnyIgnoreCase(null, ["abc", null]) = true StringUtils.startsWithAnyIgnoreCase(null, ["abc", "null"]) = false- Parameters:
- string- the string to check
- searchStrings- the prefixes to look for
- Returns:
- true if stringstarts with any of the items insearchStrings(case insensitive); false ifsearchStringsis null or empty.
 
 - 
transformEntrypublic static String[] transformEntry(String[] strArr, @NotNull @NotNull Function<String,String> entryTransformer) Transform each element in the array using the provided function, and then return the transformed array.- Parameters:
- strArr- the array to transform
- entryTransformer- the function that will be used to transform each element
- Returns:
- the transformed array
 
 - 
countMatchespublic static int countMatches(Collection<String> strings, String regularExpression) Counts the number of entries in stringsmatching the regular expressionregularExpression. A null collection of entries or regular expression matches none (thus, zero is returned).- Parameters:
- strings- the entries to check
- regularExpression- the regular expression to match against
- Returns:
- number of entries in stringsmatchingregularExpression; zero if eitherstringsorregularExpressionis null
- See Also:
- countFinds(Collection, String)
 
 - 
countFindspublic static int countFinds(Collection<String> strings, String regularExpression) Counts the total number of occurrences of the given regular expression in the entries. A null collection of entries or regular expression matches none (thus, zero is returned). - Parameters:
- strings- the entries to check
- regularExpression- the regular expression to find
- Returns:
- number of entries in stringsmatchingregularExpression; zero if eitherstringsorregularExpressionis null
- See Also:
- countMatches(Collection, String)
 
 - 
hasAMatchpublic static boolean hasAMatch(String string, Collection<String> regularExpressions) Check if the given string matches any of the given regular expressions. Results to no matches if either stringorregularExpressionsis null.- Returns:
- if the given string matches any of the given regular expressions
 
 - 
substitutepublic static String substitute(Object tokenisedObject) Substitutes variables within the given source object with Martini application properties and system property values. This method takes a piece of text and substitutes all the variables within it. The default definition of a variable is ${variableName}. This method allows a default value for unresolved variables. The default value for a variable can be appended to the variable name after the variable default value delimiter. The default value of the "variable default value delimiter" is :-, as in Bash and other *nix shells, as those are arguably where the default ${} delimiter set originated. The list variable values used are taken from the underlying Martini application properties. Properties in the override file are checked first, then the standard properties file, then the JVM system properties. The following shows an example with variable default value settings: String templateString = StringMethods.substitute( "The ${animal} jumped over the ${target}. ${undefined.number:-1234567890}." );Resulting in:The quick brown fox jumped over the lazy dog. 1234567890. - Parameters:
- tokenisedObject- the source object
- Returns:
- the resulting, parsed string
 
 - 
substituteAsIntpublic static int substituteAsInt(Object tokenisedObject) throws NumberFormatException Uses substitute(Object)to substitute variables in the source object, but attempts to parse the result as anint.- Parameters:
- tokenisedObject- the source object
- Returns:
- the resulting integer
- Throws:
- NumberFormatException- when the result of the expression can't be parsed as an integer
 
 - 
substituteAsIntpublic static int substituteAsInt(Object tokenisedObject, int defaultValue) Uses substitute(Object)to substitute variables in the source object, but attempts to parse the result as anint. If the result could not be parsed as an integer, the default value is returned.- Parameters:
- tokenisedObject- the source object
- defaultValue- the value to return if the result could not be parsed as an integer
- Returns:
- the resulting integer; or defaultValueif the result could not be parsed as an integer
 
 - 
substituteAsBooleanpublic static boolean substituteAsBoolean(Object tokenisedObject) Uses substitute(Object)to substitute variables in the source object, then checks whether or not the result is equal to true (case insensitive).- Parameters:
- tokenisedObject- the source object
- Returns:
- true if the resulting string is equal to true; false otherwise
 
 - 
splitpublic static String[] split(String str, String regex) Splits this string around matches of the given regular expression Note: This method was overridden to prevent accidental usage ofStringUtils.split(String, String)overString.split(String)when used as a one-liner.- Parameters:
- regex- the delimiting regular expression
- Returns:
- the array of strings computed by splitting this string around matches of the given regular expression
- Throws:
- PatternSyntaxException- if the regular expression's syntax is invalid
 
 
- 
 
-