Package io.microsphere.util
Class Assert
- java.lang.Object
-
- io.microsphere.util.BaseUtils
-
- io.microsphere.util.Assert
-
-
Constructor Summary
Constructors Constructor Description Assert()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
assertNoNullElements(java.lang.Iterable<?> elements, java.lang.String message)
Assert that a elements contains nonull
elements.static void
assertNoNullElements(java.lang.Iterable<?> elements, java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that a elements contains nonull
elements.static void
assertNoNullElements(java.lang.Object[] array, java.lang.String message)
Assert that an array contains nonull
elements.static void
assertNoNullElements(java.lang.Object[] array, java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that an array contains nonull
elements.static void
assertNotEmpty(java.lang.Object[] array, java.lang.String message)
Assert that an array contains elements; that is, it must not benull
and must contain at least one element.static void
assertNotEmpty(java.lang.Object[] array, java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that an array contains elements; that is, it must not benull
and must contain at least one element.static void
assertNotEmpty(java.util.Collection<?> collection, java.lang.String message)
Assert that a collection contains elements; that is, it must not benull
and must contain at least one element.static void
assertNotEmpty(java.util.Collection<?> collection, java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that a collection contains elements; that is, it must not benull
and must contain at least one element.static void
assertNotEmpty(java.util.Map<?,?> map, java.lang.String message)
Assert that a Map contains entries; that is, it must not benull
and must contain at least one entry.static void
assertNotEmpty(java.util.Map<?,?> map, java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that a Map contains entries; that is, it must not benull
and must contain at least one entry.static void
assertNotNull(java.lang.Object object, java.lang.String message)
Assert that an object is notnull
.static void
assertNotNull(java.lang.Object object, java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that an object is notnull
.static void
assertNull(java.lang.Object object, java.lang.String message)
Assert that an object isnull
.static void
assertNull(java.lang.Object object, java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that an object isnull
.static void
assertTrue(boolean expression, java.lang.String message)
Assert a boolean expression, throwing anIllegalArgumentException
if the expression evaluates tofalse
.static void
assertTrue(boolean expression, java.util.function.Supplier<java.lang.String> messageSupplier)
Assert a boolean expression, throwing anIllegalArgumentException
if the expression evaluates tofalse
.
-
-
-
Method Detail
-
assertTrue
public static void assertTrue(boolean expression, java.lang.String message)
Assert a boolean expression, throwing anIllegalArgumentException
if the expression evaluates tofalse
.assertTrue(i > 0, "The value must be greater than zero");
- Parameters:
expression
- a boolean expressionmessage
- the exception message to use if the assertion fails- Throws:
java.lang.IllegalArgumentException
- ifexpression
isfalse
-
assertTrue
public static void assertTrue(boolean expression, java.util.function.Supplier<java.lang.String> messageSupplier)
Assert a boolean expression, throwing anIllegalArgumentException
if the expression evaluates tofalse
.assertTrue(i > 0, () -> "The value '" + i + "' must be greater than zero");
- Parameters:
expression
- a boolean expressionmessageSupplier
- a supplier for the exception message to use if the assertion fails- Throws:
java.lang.IllegalArgumentException
- ifexpression
isfalse
-
assertNull
public static void assertNull(@Nullable java.lang.Object object, java.lang.String message)
Assert that an object isnull
.assertNull(value, "The value must be null");
- Parameters:
object
- the object to checkmessage
- the exception message to use if the assertion fails- Throws:
java.lang.IllegalArgumentException
- if the object is notnull
-
assertNull
public static void assertNull(@Nullable java.lang.Object object, java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that an object isnull
.assertNull(value, () -> "The value '" + value + "' must be null");
- Parameters:
object
- the object to checkmessageSupplier
- a supplier for the exception message to use if the assertion fails- Throws:
java.lang.IllegalArgumentException
- if the object is notnull
-
assertNotNull
public static void assertNotNull(@Nullable java.lang.Object object, java.lang.String message)
Assert that an object is notnull
.assertNotNull(clazz, "The class must not be null");
- Parameters:
object
- the object to checkmessage
- the exception message to use if the assertion fails- Throws:
java.lang.IllegalArgumentException
- if the object isnull
-
assertNotNull
public static void assertNotNull(@Nullable java.lang.Object object, java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that an object is notnull
.assertNotNull(entity.getId(), () -> "ID for entity " + entity.getName() + " must not be null");
- Parameters:
object
- the object to checkmessageSupplier
- a supplier for the exception message to use if the assertion fails- Throws:
java.lang.IllegalArgumentException
- if the object isnull
-
assertNotEmpty
public static void assertNotEmpty(@Nullable java.lang.Object[] array, java.lang.String message)
Assert that an array contains elements; that is, it must not benull
and must contain at least one element.assertNotEmpty(array, "The array must contain elements");
- Parameters:
array
- the array to checkmessage
- the exception message to use if the assertion fails- Throws:
java.lang.IllegalArgumentException
- if the object array isnull
or contains no elements
-
assertNotEmpty
public static void assertNotEmpty(@Nullable java.lang.Object[] array, java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that an array contains elements; that is, it must not benull
and must contain at least one element.assertNotEmpty(array, () -> "The " + arrayType + " array must contain elements");
- Parameters:
array
- the array to checkmessageSupplier
- a supplier for the exception message to use if the assertion fails- Throws:
java.lang.IllegalArgumentException
- if the object array isnull
or contains no elements
-
assertNotEmpty
public static void assertNotEmpty(@Nullable java.util.Collection<?> collection, java.lang.String message)
Assert that a collection contains elements; that is, it must not benull
and must contain at least one element.assertNotEmpty(collection, "Collection must contain elements");
- Parameters:
collection
- the collection to checkmessage
- the exception message to use if the assertion fails- Throws:
java.lang.IllegalArgumentException
- if the collection isnull
or contains no elements
-
assertNotEmpty
public static void assertNotEmpty(@Nullable java.util.Collection<?> collection, java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that a collection contains elements; that is, it must not benull
and must contain at least one element.assertNotEmpty(collection, () -> "The " + collectionType + " collection must contain elements");
- Parameters:
collection
- the collection to checkmessageSupplier
- a supplier for the exception message to use if the assertion fails- Throws:
java.lang.IllegalArgumentException
- if the collection isnull
or contains no elements
-
assertNotEmpty
public static void assertNotEmpty(@Nullable java.util.Map<?,?> map, java.lang.String message)
Assert that a Map contains entries; that is, it must not benull
and must contain at least one entry.assertNotEmpty(map, "Map must contain entries");
- Parameters:
map
- the map to checkmessage
- the exception message to use if the assertion fails- Throws:
java.lang.IllegalArgumentException
- if the map isnull
or contains no entries
-
assertNotEmpty
public static void assertNotEmpty(@Nullable java.util.Map<?,?> map, java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that a Map contains entries; that is, it must not benull
and must contain at least one entry.assertNotEmpty(map, () -> "The " + mapType + " map must contain entries");
- Parameters:
map
- the map to checkmessageSupplier
- a supplier for the exception message to use if the assertion fails- Throws:
java.lang.IllegalArgumentException
- if the map isnull
or contains no entries
-
assertNoNullElements
public static void assertNoNullElements(@Nullable java.lang.Object[] array, java.lang.String message)
Assert that an array contains nonull
elements.Note: Does not complain if the array is empty!
assertNoNullElements(array, "The array must contain non-null elements");
- Parameters:
array
- the array to checkmessage
- the exception message to use if the assertion fails- Throws:
java.lang.IllegalArgumentException
- if the object array contains anull
element
-
assertNoNullElements
public static void assertNoNullElements(@Nullable java.lang.Object[] array, java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that an array contains nonull
elements.Note: Does not complain if the array is empty!
assertNoNullElements(array, () -> "The " + arrayType + " array must contain non-null elements");
- Parameters:
array
- the array to checkmessageSupplier
- a supplier for the exception message to use if the assertion fails- Throws:
java.lang.IllegalArgumentException
- if the object array contains anull
element
-
assertNoNullElements
public static void assertNoNullElements(@Nullable java.lang.Iterable<?> elements, java.lang.String message)
Assert that a elements contains nonull
elements.Note: Does not complain if the elements is empty!
assertNoNullElements(elements, "Elements must contain non-null elements");
- Parameters:
elements
- the elements to checkmessage
- the exception message to use if the assertion fails- Throws:
java.lang.IllegalArgumentException
- if the elements contains anull
element
-
assertNoNullElements
public static void assertNoNullElements(@Nullable java.lang.Iterable<?> elements, java.util.function.Supplier<java.lang.String> messageSupplier)
Assert that a elements contains nonull
elements.Note: Does not complain if the elements is empty!
assertNoNullElements(elements, () -> "Collection " + collectionName + " must contain non-null elements");
- Parameters:
elements
- the elements to checkmessageSupplier
- a supplier for the exception message to use if the assertion fails- Throws:
java.lang.IllegalArgumentException
- if the elements contains anull
element
-
-