Package scriptella.util
Class StringUtils
java.lang.Object
scriptella.util.StringUtils
Miscellaneous String/CharSequence utility methods.
- Version:
- 1.0
- Author:
- Fyodor Kupolov
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringconsoleFormat(String string) Formats specified string for console suitable representation.static StringconsoleFormat(String string, int maxLength) Formats specified string for console suitable representation.static StringgetMaskedPassword(String string) Masks password displaying to user.static booleanChecks if specified characters sequence is empty or contains only ascii whitespace characters.static booleanChecks if specified characters sequence represents a non negative decimal number.static booleanisEmpty(CharSequence cs) Returns true if characters sequence is empty (length=0) or null.static StringReturns Null safe string representation of specified object.static StringReturns a trimmed value for specified charsequencestatic StringPads a String with a specified character.static StringremovePrefix(String string, String prefix) Removes a prefix from a string.
-
Method Details
-
isEmpty
Returns true if characters sequence is empty (length=0) or null.- Parameters:
cs- characters sequence to test.- Returns:
- true if characters sequence is empty (length=0) or null.
-
nullsafeTrim
Returns a trimmed value for specified charsequence- Parameters:
cs- charsequence to trim.- Returns:
- trimmed value for specified charsequence or empty string if cs=null
-
nullsafeToString
Returns Null safe string representation of specified object.- Parameters:
o- object to convert to String.- Returns:
o.toString()or""ifo==null.
-
isAsciiWhitespacesOnly
Checks if specified characters sequence is empty or contains only ascii whitespace characters.- Parameters:
cs- characters sequence to check.- Returns:
- true if characters sequence is empty or contains only ascii whitespace characters.
-
isDecimalInt
Checks if specified characters sequence represents a non negative decimal number.- Parameters:
cs- characters sequence to check.- Returns:
- true if specified characters sequence represents a non negative decimal number.
-
consoleFormat
Formats specified string for console suitable representation.All EOL char sequences are replaced with a single system line.separator, and all other whitespace sequences are replaced with a single space.
String larger than 10KB are trimmed.
- Parameters:
string- string to format. Nulls are allowed.- Returns:
- formatted string.
-
consoleFormat
Formats specified string for console suitable representation.All EOL char sequences are replaced with a single system line.separator, and all other whitespace sequences are replaced with a single space.
- Parameters:
string- string to format. Nulls are allowed.maxLength- maximum number of characters to show or negative if the string cannot be trimmed.- Returns:
- formatted string.
-
removePrefix
Removes a prefix from a string.- Parameters:
string- original string. May be null.prefix- prefix to to check and remove. May be null.- Returns:
- string without a prefix, or unchanged string.
-
getMaskedPassword
Masks password displaying to user.- Parameters:
string- password.- Returns:
- masked password or empty string for empty/null password.
-
pad
Pads a String with a specified character.- Parameters:
str- string to pad. Null is treated as empty string.left- true if left pad, false if rightwidth- with of the padded stringpadChar- character to use for padding- Returns:
- padded string.
-