java.lang.Object
dev.metaschema.core.util.StringUtils
Provides a collection of utilities for checking and managing strings.
This utility class provides methods for string validation and manipulation, with strict null-safety guarantees. All methods in this class are thread-safe and throw appropriate exceptions for invalid inputs.
-
Method Summary
Modifier and TypeMethodDescriptionstatic CharSequencereplaceTokens(CharSequence text, Pattern pattern, Function<Matcher, CharSequence> replacementFunction) Searches for instances ofpatternintext.static StringrequireNonEmpty(String string) Require a non-empty string value.static StringrequireNonEmpty(String string, String message) Require a non-empty string value.
-
Method Details
-
requireNonEmpty
Require a non-empty string value.- Parameters:
string- the object reference to check for emptiness- Returns:
stringif notnullor empty- Throws:
NullPointerException- ifstringisnullIllegalArgumentException- ifstringis empty
-
requireNonEmpty
Require a non-empty string value.- Parameters:
string- the object reference to check for emptinessmessage- detail message to be used in the event that anIllegalArgumentExceptionis thrown- Returns:
stringif notnullor empty- Throws:
NullPointerException- ifstringisnullIllegalArgumentException- ifstringis empty
-
replaceTokens
public static CharSequence replaceTokens(@NonNull CharSequence text, @NonNull Pattern pattern, @NonNull Function<Matcher, CharSequence> replacementFunction) Searches for instances ofpatternintext. Replace each matching occurrence using thereplacementFunction.This method builds a new string by efficiently copying unmatched segments and applying the replacement function only to matched portions.
- Parameters:
text- the text to searchpattern- the pattern to search forreplacementFunction- a function that will provided the replacement text- Returns:
- the resulting text after replacing matching occurrences in
text
-