public class StringUtil extends Object
Modifier and Type | Class and Description |
---|---|
static class |
StringUtil.DefaultFormatter |
static interface |
StringUtil.StringUtilFormatter<Type> |
static class |
StringUtil.ToStringFormatter |
Constructor and Description |
---|
StringUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
concatConsistentCase(String baseString,
String addition)
Concatenates the addition string to the baseString string, adjusting the case of "addition" to match the base string.
|
static boolean |
equalsIgnoreCaseAndEmpty(String s1,
String s2)
Returns if two strings are equal, ignoring:
case (uppercase/lowercase)
difference between null, and empty string, and a string that only has spaces
|
static boolean |
equalsWordNull(String value)
Check whether the value is 'null' (case insensitive)
|
static String |
escapeHtml(String str) |
static byte[] |
getBytesWithEncoding(String string) |
static String |
getLastBlockComment(String sqlString) |
static String |
getLastLineComment(String sqlString) |
static boolean |
hasLowerCase(String string) |
static boolean |
hasUpperCase(String string) |
static String |
indent(String string) |
static String |
indent(String string,
int padding) |
static boolean |
isAscii(char ch)
Returns true if ch is a "7-bit-clean" ASCII character (ordinal number < 128).
|
static boolean |
isAscii(String string) |
protected static boolean |
isDelimiter(String piece,
String previousPiece,
String endDelimiter)
Returns true if the input is a delimiter in one of the popular RDBMSs.
|
static boolean |
isEmpty(CharSequence cs) |
static boolean |
isEmpty(String value)
Returns true if the input string is the empty string (null-safe).
|
static boolean |
isMinimumVersion(String minimumVersion,
int candidateMajor,
int candidateMinor,
int candidatePatch)
Compares a minimum version number given in string form (only the first three parts are considered) with a
candidate version given as the three ints major, minor and patch.
|
static boolean |
isNotEmpty(String value)
Returns true if the input string is NOT the empty string.
|
static boolean |
isNumeric(CharSequence cs)
Checks whether the char sequence is numeric by checking that all chars in the sequence are
numbers, so (-1, 1.0 and 1F) will return false
|
static boolean |
isWhitespace(CharSequence string)
Returns true if the given string only consists of whitespace characters (null-safe)
|
static String |
join(Collection<String> collection,
String delimiter) |
static String |
join(Collection<String> collection,
String delimiter,
boolean sorted) |
static String |
join(Collection collection,
String delimiter,
StringUtil.StringUtilFormatter formatter) |
static String |
join(Collection collection,
String delimiter,
StringUtil.StringUtilFormatter formatter,
boolean sorted) |
static String |
join(ExtensibleObject extensibleObject,
String delimiter) |
static String |
join(ExtensibleObject extensibleObject,
String delimiter,
StringUtil.StringUtilFormatter formatter) |
static String |
join(int[] array,
String delimiter) |
static String |
join(Integer[] array,
String delimiter) |
static String |
join(Map map,
String delimiter) |
static String |
join(Map map,
String delimiter,
StringUtil.StringUtilFormatter formatter) |
static String |
join(Object[] array,
String delimiter,
StringUtil.StringUtilFormatter formatter) |
static String |
join(String[] array,
String delimiter) |
static String |
leftPad(String value,
int length)
Adds spaces to the left of the input value until the string has reached the given length.
|
static String |
limitSize(String string,
int maxLength) |
static String |
lowerCaseFirst(String string) |
static String |
pad(String value,
int length)
Adds spaces to the right of the input value until the string has reached the given length.
|
static String[] |
processMultiLineSQL(String multiLineSQL,
boolean stripComments,
boolean splitStatements,
String endDelimiter)
Removes any comments from multiple line SQL using
stripComments(String)
and then extracts each individual statement using splitSQL(String, String) . |
static String[] |
processMutliLineSQL(String multiLineSQL,
boolean stripComments,
boolean splitStatements,
String endDelimiter)
Deprecated.
The new method is
processMultiLineSQL(String, boolean, boolean, String) (String)} |
static String |
randomIdentifer(int len)
Produce a random identifer of the given length, consisting only of uppercase letters.
|
static String |
repeat(String string,
int times) |
static List<String> |
splitAndTrim(String s,
String regex) |
static String[] |
splitCamelCase(String str)
Splits a camel-case string into words based on the came casing.
|
static String[] |
splitSQL(String multiLineSQL,
String endDelimiter)
Splits a candidate multi-line SQL statement along ;'s and "go"'s.
|
static String |
standardizeLineEndings(String string) |
static boolean |
startsWith(String value,
String startsWith)
Checks if
value starts with startsWith . |
static String |
stripComments(String multiLineSQL)
Searches through a String which contains SQL code and strips out
any comments that are between \/**\/ or anything that matches
SP--SP
|
static String |
stripEnclosingQuotes(String string) |
static String |
stripSqlCommentsAndWhitespacesFromTheEnd(String sqlString)
Strips the comments and whitespaces from the end of given sql string.
|
static String |
toCamelCase(String string)
Converts a kabob-case or underscore_case string to a camel-case one
|
static String |
toKabobCase(String string)
Converts a camelCase string to a kabob-case one
|
static String |
toLowerWithoutWhitespaces(String value) |
static String |
trimRight(String string)
Trims
whitespace characters from the
end of specified string |
static String |
trimToEmpty(String string)
Returns the trimmed (left and right) version of the input string.
|
static String |
trimToNull(String string)
Returns the trimmed (left and right) form of the input string.
|
static String |
upperCaseFirst(String string) |
static String |
wrap(String inputStr,
int wrapPoint,
int extraLinePadding)
Add new lines to the input string to cause output to wrap.
|
public static String trimToEmpty(String string)
string
- the input string to trimpublic static String trimToNull(String string)
string
- the string to trimpublic static String[] processMultiLineSQL(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter)
stripComments(String)
and then extracts each individual statement using splitSQL(String, String)
.multiLineSQL
- A String containing all the SQL statementsstripComments
- If true then comments will be stripped, if false then they will be left in the codepublic static String[] processMutliLineSQL(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter)
processMultiLineSQL(String, boolean, boolean, String)
(String)}stripComments(String)
and then extracts each individual statement using splitSQL(String, String)
.multiLineSQL
- A String containing all the SQL statementsstripComments
- If true then comments will be stripped, if false then they will be left in the codeprotected static boolean isDelimiter(String piece, String previousPiece, String endDelimiter)
piece
- the input line to testpreviousPiece
- the characters in the input stream that came before pieceendDelimiter
- ??? (need to see this in a debugger to find out)public static String wrap(String inputStr, int wrapPoint, int extraLinePadding)
inputStr
- The string to split and wrapwrapPoint
- The point at which to split the linesextraLinePadding
- Any additional spaces to addpublic static String[] splitSQL(String multiLineSQL, String endDelimiter)
public static String stripComments(String multiLineSQL)
public static String join(Object[] array, String delimiter, StringUtil.StringUtilFormatter formatter)
public static String join(Collection<String> collection, String delimiter)
public static String join(Collection collection, String delimiter, StringUtil.StringUtilFormatter formatter)
public static String join(Collection collection, String delimiter, StringUtil.StringUtilFormatter formatter, boolean sorted)
public static String join(Collection<String> collection, String delimiter, boolean sorted)
public static String join(Map map, String delimiter, StringUtil.StringUtilFormatter formatter)
public static String join(ExtensibleObject extensibleObject, String delimiter)
public static String join(ExtensibleObject extensibleObject, String delimiter, StringUtil.StringUtilFormatter formatter)
public static boolean hasUpperCase(String string)
public static boolean hasLowerCase(String string)
public static boolean isAscii(String string)
public static boolean isAscii(char ch)
ch
- the character to testpublic static String pad(String value, int length)
value
- The string to pad (if necessary)length
- the desired lengthpublic static String leftPad(String value, int length)
value
- The string to pad (if necessary)length
- the desired lengthpublic static boolean isEmpty(String value)
value
- String to be checkedpublic static boolean isNotEmpty(String value)
value
- String to be checkedpublic static boolean startsWith(String value, String startsWith)
value
starts with startsWith
.value
- startsWith
- value
starts with startsWith
, otherwise false. If any of arguments is null returns falsepublic static boolean isWhitespace(CharSequence string)
string
- the string to testpublic static boolean isMinimumVersion(String minimumVersion, int candidateMajor, int candidateMinor, int candidatePatch)
minimumVersion
- The minimum version that is required, given as a string with up to 3 parts, e.g. "7.4" or "9.6.3"candidateMajor
- the version number to be tested, major partcandidateMinor
- the version number to be tested, minor partcandidatePatch
- the version number to be tested, patch partpublic static String randomIdentifer(int len)
len
- desired length of the stringpublic static String toKabobCase(String string)
public static String toCamelCase(String string)
public static boolean equalsIgnoreCaseAndEmpty(String s1, String s2)
s1
- the first String to compare (or null)s2
- the second String to compare (or null)public static String trimRight(String string)
whitespace
characters from the
end of specified string
string
- String to trimpublic static String getLastBlockComment(String sqlString)
sqlString
- public static String getLastLineComment(String sqlString)
sqlString
- public static String stripSqlCommentsAndWhitespacesFromTheEnd(String sqlString)
sqlString
- public static String concatConsistentCase(String baseString, String addition)
public static boolean equalsWordNull(String value)
public static String[] splitCamelCase(String str)
Splits a camel-case string into words based on the came casing.
This code originated from the StringUtils class of https://github.com/apache/commons-lang
str
- the String to split, may be null
null
if null String inputpublic static byte[] getBytesWithEncoding(String string)
public static String toLowerWithoutWhitespaces(String value)
value
- string to processpublic static boolean isNumeric(CharSequence cs)
Checks whether the char sequence is numeric by checking that all chars in the sequence are numbers, so (-1, 1.0 and 1F) will return false
This code originated from the StringUtils class of https://github.com/apache/commons-lang
cs
- the arg to check if it is numericpublic static boolean isEmpty(CharSequence cs)
Copyright © 2023 Liquibase.org. All rights reserved.