Class StringUtils

java.lang.Object
dev.metaschema.core.util.StringUtils

public final class StringUtils extends Object
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 Details

    • requireNonEmpty

      @NonNull public static String requireNonEmpty(@NonNull String string)
      Require a non-empty string value.
      Parameters:
      string - the object reference to check for emptiness
      Returns:
      string if not null or empty
      Throws:
      NullPointerException - if string is null
      IllegalArgumentException - if string is empty
    • requireNonEmpty

      @NonNull public static String requireNonEmpty(@NonNull String string, @NonNull String message)
      Require a non-empty string value.
      Parameters:
      string - the object reference to check for emptiness
      message - detail message to be used in the event that an IllegalArgumentException is thrown
      Returns:
      string if not null or empty
      Throws:
      NullPointerException - if string is null
      IllegalArgumentException - if string is empty
    • replaceTokens

      public static CharSequence replaceTokens(@NonNull CharSequence text, @NonNull Pattern pattern, @NonNull Function<Matcher,CharSequence> replacementFunction)
      Searches for instances of pattern in text. Replace each matching occurrence using the replacementFunction.

      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 search
      pattern - the pattern to search for
      replacementFunction - a function that will provided the replacement text
      Returns:
      the resulting text after replacing matching occurrences in text