public final class JkUtilsString
extends java.lang.Object
Constructor and Description |
---|
JkUtilsString() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
blankToNull(java.lang.String in)
Converts a blank string to null.
|
static java.lang.String |
capitalize(java.lang.String string)
Returns the specified string but upper-casing its first character.
|
static boolean |
containsAny(java.lang.String stringToMatch,
java.lang.String... candidates)
Checks if the given string contains any of the specified candidate substrings.
|
static int |
countOccurrence(java.lang.String matchedString,
char occurrence)
Returns occurrence count of the specified character into the specified string.
|
static java.lang.String |
ellipse(java.lang.String string,
int max)
Returns the specified string truncated and ending with ... if the specified
string is longer than the specified max length.
|
static java.lang.String |
emptyToNull(java.lang.String in)
Converts an empty or blank string to null.
|
static boolean |
endsWithAny(java.lang.String stringToMatch,
java.lang.String... candidates)
Returns
true if the specified string ends with any of the
candidates. |
static java.util.List<java.lang.String> |
extractVariableToken(java.lang.String string)
Extracts variable tokens enclosed in `${}` from the provided string.
|
static java.lang.String |
firstMatching(java.lang.String stringToMatch,
java.lang.String... candidates)
Returns the first string out of the specified candidates matching the
specified string.
|
static java.lang.String |
formatOptions(java.util.List<java.lang.String> options)
Converts a list of options into a formatted string representation.
|
static java.lang.String |
interpolate(java.lang.String string,
java.util.function.Function<java.lang.String,java.lang.String> replacer)
Replaces variable tokens in the given string with the corresponding values
provided by the replacer function.
|
static boolean |
isBlank(java.lang.String string)
Checks if a String is whitespace, empty ("") or null.
|
static boolean |
isDigits(java.lang.String string)
Checks if the provided string consists only of digits.
|
static java.lang.String |
nullToEmpty(java.lang.String in)
Converts a null string to an empty string.
|
static java.lang.String |
padEnd(java.lang.String string,
int minLength,
char padChar)
Pads the given string with the specified pad character to ensure it reaches the minimum length.
|
static java.lang.String |
padStart(java.lang.String string,
int minLength,
char padChar)
Pads the given string with the specified pad character to ensure it reaches the minimum length.
|
static java.lang.String[] |
parseCommandline(java.lang.String commandline)
Parses a command line string and splits it into an array of individual command line arguments.
|
static java.util.List<java.lang.String> |
parseCommandlineAsList(java.lang.String commandline) |
static java.lang.String |
pluralize(int count,
java.lang.String singular)
Returns a string containing the quantity and noun.
|
static java.lang.String |
pluralize(int count,
java.lang.String singular,
java.lang.String plural)
Returns a string containing the quantity and noun.
|
static java.lang.String |
readableCommandAgs(java.lang.String margin,
java.util.List<java.lang.String> options)
Returns a readable representation of command line arguments.
|
static java.lang.String |
removePackagePrefix(java.lang.String fullName)
Removes the package prefix from a fully qualified name, leaving only the last class name
and the subsequent part (e.g., method name or variable).
|
static java.lang.String |
repeat(java.lang.String pattern,
int count)
Returns a string made of the specified pattern repeat the
specified count.
|
static java.lang.String |
shortenPackageName(java.lang.String fullName)
Shortens a fully qualified package name by abbreviating all segments except the last class name
and appends the remaining part after the class, preserving the structure.
|
static java.util.List<java.lang.String> |
splitWhiteSpaces(java.lang.String string)
Splits the provided string into a list of substrings based on whitespace.
|
static boolean |
startsWithAny(java.lang.String stringToMatch,
java.lang.String... stringToCheckEquals)
Returns
true if the specified string starts with any of the
candidates. |
static boolean |
startsWithUpperCase(java.lang.String str)
Checks if the given string starts with an uppercase letter.
|
static java.lang.String |
substringAfterFirst(java.lang.String string,
java.lang.String delimiter)
Returns the substring after the first delimiter of the specified
occurrence.
|
static java.lang.String |
substringAfterLast(java.lang.String string,
java.lang.String delimiter)
Returns the substring after the last delimiter of the specified
occurrence.
|
static java.lang.String |
substringBeforeFirst(java.lang.String string,
java.lang.String delimiter)
Returns the substring before the first delimiter of the specified
occurrence.
|
static java.lang.String |
substringBeforeLast(java.lang.String string,
java.lang.String delimiter)
Returns the substring before the last delimiter of the specified
occurrence.
|
static java.lang.String |
toHexString(byte[] raw)
Returns the hexadecimal for of the given array of bytes.
|
static java.lang.String |
uncapitalize(java.lang.String string)
Returns the specified string but lower-casing its first character.
|
static java.lang.String |
withLeftMargin(java.lang.String paragraph,
java.lang.String margin)
Returns a string with a left margin added to each line.
|
static java.lang.String |
wrapStringCharacterWise(java.lang.String input,
int maxLineLength)
Wraps the given string character-wise to fit within the specified width.
|
public static java.lang.String capitalize(java.lang.String string)
public static java.lang.String uncapitalize(java.lang.String string)
public static java.lang.String firstMatching(java.lang.String stringToMatch, java.lang.String... candidates)
public static int countOccurrence(java.lang.String matchedString, char occurrence)
public static java.lang.String substringAfterLast(java.lang.String string, java.lang.String delimiter)
public static java.lang.String substringBeforeFirst(java.lang.String string, java.lang.String delimiter)
public static java.lang.String substringAfterFirst(java.lang.String string, java.lang.String delimiter)
public static java.lang.String substringBeforeLast(java.lang.String string, java.lang.String delimiter)
public static java.lang.String repeat(java.lang.String pattern, int count)
repeat("##", 3)
will return ######public static java.lang.String pluralize(int count, java.lang.String singular, java.lang.String plural)
public static java.lang.String pluralize(int count, java.lang.String singular)
public static java.lang.String toHexString(byte[] raw) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public static boolean endsWithAny(java.lang.String stringToMatch, java.lang.String... candidates)
true
if the specified string ends with any of the
candidates.public static boolean containsAny(java.lang.String stringToMatch, java.lang.String... candidates)
public static boolean startsWithAny(java.lang.String stringToMatch, java.lang.String... stringToCheckEquals)
true
if the specified string starts with any of the
candidates.public static boolean startsWithUpperCase(java.lang.String str)
str
- the string to check; may be null or emptytrue
if the string starts with an uppercase letter, false
otherwisepublic static boolean isBlank(java.lang.String string)
public static boolean isDigits(java.lang.String string)
public static java.util.List<java.lang.String> extractVariableToken(java.lang.String string)
string
- the input string from which to extract variable tokenspublic static java.lang.String interpolate(java.lang.String string, java.util.function.Function<java.lang.String,java.lang.String> replacer)
string
- the input string containing variable tokens to be replacedreplacer
- a function that takes a variable token (without `${}`)
and returns the replacement value for the tokenjava.lang.IllegalArgumentException
- if no replacement is defined for a tokenpublic static java.lang.String ellipse(java.lang.String string, int max)
public static java.lang.String[] parseCommandline(java.lang.String commandline)
Borrowed from ANT.
commandline
- the command line string to parsejava.lang.IllegalArgumentException
- if there are unbalanced quotes in the command line stringpublic static java.util.List<java.lang.String> parseCommandlineAsList(java.lang.String commandline)
parseCommandline(String)
public static java.lang.String padEnd(java.lang.String string, int minLength, char padChar)
string
- The string to pad.minLength
- The minimum length the resulting string should have.padChar
- The character to use for padding.public static java.lang.String padStart(java.lang.String string, int minLength, char padChar)
string
- The string to pad.minLength
- The minimum length the resulting string should have.padChar
- The character to use for padding.public static java.lang.String blankToNull(java.lang.String in)
in
- the input stringpublic static java.lang.String nullToEmpty(java.lang.String in)
in
- the input stringpublic static java.lang.String emptyToNull(java.lang.String in)
public static java.lang.String wrapStringCharacterWise(java.lang.String input, int maxLineLength)
public static java.lang.String withLeftMargin(java.lang.String paragraph, java.lang.String margin)
public static java.lang.String readableCommandAgs(java.lang.String margin, java.util.List<java.lang.String> options)
public static java.lang.String shortenPackageName(java.lang.String fullName)
fullName
- The fully qualified package name including the class and optionally the method.
If null or if the input does not contain any dot, it is returned as-is.public static java.lang.String removePackagePrefix(java.lang.String fullName)
fullName
- The fully qualified name from which the package prefix should be removed.
If the input is null or does not contain a dot, it is returned as-is.public static java.util.List<java.lang.String> splitWhiteSpaces(java.lang.String string)
Null or empty sting result in an empty list.
public static java.lang.String formatOptions(java.util.List<java.lang.String> options)
options
- the list of options to be formatted as a string