public class StringUtils
extends java.lang.Object
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
emptyToNull(java.lang.String input)
Converts an empty string into a
null . |
static boolean |
isNullOrEmpty(java.lang.String input)
Check if the provided string is either
null or empty. |
static java.lang.String |
makeRandomString(int length)
Produces a random string of the provided length.
|
static java.util.Optional<java.lang.String> |
nonEmptyOptional(java.lang.String input)
Simple utility function for returning an
Optional that if contents present are
guaranteed to not be empty. |
static java.lang.String |
nullToEmpty(java.lang.String input)
Makes sure a given string is not
null . |
static java.lang.String |
padEnd(java.lang.String sourceStr,
int minLength,
char padChar)
Pads the end of the provided string with the provided character until a minimum length is
reached.
|
static java.lang.String |
padStart(java.lang.String sourceStr,
int minLength,
char padChar)
Pads the start of the provided string with the provided character until a minimum length is
reached.
|
public static java.lang.String nullToEmpty(java.lang.String input)
null
. If it is not null
, the provided string
is immediately returned. If it IS null
, then an empty string is returned.input
- String which should be returned if not null
null
, otherwise an empty stringpublic static java.lang.String emptyToNull(java.lang.String input)
null
. If it is not empty or null
, the
provided string is immediately returned.input
- String which should be returned if not null
or emptynull
public static boolean isNullOrEmpty(java.lang.String input)
null
or empty.input
- String to check againsttrue
if the provided string is null
or has no contentpublic static java.util.Optional<java.lang.String> nonEmptyOptional(java.lang.String input)
Optional
that if contents present are
guaranteed to not be empty. Basically taking the empty case into consideration in addition
to Optional.ofNullable(Object)
's normal null
check.input
- String to be contained in returned Optional
if not null or emptypublic static java.lang.String padStart(java.lang.String sourceStr, int minLength, char padChar)
null
it will be returned as an empty
string, padded to the minimum length.sourceStr
- String to start from, this will be the end of the returned result stringminLength
- Minimum number of characters the returned string should bepadChar
- Character to pad on to the start of to reach the minimum lengthpublic static java.lang.String padEnd(java.lang.String sourceStr, int minLength, char padChar)
null
it will be returned as an empty
string, padded to the minimum length.sourceStr
- String to start from, this will be the start of the returned result stringminLength
- Minimum number of characters the returned string should bepadChar
- Character to pad on to the end of to reach the minimum lengthpublic static java.lang.String makeRandomString(int length)
length
- Number of characters the resulting string should be.