Package valorless.valorlessutils.json
Class StringUtils
java.lang.Object
valorless.valorlessutils.json.StringUtils
Utility functions related to Strings.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> void
addArgumentsToMap
(Map<@NonNull String, @NonNull Object> argumentsMap, @NonNull Object... argumentPairs) static String
capitalizeAll
(String source) static boolean
Checks if the givenString
contains the specified character.static boolean
containsNewline
(@Nullable String string) static boolean
containsWhitespace
(@Nullable String string) Checks if the given String contains whitespace characters.static String
escapeNewlinesAndBackslash
(String string) static @Nullable String
getNotEmpty
(@Nullable String string) Makes sure that the given String is not empty.static String
getOrEmpty
(@Nullable String string) Makes sure that the given String is notnull
.static boolean
static String
Normalizes the given identifier.static String
normalizeKeepCase
(String identifier) Normalizes the given identifier.static String
removeWhitespace
(String source) Removes all whitespace characters inside the given source String.static String
replaceArguments
(String source, @NonNull Object... argumentPairs) static String
replaceArguments
(String source, Map<? extends @NonNull String, @NonNull ?> arguments) static String
replaceArguments
(String source, MessageArguments arguments) replaceArguments
(Collection<? extends @NonNull String> messages, @NonNull Object... argumentPairs) replaceArguments
(Collection<? extends @NonNull String> sources, Map<? extends @NonNull String, @NonNull ?> arguments) replaceArguments
(Collection<? extends @NonNull String> sources, MessageArguments arguments) static String
replaceFirst
(String source, String target, CharSequence replacement) static String
replaceWhitespace
(String source, String replacement) Replaces all whitespace characters inside the given source String.static @NonNull String[]
splitLines
(String source) static @NonNull String[]
splitLines
(String source, boolean splitLiteralNewlines) static String
stripTrailingNewlines
(String string) static String
toStringOrEmpty
(@Nullable Object object) Converts the givenObject
to a String via itsObject.toString()
method.static @Nullable String
toStringOrNull
(@Nullable Object object) Converts the givenObject
to a String via itsObject.toString()
method.
-
Method Details
-
isEmpty
-
getNotEmpty
Makes sure that the given String is not empty.- Parameters:
string
- the String- Returns:
- the String itself, or
null
if it is empty
-
getOrEmpty
Makes sure that the given String is notnull
.- Parameters:
string
- the String- Returns:
- the String itself, or an empty String if it is
null
-
toStringOrEmpty
Converts the givenObject
to a String via itsObject.toString()
method.If the object is
null
, or if itsObject.toString()
method returnsnull
, this returns an empty String.- Parameters:
object
- the object- Returns:
- the String, not
null
-
toStringOrNull
Converts the givenObject
to a String via itsObject.toString()
method.Returns
null
if the object isnull
, or if itsObject.toString()
method returnsnull
.- Parameters:
object
- the object- Returns:
- the String, possibly
null
-
contains
Checks if the givenString
contains the specified character.This is a shortcut for invoking
String.indexOf(int)
and checking if the return value does not equal-1
.- Parameters:
string
- the Stringcharacter
- the character- Returns:
true
if the String contains the given character
-
normalizeKeepCase
Normalizes the given identifier.This trims leading and trailing whitespace and converts all remaining whitespace and underscores to dashes ('
-
').- Parameters:
identifier
- the identifier, notnull
- Returns:
- the normalized identifier
-
normalize
Normalizes the given identifier.This trims leading and trailing whitespace, converts all remaining whitespace and underscores to dashes ('
-
') and converts all characters to lower case.- Parameters:
identifier
- the identifier, notnull
- Returns:
- the normalized identifier
-
normalize
-
containsWhitespace
Checks if the given String contains whitespace characters.- Parameters:
string
- the String- Returns:
true
if the given String is not empty and contains at least one whitespace character
-
removeWhitespace
Removes all whitespace characters inside the given source String.- Parameters:
source
- the source String, notnull
- Returns:
- the String without any whitespace characters
-
replaceWhitespace
Replaces all whitespace characters inside the given source String.- Parameters:
source
- the source String, notnull
replacement
- the replacement String, notnull
- Returns:
- the String with any whitespace characters replaced
-
capitalizeAll
-
splitLines
-
splitLines
-
stripTrailingNewlines
-
containsNewline
-
escapeNewlinesAndBackslash
-
replaceFirst
-
addArgumentsToMap
-
replaceArguments
-
replaceArguments
-
replaceArguments
-
replaceArguments
public static List<@NonNull String> replaceArguments(Collection<? extends @NonNull String> messages, @NonNull Object... argumentPairs) -
replaceArguments
-
replaceArguments
public static List<@NonNull String> replaceArguments(Collection<? extends @NonNull String> sources, MessageArguments arguments)
-