Assert

org.beangle.commons.lang.Assert
object Assert

Assertion tool class

Attributes

Since

3.0.0

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Assert.type

Members list

Value members

Concrete methods

def isTrue(expression: Boolean): Unit

Assert is True

Assert is True

Validate that the argument condition is true; otherwise throwing an exception. This method is useful when validating according to an arbitrary boolean expression, such as validating a primitive number or using your own custom validation expression.

Assert.isTrue(i > 0);
Assert.isTrue(myObject.isOk());

The message of the exception is "The validated expression is false".

Value parameters

expression

the boolean expression to check

Attributes

Throws
IllegalArgumentException

if expression is false

See also

#isTrue(boolean, String, Object...)

def isTrue(expression: Boolean, message: String, values: AnyRef*): Unit

Validate that the argument condition is true;

Validate that the argument condition is true;

otherwise throwing an exception with the specified message. This method is useful when validating according to an arbitrary boolean expression, such as validating a primitive number or using your own custom validation expression.

Assert.isTrue(i >= min && i <= max, "The value must be between %d and %d", min, max);
Assert.isTrue(myObject.isOk(), "The object is not okay");

Value parameters

expression

the boolean expression to check

message

the [[String# format ( String, Object...)]] exception message if invalid, not null

values

the optional values for the formatted exception message, null array not recommended

Attributes

Throws
IllegalArgumentException

if expression is false

See also

#isTrue(boolean)

def noNullElements[T <: Iterable[_]](iterable: T, message: String, values: AnyRef*): T

Validate that the specified argument iterable is neither null nor contains any elements that are null; otherwise throwing an exception with the specified message.

Validate that the specified argument iterable is neither null nor contains any elements that are null; otherwise throwing an exception with the specified message.

Assert.noNullElements(myCollection, "The collection contains null at position %d");

If the iterable is null, then the message in the exception is "The validated object is null".

If the iterable has a null element, then the iteration index of the invalid element is appended to the values argument.

Value parameters

<

T> the iterable type

iterable

the iterable to check, validated not null by this method

message

the [[String# format ( String, Object...)]] exception message if invalid, not null

values

the optional values for the formatted exception message, null array not recommended

Attributes

Returns

the validated iterable (never null method for chaining)

Throws
IllegalArgumentException

if an element is null

NullPointerException

if the array is null

def notEmpty[T <: CharSequence](chars: T): T

Validate that the specified argument array is neither null nor a length of zero (no elements); otherwise throwing an exception.

Validate that the specified argument array is neither null nor a length of zero (no elements); otherwise throwing an exception.

Assert.notEmpty(myArray);

The message in the exception is "The validated array is empty".

Value parameters

<

T> the array type

Attributes

Returns

the validated array (never null method for chaining)

Throws
IllegalArgumentException

if the array is empty

NullPointerException

if the array is null

def notEmpty[T <: CharSequence](chars: T, message: String, values: AnyRef*): T

Validate that the specified argument character sequence is neither null nor a length of zero (no characters); otherwise throwing an exception with the specified message.

Validate that the specified argument character sequence is neither null nor a length of zero (no characters); otherwise throwing an exception with the specified message.

Assert.notEmpty(myString);

The message in the exception is "The validated character sequence is empty".

Value parameters

<

T> the character sequence type

chars

the character sequence to check, validated not null by this method

Attributes

Returns

the validated character sequence (never null method for chaining)

Throws
IllegalArgumentException

if the character sequence is empty

NullPointerException

if the character sequence is null

def notNull[T](value: T): T

Validate that the specified argument is not null; otherwise throwing an exception.

Validate that the specified argument is not null; otherwise throwing an exception.

Assert.notNull(myObject, "The object must not be null");

The message of the exception is "The validated object is null".

Value parameters

value

the object to check

Attributes

Returns

the validated object (never null for method chaining)

Throws
NullPointerException

if the object is null

See also

#notNull(Object, String, Object...)

def notNull[T](value: T, message: String, values: AnyRef*): T

Validate that the specified argument is not null; otherwise throwing an exception with the specified message.

Validate that the specified argument is not null; otherwise throwing an exception with the specified message.

Assert.notNull(myObject, "The object must not be null");

Value parameters

message

the [[String# format ( String, Object...)]] exception message if invalid, not null

object

the object to check

values

the optional values for the formatted exception message

Attributes

Returns

the validated object (never null for method chaining)

Throws
NullPointerException

if the object is null

See also

#notNull(Object)