java.lang.Object
io.modelcontextprotocol.util.Assert
Utility class providing assertion methods for parameter validation.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanCheck whether the givenStringcontains actual text.static voidAssert that the given String contains valid text content; that is, it must not benulland must contain at least one non-whitespace character.static voidAssert a boolean expression, throwing anIllegalArgumentExceptionif the expression evaluates tofalse.static voidnotEmpty(Collection<?> collection, String message) Assert that the collection is notnulland not empty.static voidAssert that an object is notnull.
-
Constructor Details
-
Assert
public Assert()
-
-
Method Details
-
notEmpty
Assert that the collection is notnulland not empty.- Parameters:
collection- the collection to checkmessage- the exception message to use if the assertion fails- Throws:
IllegalArgumentException- if the collection isnullor empty
-
notNull
Assert that an object is notnull.Assert.notNull(clazz, "The class must not be null");
- Parameters:
object- the object to checkmessage- the exception message to use if the assertion fails- Throws:
IllegalArgumentException- if the object isnull
-
hasText
Assert that the given String contains valid text content; that is, it must not benulland must contain at least one non-whitespace character.Assert.hasText(name, "'name' must not be empty");
- Parameters:
text- the String to checkmessage- the exception message to use if the assertion fails- Throws:
IllegalArgumentException- if the text does not contain valid text content
-
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:
-
isTrue
Assert a boolean expression, throwing anIllegalArgumentExceptionif the expression evaluates tofalse.- Parameters:
expression- a boolean expressionmessage- the exception message to use if the assertion fails- Throws:
IllegalArgumentException- ifexpressionisfalse
-