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> voidaddArgumentsToMap(Map<@NonNull String, @NonNull Object> argumentsMap, @NonNull Object... argumentPairs) static StringcapitalizeAll(String source) static booleanChecks if the givenStringcontains the specified character.static booleancontainsNewline(@Nullable String string) static booleancontainsWhitespace(@Nullable String string) Checks if the given String contains whitespace characters.static StringescapeNewlinesAndBackslash(String string) static @Nullable StringgetNotEmpty(@Nullable String string) Makes sure that the given String is not empty.static StringgetOrEmpty(@Nullable String string) Makes sure that the given String is notnull.static booleanstatic StringNormalizes the given identifier.static StringnormalizeKeepCase(String identifier) Normalizes the given identifier.static StringremoveWhitespace(String source) Removes all whitespace characters inside the given source String.static StringreplaceArguments(String source, @NonNull Object... argumentPairs) static StringreplaceArguments(String source, Map<? extends @NonNull String, @NonNull ?> arguments) static StringreplaceArguments(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 StringreplaceFirst(String source, String target, CharSequence replacement) static StringreplaceWhitespace(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 StringstripTrailingNewlines(String string) static StringtoStringOrEmpty(@Nullable Object object) Converts the givenObjectto a String via itsObject.toString()method.static @Nullable StringtoStringOrNull(@Nullable Object object) Converts the givenObjectto 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
nullif 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 givenObjectto 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 givenObjectto a String via itsObject.toString()method.Returns
nullif the object isnull, or if itsObject.toString()method returnsnull.- Parameters:
object- the object- Returns:
- the String, possibly
null
-
contains
Checks if the givenStringcontains 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:
trueif 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:
trueif 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, notnullreplacement- 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)
-