Package org.apache.ofbiz.base.util
Class Assert
- java.lang.Object
-
- org.apache.ofbiz.base.util.Assert
-
@ThreadSafe public class Assert extends java.lang.Object
Basic assertions. The static methods in this class provide a convenient way to test method arguments. All of the methods in this class throwIllegalArgumentException
if the method arguments are invalid.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
isAssignableTo(java.lang.String argumentName, java.lang.Object argumentObject, java.lang.Class<?> targetClass)
Tests if an argument is not null and can be cast to a specified class.static void
isInstanceOf(java.lang.String argumentName, java.lang.Object argumentObject, java.lang.Class<?> targetClass)
Tests if an argument is not null and is an instance of a specified class.static void
isInstanceOf(java.lang.String argumentName, java.lang.Object argumentObject, java.lang.Class<?>... targetClasses)
Tests if an argument is not null and is an instance of one of the specified classes.static void
isNotInstanceOf(java.lang.String argumentName, java.lang.Object argumentObject, java.lang.Class<?> targetClass)
Tests if an argument is not null and is not an instance of a specified class.static void
isNotInstanceOf(java.lang.String argumentName, java.lang.Object argumentObject, java.lang.Class<?>... targetClasses)
Tests if an argument is not null and is not an instance of one of the specified classes.static void
notEmpty(java.lang.String argumentName, java.lang.String argumentObject)
Tests if an argument is not null and is not empty.static <T extends java.util.Map<?,?>>
voidnotEmpty(java.lang.String argumentName, T argumentObject)
Tests if an argument is not null and is not empty.static <T> void
notEmpty(java.lang.String argumentName, T[] argumentObject)
Tests if an argument is not null and is not empty.static void
notNull(java.lang.Object... arguments)
Tests a list of arguments fornull
.static void
notNull(java.lang.String argumentName, java.lang.Object objectToTest)
Tests an argument fornull
.
-
-
-
Method Detail
-
isAssignableTo
public static void isAssignableTo(java.lang.String argumentName, java.lang.Object argumentObject, java.lang.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:
java.lang.IllegalArgumentException
-
isInstanceOf
public static void isInstanceOf(java.lang.String argumentName, java.lang.Object argumentObject, java.lang.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:
java.lang.IllegalArgumentException
-
isInstanceOf
public static void isInstanceOf(java.lang.String argumentName, java.lang.Object argumentObject, java.lang.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:
java.lang.IllegalArgumentException
-
isNotInstanceOf
public static void isNotInstanceOf(java.lang.String argumentName, java.lang.Object argumentObject, java.lang.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:
java.lang.IllegalArgumentException
-
isNotInstanceOf
public static void isNotInstanceOf(java.lang.String argumentName, java.lang.Object argumentObject, java.lang.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:
java.lang.IllegalArgumentException
-
notEmpty
public static void notEmpty(java.lang.String argumentName, java.lang.String argumentObject)
Tests if an argument is not null and is not empty.Assert.notEmpty("foo", foo);
- Parameters:
argumentName
-argumentObject
-- Throws:
java.lang.IllegalArgumentException
-
notEmpty
public static <T extends java.util.Map<?,?>> void notEmpty(java.lang.String argumentName, T argumentObject)
Tests if an argument is not null and is not empty.Assert.notEmpty("foo", foo);
- Parameters:
argumentName
-argumentObject
-- Throws:
java.lang.IllegalArgumentException
-
notEmpty
public static <T extends java.util.Collection<?>> void notEmpty(java.lang.String argumentName, T argumentObject)
Tests if an argument is not null and is not empty.Assert.notEmpty("foo", foo);
- Parameters:
argumentName
-argumentObject
-- Throws:
java.lang.IllegalArgumentException
-
notEmpty
public static <T> void notEmpty(java.lang.String argumentName, T[] argumentObject)
Tests if an argument is not null and is not empty.Assert.notEmpty("foo", foo);
- Parameters:
argumentName
-argumentObject
-- Throws:
java.lang.IllegalArgumentException
-
notNull
public static void notNull(java.lang.Object... arguments)
Tests a list of arguments fornull
.Assert.notNull("foo", foo, "bar", bar, ...);
- Parameters:
arguments
-- Throws:
java.lang.IllegalArgumentException
-
notNull
public static void notNull(java.lang.String argumentName, java.lang.Object objectToTest)
Tests an argument fornull
.Assert.notNull("foo", foo);
- Parameters:
argumentName
-objectToTest
-- Throws:
java.lang.IllegalArgumentException
-
-