java.lang.Object
io.modelcontextprotocol.util.Assert

public final class Assert extends Object
Utility class providing assertion methods for parameter validation.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Check whether the given String contains actual text.
    static void
    hasText(String text, String message)
    Assert that the given String contains valid text content; that is, it must not be null and must contain at least one non-whitespace character.
    static void
    notEmpty(Collection<?> collection, String message)
    Assert that the collection is not null and not empty.
    static void
    notNull(Object object, String message)
    Assert that an object is not null.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Assert

      public Assert()
  • Method Details

    • notEmpty

      public static void notEmpty(@Nullable Collection<?> collection, String message)
      Assert that the collection is not null and not empty.
      Parameters:
      collection - the collection to check
      message - the exception message to use if the assertion fails
      Throws:
      IllegalArgumentException - if the collection is null or empty
    • notNull

      public static void notNull(@Nullable Object object, String message)
      Assert that an object is not null.
       Assert.notNull(clazz, "The class must not be null");
       
      Parameters:
      object - the object to check
      message - the exception message to use if the assertion fails
      Throws:
      IllegalArgumentException - if the object is null
    • hasText

      public static void hasText(@Nullable String text, String message)
      Assert that the given String contains valid text content; that is, it must not be null and must contain at least one non-whitespace character.
      Assert.hasText(name, "'name' must not be empty");
      Parameters:
      text - the String to check
      message - the exception message to use if the assertion fails
      Throws:
      IllegalArgumentException - if the text does not contain valid text content
    • 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: