net.sf.staccatocommons.check
Class Validate<ExceptionType extends Throwable>
java.lang.Object
net.sf.staccatocommons.check.Check<ExceptionType>
net.sf.staccatocommons.check.Validate<ExceptionType>
- Type Parameters:
ExceptionType - the type of the exception this Validate will throw on
failure
public final class Validate<ExceptionType extends Throwable>
- extends Check<ExceptionType>
Validate is a generic Check that on failure will throw a and
exception of a parameterized class.
Typical usage is the following:
Validate
.throwing(MyExceptionType.class)
.that(condition1, message1)
.that(condition2, message2)
..etc..
Since Checks are Transparent, and thus thread safe, it is
possible to cache Validate instances as class atributes and reuse
them across different validations. Example:
private static Validate<IllegalStateException> validate
= Validate.throwing(IllegalStateException.class);
public void foo() {
validate.that(...);
}
public void bar(){
validate.that(...);
}
- Author:
- flbulgarelli
| Methods inherited from class net.sf.staccatocommons.check.Check |
contains, createVarException, fail, failVar, isBetween, isEmpty, isEmpty, isEmpty, isEmpty, isEmpty, isEmpty, isFalse, isGreaterThan, isGreaterThanOrEqualTo, isIn, isInstanceOf, isLessThan, isLessThanOrEqualTo, isMaxSize, isMaxSize, isMinSize, isMinSize, isNotEmpty, isNotEmpty, isNotEmpty, isNotEmpty, isNotEmpty, isNotEmpty, isNotNegative, isNotNegative, isNotNegative, isNotNegative, isNotNegative, isNotNegative, isNotNegative, isNotNull, isNotZero, isNull, isPositive, isPositive, isPositive, isPositive, isPositive, isPositive, isPositive, isSize, isSize, isSize, isSize, isSize, isTrue, isZero, matches, matches, that, thatVar |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
throwing
public static <E extends Throwable> Validate<E> throwing(Class<E> exceptionType)
- Created a new
Validate that will throw an exception of the given
class on failure
- Type Parameters:
E - - Parameters:
exceptionType - the class of exception to throw on check failure
- Returns:
- a new
Validate
createException
protected ExceptionType createException(Check.Failure failure)
- Specified by:
createException in class Check<ExceptionType extends Throwable>