Package migratedb.core.internal.util
Enum StringUtils
- java.lang.Object
-
- java.lang.Enum<StringUtils>
-
- migratedb.core.internal.util.StringUtils
-
- All Implemented Interfaces:
Serializable,Comparable<StringUtils>
public enum StringUtils extends Enum<StringUtils>
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringarrayToCommaDelimitedString(Object[] strings)Turns this string array in one comma-delimited string.static StringarrayToDelimitedString(String delimiter, Object[] strings)Turns this string array in one delimited string.static StringcollapseWhitespace(String str)Replaces all sequences of whitespace by a single blank.static StringcollectionToCommaDelimitedString(Collection<?> collection)Convenience method to return a Collection as a comma-delimited String. e.g. useful fortoString()implementations.static StringcollectionToDelimitedString(Collection<?> collection, String delimiter)Convenience method to return a Collection as a delimited String.static StringgetFileExtension(String path)static booleanhasLength(String str)Checks whether this string is notnulland not empty.static booleanhasText(String s)Checks whether this string isn'tnulland contains at least one non-blank character.static booleanisCharAnyOf(char c, String chars)Checks whether this character matches any of these characters.static Stringleft(String str, int count)Returns the first n characters from this string, where n = count.static StringleftPad(String original, int length, char padChar)static Stringreplace(String inString, String oldPattern, String newPattern)Replace all occurrences of a substring within a string with another string.static StringreplaceAll(String str, String originalToken, String replacementToken)Replaces all occurrences of this originalToken in this string with this replacementToken.static booleanstartsAndEndsWith(String str, String prefix, String... suffixes)Checks whetherstrboth begins with this prefix and ends withs either of these suffixes.static String[]tokenizeToStringArray(String str, String delimiters)Splits this string into an array using these delimiters.static List<String>tokenizeToStringCollection(String str, char delimiterChar, char groupDelimiterChar)Splits this string into a collection using this delimiter and this group delimiter.static List<String>tokenizeToStringCollection(String str, String delimiters)Splits this string into a collection using these delimiters.static StringtrimChar(String s, char c)static StringtrimLeadingCharacter(String str, char character)Trim any leading occurrence of this character from the given String.static StringtrimOrLeftPad(String str, int length, char padChar)Trims or pads this string, so it has this exact length.static StringtrimOrPad(String str, int length)Trims or pads (with spaces) this string, so it has this exact length.static StringtrimOrPad(String str, int length, char padChar)Trims or pads this string, so it has this exact length.static StringUtilsvalueOf(String name)Returns the enum constant of this type with the specified name.static StringUtils[]values()Returns an array containing the constants of this enum type, in the order they are declared.static StringwordWrap(String str, int lineSize)Wrap this string at the word boundary at or below lineSize characters.static Stringwrap(String str, int lineSize)Wrap this string every lineSize characters.
-
-
-
Method Detail
-
values
public static StringUtils[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (StringUtils c : StringUtils.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static StringUtils valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
trimOrPad
public static String trimOrPad(String str, int length)
Trims or pads (with spaces) this string, so it has this exact length.- Parameters:
str- The string to adjust.nullis treated as an empty string.length- The exact length to reach.- Returns:
- The adjusted string.
-
trimOrPad
public static String trimOrPad(String str, int length, char padChar)
Trims or pads this string, so it has this exact length.- Parameters:
str- The string to adjust.nullis treated as an empty string.length- The exact length to reach.padChar- The padding character.- Returns:
- The adjusted string.
-
trimOrLeftPad
public static String trimOrLeftPad(String str, int length, char padChar)
Trims or pads this string, so it has this exact length.- Parameters:
str- The string to adjust.nullis treated as an empty string.length- The exact length to reach.padChar- The padding character.- Returns:
- The adjusted string.
-
collapseWhitespace
public static String collapseWhitespace(String str)
Replaces all sequences of whitespace by a single blank. Ex.: " "->" "- Parameters:
str- The string to analyse.- Returns:
- The input string, with all whitespace collapsed.
-
left
public static String left(String str, int count)
Returns the first n characters from this string, where n = count. If the string is shorter, the entire string will be returned. If the string is longer, it will be truncated.- Parameters:
str- The string to parse.count- The amount of characters to return.- Returns:
- The first n characters from this string, where n = count.
-
replaceAll
public static String replaceAll(String str, String originalToken, String replacementToken)
Replaces all occurrences of this originalToken in this string with this replacementToken.- Parameters:
str- The string to process.originalToken- The token to replace.replacementToken- The replacement.- Returns:
- The transformed str.
-
hasLength
public static boolean hasLength(String str)
Checks whether this string is notnulland not empty.- Parameters:
str- The string to check.- Returns:
trueif it has content,falseif it isnullor blank.
-
arrayToCommaDelimitedString
public static String arrayToCommaDelimitedString(Object[] strings)
Turns this string array in one comma-delimited string.- Parameters:
strings- The array to process.- Returns:
- The new comma-delimited string. An empty string if
stringsis empty.nullif strings isnull.
-
arrayToDelimitedString
public static String arrayToDelimitedString(String delimiter, Object[] strings)
Turns this string array in one delimited string.- Parameters:
delimiter- The delimiter to use.strings- The array to process.- Returns:
- The new delimited string. An empty string if
stringsis empty.nullif strings isnull.
-
hasText
public static boolean hasText(String s)
Checks whether this string isn'tnulland contains at least one non-blank character.- Parameters:
s- The string to check.- Returns:
trueif it has text,falseif not.
-
tokenizeToStringArray
public static String[] tokenizeToStringArray(String str, String delimiters)
Splits this string into an array using these delimiters.- Parameters:
str- The string to split.delimiters- The delimiters to use.- Returns:
- The resulting array.
-
tokenizeToStringCollection
public static List<String> tokenizeToStringCollection(String str, String delimiters)
Splits this string into a collection using these delimiters.- Parameters:
str- The string to split.delimiters- The delimiters to use.- Returns:
- The resulting array.
-
tokenizeToStringCollection
public static List<String> tokenizeToStringCollection(String str, char delimiterChar, char groupDelimiterChar)
Splits this string into a collection using this delimiter and this group delimiter.- Parameters:
str- The string to split.delimiterChar- The delimiter to use.groupDelimiterChar- The character to use to delimit groups.- Returns:
- The resulting array.
-
replace
public static String replace(String inString, String oldPattern, String newPattern)
Replace all occurrences of a substring within a string with another string.- Parameters:
inString- String to examineoldPattern- String to replacenewPattern- String to insert- Returns:
- a String with the replacements
-
collectionToCommaDelimitedString
public static String collectionToCommaDelimitedString(Collection<?> collection)
Convenience method to return a Collection as a comma-delimited String. e.g. useful fortoString()implementations.- Parameters:
collection- the Collection to analyse- Returns:
- The comma-delimited String.
-
collectionToDelimitedString
public static String collectionToDelimitedString(Collection<?> collection, String delimiter)
Convenience method to return a Collection as a delimited String. E.g. useful fortoString()implementations.- Parameters:
collection- the Collection to analysedelimiter- The delimiter.- Returns:
- The delimited String.
-
trimLeadingCharacter
public static String trimLeadingCharacter(String str, char character)
Trim any leading occurrence of this character from the given String.- Parameters:
str- the String to check.character- The character to trim.- Returns:
- the trimmed String
- See Also:
Character.isWhitespace(char)
-
startsAndEndsWith
public static boolean startsAndEndsWith(String str, String prefix, String... suffixes)
Checks whetherstrboth begins with this prefix and ends withs either of these suffixes.- Parameters:
str- The string to check.prefix- The prefix.suffixes- The suffixes.- Returns:
trueif it does,falseif not.
-
wrap
public static String wrap(String str, int lineSize)
Wrap this string every lineSize characters.- Parameters:
str- The string to wrap.lineSize- The maximum size of each line.- Returns:
- The wrapped string.
-
wordWrap
public static String wordWrap(String str, int lineSize)
Wrap this string at the word boundary at or below lineSize characters.- Parameters:
str- The string to wrap.lineSize- The maximum size of each line.- Returns:
- The word-wrapped string.
-
isCharAnyOf
public static boolean isCharAnyOf(char c, String chars)Checks whether this character matches any of these characters.- Parameters:
c- The char to check.chars- The chars that should match.- Returns:
trueif it does,false if not.
-
-