Class Assert

java.lang.Object
org.apache.ofbiz.base.util.Assert

@ThreadSafe public final class Assert extends Object
Basic assertions. The static methods in this class provide a convenient way to test method arguments. All of the methods in this class throw IllegalArgumentException if the method arguments are invalid.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    isAssignableTo(String argumentName, Object argumentObject, Class<?> targetClass)
    Tests if an argument is not null and can be cast to a specified class.
    static void
    isInstanceOf(String argumentName, Object argumentObject, Class<?> targetClass)
    Tests if an argument is not null and is an instance of a specified class.
    static void
    isInstanceOf(String argumentName, Object argumentObject, Class<?>... targetClasses)
    Tests if an argument is not null and is an instance of one of the specified classes.
    static void
    isNotInstanceOf(String argumentName, Object argumentObject, Class<?> targetClass)
    Tests if an argument is not null and is not an instance of a specified class.
    static void
    isNotInstanceOf(String argumentName, Object argumentObject, Class<?>... targetClasses)
    Tests if an argument is not null and is not an instance of one of the specified classes.
    static void
    notEmpty(String argumentName, String argumentObject)
    Tests if an argument is not null and is not empty.
    static <T extends Map<?, ?>>
    void
    notEmpty(String argumentName, T argumentObject)
    Tests if an argument is not null and is not empty.
    static <T> void
    notEmpty(String argumentName, T[] argumentObject)
    Tests if an argument is not null and is not empty.
    static void
    notNull(Object... arguments)
    Tests a list of arguments for null.
    static void
    notNull(String argumentName, Object objectToTest)
    Tests an argument for null.

    Methods inherited from class java.lang.Object

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

    • isAssignableTo

      public static void isAssignableTo(String argumentName, Object argumentObject, Class<?> targetClass)
      Tests if an argument is not null and can be cast to a specified class.

      Assert.isAssignableTo("foo", foo, Foo.class);

      Parameters:
      argumentName -
      argumentObject -
      targetClass -
      Throws:
      IllegalArgumentException
    • isInstanceOf

      public static void isInstanceOf(String argumentName, Object argumentObject, Class<?> targetClass)
      Tests if an argument is not null and is an instance of a specified class.

      Assert.isInstanceOf("foo", foo, Foo.class);

      Parameters:
      argumentName -
      argumentObject -
      targetClass -
      Throws:
      IllegalArgumentException
    • isInstanceOf

      public static void isInstanceOf(String argumentName, Object argumentObject, Class<?>... targetClasses)
      Tests if an argument is not null and is an instance of one of the specified classes.

      Assert.isInstanceOf("foo", foo, Foo.class, Bar.class, ...);

      Parameters:
      argumentName -
      argumentObject -
      targetClasses -
      Throws:
      IllegalArgumentException
    • isNotInstanceOf

      public static void isNotInstanceOf(String argumentName, Object argumentObject, Class<?> targetClass)
      Tests if an argument is not null and is not an instance of a specified class.

      Assert.isNotInstanceOf("foo", foo, Foo.class);

      Parameters:
      argumentName -
      argumentObject -
      targetClass -
      Throws:
      IllegalArgumentException
    • isNotInstanceOf

      public static void isNotInstanceOf(String argumentName, Object argumentObject, Class<?>... targetClasses)
      Tests if an argument is not null and is not an instance of one of the specified classes.

      Assert.isNotInstanceOf("foo", foo, Foo.class, Bar.class, ...);

      Parameters:
      argumentName -
      argumentObject -
      targetClasses -
      Throws:
      IllegalArgumentException
    • notEmpty

      public static void notEmpty(String argumentName, String argumentObject)
      Tests if an argument is not null and is not empty.

      Assert.notEmpty("foo", foo);

      Parameters:
      argumentName -
      argumentObject -
      Throws:
      IllegalArgumentException
    • notEmpty

      public static <T extends Map<?, ?>> void notEmpty(String argumentName, T argumentObject)
      Tests if an argument is not null and is not empty.

      Assert.notEmpty("foo", foo);

      Parameters:
      argumentName -
      argumentObject -
      Throws:
      IllegalArgumentException
    • notEmpty

      public static <T extends Collection<?>> void notEmpty(String argumentName, T argumentObject)
      Tests if an argument is not null and is not empty.

      Assert.notEmpty("foo", foo);

      Parameters:
      argumentName -
      argumentObject -
      Throws:
      IllegalArgumentException
    • notEmpty

      public static <T> void notEmpty(String argumentName, T[] argumentObject)
      Tests if an argument is not null and is not empty.

      Assert.notEmpty("foo", foo);

      Parameters:
      argumentName -
      argumentObject -
      Throws:
      IllegalArgumentException
    • notNull

      public static void notNull(Object... arguments)
      Tests a list of arguments for null.

      Assert.notNull("foo", foo, "bar", bar, ...);

      Parameters:
      arguments -
      Throws:
      IllegalArgumentException
    • notNull

      public static void notNull(String argumentName, Object objectToTest)
      Tests an argument for null.

      Assert.notNull("foo", foo);

      Parameters:
      argumentName -
      objectToTest -
      Throws:
      IllegalArgumentException