Class Assert<T>

  • Type Parameters:
    T - the type of the object the Assert class verifies.

    public final class Assert<T>
    extends java.lang.Object
    Class for checking the validity of a provided object.
    Since:
    1.6
    Author:
    Alexandra Buzila
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T check()
      Usage example:
      Assert.create(Object object).notNull().ofClass(Class clazz).check().
      static <T> Assert<T> create​(T object)  
      Assert<T> notNull()
      Checks if the object is null, in which case an IllegalArgumentException is thrown.
      Assert<?> ofClass​(java.lang.Class<?> clazz)
      Checks if the object has a different type than the Class provided as parameter, in which case an IllegalArgumentException is thrown.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • create

        public static <T> Assert<T> create​(T object)
        Type Parameters:
        T - the type of the object the Assert class verifies.
        Parameters:
        object - the object that will be checked
        Returns:
        a new instance of the Assert class.
      • notNull

        public Assert<T> notNull()
        Checks if the object is null, in which case an IllegalArgumentException is thrown.
        Returns:
        the Assert instance, when no exception is thrown.
      • ofClass

        public Assert<?> ofClass​(java.lang.Class<?> clazz)
        Checks if the object has a different type than the Class provided as parameter, in which case an IllegalArgumentException is thrown.
        Parameters:
        clazz - the Class against which the type of the object is checked.
        Returns:
        the Assert instance, when no exception is thrown.
      • check

        public T check()
        Usage example:
        Assert.create(Object object).notNull().ofClass(Class clazz).check().
        Returns:
        the object for which the Assert is created.