java.lang.Object
io.modelcontextprotocol.util.Utils

public final class Utils extends Object
Miscellaneous utility methods.
Author:
Christian Tzolov
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • hasText

      public static boolean hasText(@Nullable String str)
      Check whether the given String contains actual text.

      More specifically, this method returns true if the String is not null, its length is greater than 0, and it contains at least one non-whitespace character.

      Parameters:
      str - the String to check (may be null)
      Returns:
      true if the String is not null, its length is greater than 0, and it does not contain whitespace only
      See Also:
    • isEmpty

      public static boolean isEmpty(@Nullable Collection<?> collection)
      Return true if the supplied Collection is null or empty. Otherwise, return false.
      Parameters:
      collection - the Collection to check
      Returns:
      whether the given Collection is empty
    • isEmpty

      public static boolean isEmpty(@Nullable Map<?,?> map)
      Return true if the supplied Map is null or empty. Otherwise, return false.
      Parameters:
      map - the Map to check
      Returns:
      whether the given Map is empty
    • resolveUri

      public static URI resolveUri(URI baseUrl, String endpointUrl)
      Resolves the given endpoint URL against the base URL.
      • If the endpoint URL is relative, it will be resolved against the base URL.
      • If the endpoint URL is absolute, it will be validated to ensure it matches the base URL's scheme, authority, and path prefix.
      • If validation fails for an absolute URL, an IllegalArgumentException is thrown.
      Parameters:
      baseUrl - The base URL (must be absolute)
      endpointUrl - The endpoint URL (can be relative or absolute)
      Returns:
      The resolved endpoint URI
      Throws:
      IllegalArgumentException - If the absolute endpoint URL does not match the base URL or URI is malformed