Package liquibase.util
Class StringUtil
java.lang.Object
liquibase.util.StringUtil
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic interfacestatic class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringconcatConsistentCase(String baseString, String addition) Concatenates the addition string to the baseString string, adjusting the case of "addition" to match the base string.static booleanDeprecated.static booleanDeprecated.useStringUtils.endsWith(CharSequence, CharSequence)insteadstatic booleanequalsIgnoreCaseAndEmpty(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 spacesstatic booleanequalsWordNull(String value) Check whether the value is 'null' (case insensitive)static StringescapeHtml(String str) static byte[]getBytesWithEncoding(String string) static StringgetLastBlockComment(String sqlString) Retrieves the last block comment in a SQL string, if any.static StringgetLastLineComment(String sqlString) Returns the last line comment from a given SQL string, if there is one.static booleanhasLowerCase(String string) static booleanhasUpperCase(String string) static Stringstatic Stringstatic booleanisAscii(char ch) Deprecated.useCharUtils.isAscii(char)insteadstatic booleanprotected static booleanisDelimiter(String piece, String previousPiece, String endDelimiter) Returns true if the input is a delimiter in one of the popular RDBMSs.static booleanisEmpty(CharSequence cs) Deprecated.useStringUtils.isEmpty(CharSequence)static booleanDeprecated.useStringUtils.isEmpty(CharSequence)insteadstatic booleanisMinimumVersion(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 booleanisNotEmpty(String value) Deprecated.useStringUtils.isNotEmpty(CharSequence)insteadstatic booleanDeprecated.useStringUtils.isNumeric(CharSequence)insteadstatic booleanisWhitespace(CharSequence string) Returns true if the given string only consists of whitespace characters (null-safe)static StringDeprecated.useStringUtils.join(int[], char)insteadstatic StringDeprecated.useStringUtils.join(Object[], String)insteadstatic Stringjoin(Object[] array, String delimiter, StringUtil.StringUtilFormatter formatter) static Stringstatic Stringjoin(Collection<String> collection, String delimiter) static Stringjoin(Collection<String> collection, String delimiter, boolean sorted) static Stringjoin(Collection collection, String delimiter, StringUtil.StringUtilFormatter formatter) static Stringjoin(Collection collection, String delimiter, StringUtil.StringUtilFormatter formatter, boolean sorted) static Stringstatic Stringjoin(Map map, String delimiter, StringUtil.StringUtilFormatter formatter) static Stringjoin(ExtensibleObject extensibleObject, String delimiter) static Stringjoin(ExtensibleObject extensibleObject, String delimiter, StringUtil.StringUtilFormatter formatter) static StringAdds spaces to the left of the input value until the string has reached the given length.static Stringstatic StringlowerCaseFirst(String string) Deprecated.useStringUtils.uncapitalize(String)insteadstatic StringAdds 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 usingstripComments(String, ChangeSet)and then extracts each individual statement usingsplitSQL(String, String, ChangeSet).static String[]processMultiLineSQL(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter, ChangeSet changeSet) Removes any comments from multiple line SQL usingstripComments(String, ChangeSet)and then extracts each individual statement usingsplitSQL(String, String, ChangeSet).static String[]processMutliLineSQL(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter) Deprecated.The new method isprocessMultiLineSQL(String, boolean, boolean, String, ChangeSet)(String)}static String[]processMutliLineSQL(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter, ChangeSet changeSet) Deprecated.The new method isprocessMultiLineSQL(String, boolean, boolean, String, ChangeSet)(String)}static StringrandomIdentifer(int len) Deprecated.static StringrandomIdentifier(int len) Produce a random identifier of the given length, consisting only of uppercase letters.static StringDeprecated.useStringUtils.repeat(String, int)insteadsplitAndTrim(String s, String regex) static String[]splitCamelCase(String str) Deprecated.useStringUtils.splitByCharacterTypeCamelCase(String)insteadstatic String[]Splits a candidate multi-line SQL statement along ;'s and "go"'s.static String[]Splits a candidate multi-line SQL statement along ;'s and "go"'s.splitToChunks(String input, int chunkSize) Split the input string into chunks no larger than the supplied chunkSize.static StringstandardizeLineEndings(String string) static booleanstartsWith(String value, String startsWith) Deprecated.useStringUtils.startsWith(CharSequence, CharSequence)insteadstatic StringstripComments(String multiLineSQL) Searches through a String which contains SQL code and strips out any comments that are between \/**\/ or anything that matches SP--SP\n (to support the ANSI standard commenting of -- at the end of a line). static StringstripComments(String multiLineSQL, ChangeSet changeSet) Searches through a String which contains SQL code and strips out any comments that are between \/**\/ or anything that matches SP--SP\n (to support the ANSI standard commenting of -- at the end of a line). static StringstripEnclosingQuotes(String string) static StringstripSqlCommentsAndWhitespacesFromTheEnd(String sqlString) Strips the comments and white spaces from the end of given SQL string.static StringtoCamelCase(String string) Converts a kabob-case or underscore_case string to a camel-case onestatic StringtoKabobCase(String string) Converts a camelCase string to a kabob-case onestatic StringtoLowerWithoutWhitespaces(String value) Deprecated.useStringUtils.toRootLowerCase(String)andStringUtils.deleteWhitespace(String)insteadstatic StringTrimswhitespacecharacters from the end of specifiedstringstatic StringtrimToEmpty(String string) Deprecated.useStringUtils.trimToEmpty(String)insteadstatic StringtrimToNull(String string) Deprecated.useStringUtils.trimToNull(String)insteadstatic StringupperCaseFirst(String string) Deprecated.useStringUtils.capitalize(String)insteadstatic StringDeprecated.Liquibase does not wrap any console output, and instead lets the terminal handle its own wrapping.
-
Constructor Details
-
StringUtil
public StringUtil()
-
-
Method Details
-
trimToEmpty
Deprecated.useStringUtils.trimToEmpty(String)insteadReturns the trimmed (left and right) version of the input string. If null is passed, an empty string is returned.- Parameters:
string- the input string to trim- Returns:
- the trimmed string, or an empty string if the input was null.
-
trimToNull
Deprecated.useStringUtils.trimToNull(String)insteadReturns the trimmed (left and right) form of the input string. If the string is empty after trimming (or null was passed in the first place), null is returned, i.e. the input string is reduced to nothing.- Parameters:
string- the string to trim- Returns:
- the trimmed string or null
-
processMultiLineSQL
public static String[] processMultiLineSQL(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter) Removes any comments from multiple line SQL usingstripComments(String, ChangeSet)and then extracts each individual statement usingsplitSQL(String, String, ChangeSet).- Parameters:
multiLineSQL- A String containing all the SQL statementsstripComments- If true then comments will be stripped, if false then they will be left in the code
-
processMultiLineSQL
public static String[] processMultiLineSQL(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter, ChangeSet changeSet) Removes any comments from multiple line SQL usingstripComments(String, ChangeSet)and then extracts each individual statement usingsplitSQL(String, String, ChangeSet).- Parameters:
multiLineSQL- A String containing all the SQL statementsstripComments- If true then comments will be stripped, if false then they will be left in the codechangeSet- the changeset associated with the sql being parsed
-
processMutliLineSQL
@Deprecated public static String[] processMutliLineSQL(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter) Deprecated.The new method isprocessMultiLineSQL(String, boolean, boolean, String, ChangeSet)(String)}Removes any comments from multiple line SQL usingstripComments(String, ChangeSet)and then extracts each individual statement usingsplitSQL(String, String, ChangeSet).- Parameters:
multiLineSQL- A String containing all the SQL statementsstripComments- If true then comments will be stripped, if false then they will be left in the code
-
processMutliLineSQL
@Deprecated public static String[] processMutliLineSQL(String multiLineSQL, boolean stripComments, boolean splitStatements, String endDelimiter, ChangeSet changeSet) Deprecated.The new method isprocessMultiLineSQL(String, boolean, boolean, String, ChangeSet)(String)}Removes any comments from multiple line SQL usingstripComments(String, ChangeSet)and then extracts each individual statement usingsplitSQL(String, String, ChangeSet).- Parameters:
multiLineSQL- A String containing all the SQL statementsstripComments- If true then comments will be stripped, if false then they will be left in the codechangeSet- the changeset associated with the sql being parsed
-
isDelimiter
Returns true if the input is a delimiter in one of the popular RDBMSs. Recognized delimiters are: semicolon (;), a slash (as the only content) or the word GO (as the only content).- Parameters:
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)
-
wrap
Deprecated.Liquibase does not wrap any console output, and instead lets the terminal handle its own wrapping. If you wish to use this method, consider whether its usage is truly necessary.Add new lines to the input string to cause output to wrap. Optional line padding can be passed in for the additional lines that are created- Parameters:
inputStr- The string to split and wrapwrapPoint- The point at which to split the linesextraLinePadding- Any additional spaces to add- Returns:
- String Output string with new lines
-
splitSQL
Splits a candidate multi-line SQL statement along ;'s and "go"'s. -
splitSQL
Splits a candidate multi-line SQL statement along ;'s and "go"'s.- Parameters:
changeSet- the changeset associated with the sql being parsed
-
stripComments
Searches through a String which contains SQL code and strips out any comments that are between \/**\/ or anything that matches SP--SP\n (to support the ANSI standard commenting of -- at the end of a line). - Returns:
- The String without the comments in
-
stripComments
Searches through a String which contains SQL code and strips out any comments that are between \/**\/ or anything that matches SP--SP\n (to support the ANSI standard commenting of -- at the end of a line). - Parameters:
changeSet- the changeset associated with the sql being parsed- Returns:
- The String without the comments in
-
join
public static String join(Object[] array, String delimiter, StringUtil.StringUtilFormatter formatter) -
join
-
join
-
join
public static String join(Collection collection, String delimiter, StringUtil.StringUtilFormatter formatter) -
join
public static String join(Collection collection, String delimiter, StringUtil.StringUtilFormatter formatter, boolean sorted) -
join
-
join
-
join
-
join
-
join
public static String join(ExtensibleObject extensibleObject, String delimiter, StringUtil.StringUtilFormatter formatter) -
splitAndTrim
-
repeat
Deprecated.useStringUtils.repeat(String, int)instead -
join
Deprecated.useStringUtils.join(Object[], String)instead -
join
Deprecated.useStringUtils.join(int[], char)instead -
indent
-
indent
-
lowerCaseFirst
Deprecated.useStringUtils.uncapitalize(String)instead -
upperCaseFirst
Deprecated.useStringUtils.capitalize(String)instead -
hasUpperCase
-
hasLowerCase
-
standardizeLineEndings
-
isAscii
-
isAscii
Deprecated.useCharUtils.isAscii(char)insteadReturns true if ch is a "7-bit-clean" ASCII character (ordinal number < 128).- Parameters:
ch- the character to test- Returns:
- true if 7 bit-clean, false otherwise.
-
escapeHtml
-
pad
Adds spaces to the right of the input value until the string has reached the given length. Nothing is done if the string already has the given length or if the string is even longer.- Parameters:
value- The string to pad (if necessary)length- the desired length- Returns:
- the input string, padded if necessary.
-
leftPad
Adds spaces to the left of the input value until the string has reached the given length. Nothing is done if the string already has the given length or if the string is even longer.- Parameters:
value- The string to pad (if necessary)length- the desired length- Returns:
- the input string, padded if necessary.
-
contains
Deprecated.useStringUtils.contains(CharSequence, CharSequence)insteadReturns true if the input string contains the specified value- Parameters:
value- String to be checkedcontainsValue- String to look for- Returns:
- true if String contains the value
-
isEmpty
Deprecated.useStringUtils.isEmpty(CharSequence)insteadReturns true if the input string is the empty string (null-safe).- Parameters:
value- String to be checked- Returns:
- true if String is null or empty
-
isNotEmpty
Deprecated.useStringUtils.isNotEmpty(CharSequence)insteadReturns true if the input string is NOT the empty string. If the string is null, false is returned.- Parameters:
value- String to be checked- Returns:
- true if string is not null and not empty (length > 0)
-
startsWith
Deprecated.useStringUtils.startsWith(CharSequence, CharSequence)insteadChecks whether the givenvaluestarts with the specifiedstartsWithstring.- Parameters:
value- the string to checkstartsWith- the prefix to check for- Returns:
trueifvaluestarts withstartsWith,falseotherwise. Returnsfalseif either argument isnull.
-
endsWith
Deprecated.useStringUtils.endsWith(CharSequence, CharSequence)insteadChecks whether the givenvalueends with the specifiedendsWithstring.- Parameters:
value- the string to checkendsWith- the prefix to check for- Returns:
trueifvalueends withendsWith,falseotherwise. Returnsfalseif either argument isnull.
-
isWhitespace
Returns true if the given string only consists of whitespace characters (null-safe)- Parameters:
string- the string to test- Returns:
- true if the string is null or only consists of whitespaces.
-
isMinimumVersion
public 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.- Parameters:
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 part- Returns:
- true if candidateMajor.candidateMinor.candidatePatch >= minimumVersion or false if not
-
limitSize
-
randomIdentifer
Deprecated.Produce a random identifier of the given length, consisting only of uppercase letters.- Parameters:
len- desired length of the string- Returns:
- an identifier of the desired length
-
randomIdentifier
Produce a random identifier of the given length, consisting only of uppercase letters.- Parameters:
len- desired length of the string- Returns:
- an identifier of the desired length
-
toKabobCase
Converts a camelCase string to a kabob-case one -
toCamelCase
Converts a kabob-case or underscore_case string to a camel-case one -
equalsIgnoreCaseAndEmpty
Returns if two strings are equal, ignoring:- case (uppercase/lowercase)
- difference between null, and empty string, and a string that only has spaces
- Parameters:
s1- the first String to compare (or null)s2- the second String to compare (or null)- Returns:
- true if the Strings are equal by the above criteria, false in all other cases
-
trimRight
Trimswhitespacecharacters from the end of specifiedstring- Parameters:
string- String to trim- Returns:
- new String without the whitespace at the end
-
getLastBlockComment
Retrieves the last block comment in a SQL string, if any.- Parameters:
sqlString- the SQL string to search for the last block comment- Returns:
- the last block comment in the SQL string, or
nullif none was found
-
getLastLineComment
Returns the last line comment from a given SQL string, if there is one.- Parameters:
sqlString- the SQL string to search- Returns:
- the last line comment from the SQL string, or
nullif there is no line comment
-
stripSqlCommentsAndWhitespacesFromTheEnd
Strips the comments and white spaces from the end of given SQL string.- Parameters:
sqlString- the SQL string to strip- Returns:
- the stripped SQL string
-
concatConsistentCase
Concatenates the addition string to the baseString string, adjusting the case of "addition" to match the base string. If the string is all caps, append addition in all caps. If all lower case, append in all lower case. If baseString is mixed case, make no changes to addition. -
stripEnclosingQuotes
-
equalsWordNull
Check whether the value is 'null' (case insensitive) -
splitCamelCase
Deprecated.useStringUtils.splitByCharacterTypeCamelCase(String)insteadSplits a camel-case string into words based on the came casing.
- Parameters:
str- the String to split, may benull- Returns:
- an array of parsed Strings,
nullif null String input
-
getBytesWithEncoding
-
toLowerWithoutWhitespaces
Deprecated.useStringUtils.toRootLowerCase(String)andStringUtils.deleteWhitespace(String)instead- Parameters:
value- string to process- Returns:
- string without any whitespaces formatted to lowercase.
-
isNumeric
Deprecated.useStringUtils.isNumeric(CharSequence)insteadChecks 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
- Parameters:
cs- the arg to check if it is numeric- Returns:
- true if convertible to numeric and false otherwise
-
isEmpty
Deprecated.useStringUtils.isEmpty(CharSequence) -
splitToChunks
Split the input string into chunks no larger than the supplied chunkSize. If the string is shorter than the chunkSize, the resultant list will contain only a single entry.
-
StringUtils.contains(CharSequence, CharSequence)instead