java.lang.Object
io.modelcontextprotocol.util.Utils
Miscellaneous utility methods.
- Author:
- Christian Tzolov
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanCheck whether the givenStringcontains actual text.static booleanisEmpty(Collection<?> collection) Returntrueif the supplied Collection isnullor empty.static booleanReturntrueif the supplied Map isnullor empty.static URIresolveUri(URI baseUrl, String endpointUrl) Resolves the given endpoint URL against the base URL.
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
hasText
Check whether the givenStringcontains actual text.More specifically, this method returns
trueif theStringis notnull, its length is greater than 0, and it contains at least one non-whitespace character.- Parameters:
str- theStringto check (may benull)- Returns:
trueif theStringis notnull, its length is greater than 0, and it does not contain whitespace only- See Also:
-
isEmpty
Returntrueif the supplied Collection isnullor empty. Otherwise, returnfalse.- Parameters:
collection- the Collection to check- Returns:
- whether the given Collection is empty
-
isEmpty
Returntrueif the supplied Map isnullor empty. Otherwise, returnfalse.- Parameters:
map- the Map to check- Returns:
- whether the given Map is empty
-
resolveUri
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
IllegalArgumentExceptionis 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
-