validState static method

void validState(
  1. bool expression, [
  2. String message = DEFAULT_VALID_STATE_EX_MESSAGE
])

Validate that the stateful 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.

Validate.validState(field > 0);
Validate.validState(this.isOk());

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

expression the boolean expression to check Throws IllegalStateException if expression is false

Implementation

static void validState(bool expression,
    [String message = DEFAULT_VALID_STATE_EX_MESSAGE]) {
  if (expression == false) {
    throw new IllegalStateError(message);
  }
}