Top Description Inners Fields Constructors Methods
liquibase.util

public Class StringUtil

extends Object
Class Inheritance
Imports
liquibase.ExtensibleObject, .GlobalConfiguration, .Scope, liquibase.changelog.ChangeSet, liquibase.parser.LiquibaseSqlParser, .SqlParserFactory, java.io.UnsupportedEncodingException, java.nio.charset.StandardCharsets, java.security.SecureRandom, java.util.*, java.util.regex.Matcher, .Pattern

Various utility methods for working with strings.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static interface
public static class

Field Summary

Modifier and TypeField and Description
private static final Pattern
private static final SecureRandom
private static final Pattern
private static final Pattern

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public 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.

public static boolean

Returns:

true if String contains the value
contains
(String
String to be checked
value
,
String
String to look for
containsValue
)

Returns true if the input string contains the specified value

public static boolean

Returns:

true if value ends with endsWith, false otherwise. Returns false if either argument is null.
endsWith
(String
the string to check
value
,
String
the prefix to check for
endsWith
)

Checks whether the given value ends with the specified endsWith string.

public static boolean

Returns:

true if the Strings are equal by the above criteria, false in all other cases
equalsIgnoreCaseAndEmpty
(String
the first String to compare (or null)
s1
,
String
the second String to compare (or null)
s2
)

Returns if two strings are equal, ignoring:

  • case (uppercase/lowercase)
  • difference between null, and empty string, and a string that only has spaces
public static boolean
equalsWordNull(String value)

Check whether the value is 'null' (case insensitive)

public static String
public static byte[]
public static String

Returns:

the last block comment in the SQL string, or null if none was found
getLastBlockComment
(String
the SQL string to search for the last block comment
sqlString
)

Retrieves the last block comment in a SQL string, if any.

public static String

Returns:

the last line comment from the SQL string, or null if there is no line comment
getLastLineComment
(String
the SQL string to search
sqlString
)

Returns the last line comment from a given SQL string, if there is one.

public static boolean
public static boolean
public static String
indent(String string)

public static String
indent(String string, int padding)

public static boolean
isAscii(String string)

public static boolean

Returns:

true if 7 bit-clean, false otherwise.
isAscii
(char
the character to test
ch
)

Returns true if ch is a "7-bit-clean" ASCII character (ordinal number < 128).

protected static boolean
isDelimiter(String
the input line to test
piece
,
String
the characters in the input stream that came before piece
previousPiece
,
String
??? (need to see this in a debugger to find out)
endDelimiter
)

Returns true if the input is a delimiter in one of the popular RDBMSs.

public static boolean

Returns:

true if String is null or empty
isEmpty
(String
String to be checked
value
)

Returns true if the input string is the empty string (null-safe).

public static boolean
public static boolean

Returns:

true if candidateMajor.candidateMinor.candidatePatch >= minimumVersion or false if not
isMinimumVersion
(String
The minimum version that is required, given as a string with up to 3 parts, e.g. "7.4" or "9.6.3"
minimumVersion
,
int
the version number to be tested, major part
candidateMajor
,
int
the version number to be tested, minor part
candidateMinor
,
int
the version number to be tested, patch part
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.

public static boolean

Returns:

true if string is not null and not empty (length > 0)
isNotEmpty
(String
String to be checked
value
)

Returns true if the input string is NOT the empty string.

public static boolean

Returns:

true if convertible to numeric and false otherwise
isNumeric
(CharSequence
the arg to check if it is numeric
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 commons-lang

public static boolean

Returns:

true if the string is null or only consists of whitespaces.
isWhitespace
(CharSequence
the string to test
string
)

Returns true if the given string only consists of whitespace characters (null-safe)

public static String
join(Object[] array, String delimiter, StringUtil.StringUtilFormatter<Type> formatter)

public static String
join(String[] array, String delimiter)

public static String
join(Collection<String> collection, String delimiter)

public static String
join(Collection<E> collection, String delimiter, StringUtil.StringUtilFormatter<Type> formatter)

public static String
join(Collection<E> collection, String delimiter, StringUtil.StringUtilFormatter<Type> formatter, boolean sorted)

public static String
join(Collection<String> collection, String delimiter, boolean sorted)

public static String
join(Map<K, V> map, String delimiter)

public static String
join(Map<K, V> map, String delimiter, StringUtil.StringUtilFormatter<Type> formatter)

public static String
join(ExtensibleObject extensibleObject, String delimiter)

public static String
join(ExtensibleObject extensibleObject, String delimiter, StringUtil.StringUtilFormatter<Type> formatter)

public static String
join(Integer[] array, String delimiter)

public static String
join(int[] array, String delimiter)

public static String

Returns:

the input string, padded if necessary.
leftPad
(String
The string to pad (if necessary)
value
,
int
the desired length
length
)

Adds spaces to the left of the input value until the string has reached the given length.

public static String
limitSize(String string, int maxLength)

public static String
private static List<Object>
mergeTokens(List<Object> parsedArray, String endDelimiter)

Delimiters like "//" may span multiple tokens.

public static String

Returns:

the input string, padded if necessary.
pad
(String
The string to pad (if necessary)
value
,
int
the desired length
length
)

Adds spaces to the right of the input value until the string has reached the given length.

public static String[]
processMultiLineSQL(String
A String containing all the SQL statements
multiLineSQL
,
boolean
If true then comments will be stripped, if false then they will be left in the code
stripComments
,
boolean splitStatements, String endDelimiter)

Removes any comments from multiple line SQL using stripComments(String, ChangeSet) and then extracts each individual statement using splitSQL(String, String, ChangeSet).

public static String[]
processMultiLineSQL(String
A String containing all the SQL statements
multiLineSQL
,
boolean
If true then comments will be stripped, if false then they will be left in the code
stripComments
,
boolean splitStatements, String endDelimiter, ChangeSet
the changeset associated with the sql being parsed
changeSet
)

Removes any comments from multiple line SQL using stripComments(String, ChangeSet) and then extracts each individual statement using splitSQL(String, String, ChangeSet).

public static String[]
processMutliLineSQL(String
A String containing all the SQL statements
multiLineSQL
,
boolean
If true then comments will be stripped, if false then they will be left in the code
stripComments
,
boolean splitStatements, String endDelimiter)

Removes any comments from multiple line SQL using stripComments(String, ChangeSet) and then extracts each individual statement using splitSQL(String, String, ChangeSet).

public static String[]
processMutliLineSQL(String
A String containing all the SQL statements
multiLineSQL
,
boolean
If true then comments will be stripped, if false then they will be left in the code
stripComments
,
boolean splitStatements, String endDelimiter, ChangeSet
the changeset associated with the sql being parsed
changeSet
)

Removes any comments from multiple line SQL using stripComments(String, ChangeSet) and then extracts each individual statement using splitSQL(String, String, ChangeSet).

public static String

Returns:

an identifier of the desired length
randomIdentifer
(int
desired length of the string
len
)

Produce a random identifer of the given length, consisting only of uppercase letters.

public static String
repeat(String string, int times)

public static List<String>
public static String[]

Returns:

an array of parsed Strings, null if null String input
splitCamelCase
(final String
the String to split, may be null
str
)

Splits a camel-case string into words based on the came casing.

public static String[]
splitSQL(String multiLineSQL, String endDelimiter)

Splits a candidate multi-line SQL statement along ;'s and "go"'s.

public static String[]
splitSQL(String multiLineSQL, String endDelimiter, ChangeSet
the changeset associated with the sql being parsed
changeSet
)

Splits a candidate multi-line SQL statement along ;'s and "go"'s.

public static String
public static boolean

Returns:

true if value starts with startsWith, false otherwise. Returns false if either argument is null.
startsWith
(String
the string to check
value
,
String
the prefix to check for
startsWith
)

Checks whether the given value starts with the specified startsWith string.

public static String

Returns:

The String without the comments in
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<text>\n (to support the ANSI standard commenting of -- at the end of a line).

public static String

Returns:

The String without the comments in
stripComments
(String multiLineSQL, ChangeSet
the changeset associated with the sql being parsed
changeSet
)

Searches through a String which contains SQL code and strips out any comments that are between \/**\/ or anything that matches SP--SP<text>\n (to support the ANSI standard commenting of -- at the end of a line).

public static String
public static String

Returns:

the stripped SQL string
stripSqlCommentsAndWhitespacesFromTheEnd
(String
the SQL string to strip
sqlString
)

Strips the comments and white spaces from the end of given SQL string.

public static String
toCamelCase(String string)

Converts a kabob-case or underscore_case string to a camel-case one

public static String
toKabobCase(String string)

Converts a camelCase string to a kabob-case one

public static String

Returns:

string without any whitespaces formatted to lowercase.
toLowerWithoutWhitespaces
(String
string to process
value
)

public static String

Returns:

new String without the whitespace at the end
trimRight
(String
String to trim
string
)

Trims whitespace characters from the end of specified string

public static String

Returns:

the trimmed string, or an empty string if the input was null.
trimToEmpty
(String
the input string to trim
string
)

Returns the trimmed (left and right) version of the input string.

public static String

Returns:

the trimmed string or null
trimToNull
(String
the string to trim
string
)

Returns the trimmed (left and right) form of the input string.

public static String
public static String

Returns:

String Output string with new lines
wrap
(final String
The string to split and wrap
inputStr
,
int
The point at which to split the lines
wrapPoint
,
int
Any additional spaces to add
extraLinePadding
)
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.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait