bb.util
Class Check.Assert
java.lang.Object
bb.util.Check
bb.util.Check.CheckAdaptor
bb.util.Check.Assert
- Enclosing class:
- Check
public static class Check.Assert
- extends Check.CheckAdaptor
Concrete subclass of Check
which is meant for checking arbitrary state.
Hence, it merely implements onFailure
(which here always throws an AssertionError)
and overrides no other methods.
The essential new feature added by this class compared to Check.State
is that it only performs checks
if assert
is enabled for this class.
However, if assert is disabled for this class, then all of the checking methods do nothing
(indeed, a good optimizing compiler like hotspot may effectively eliminate them).
This class should only be used if it is necessary to have the option of suppressing checking.
Because checking methods typically have minimal performance impact,
Check.State
should be used in preference to this class
unless checking is known to degrade performance excessively.
Another issue is that assert can not only be enabled globally, but can also be selectively enabled for just a package or class.
So, if assert is enabled for this class,
then all other classes which call this class will have checks performed
even if assert is disabled for those calling classes.
Conversely, if assert is disabled for this class,
then all other classes which call this class will have no checks performed
even if assert is enabled for those calling classes.
Users should also know that the AssertionError thrown by this class's onFailure method
will not caught by a standard catch (Exception e)
clause.
The user may need to change their generic catching code to catch (Throwable t)
instead.
This class is multithread safe: it adds no state to its multithread safe superclass.
Method Summary |
void |
onFailure(String errMsg,
Throwable throwable)
Called whenever a check fails and the code has both errMsg and throwable to report. |
Methods inherited from class bb.util.Check |
arg, azzert, edt, empty, equals, equals, equals, equals, equals, equals, equals, equals, equals, hasSize, hasSize, hasSize, hasSize, hasSize, hasSize, hasSize, hasSize, hasSize, hasSize, hasSize, infinite, infinite, isFalse, isNull, isTrue, naN, naN, negative, negative, negative, negative, negative, negative, normal, normal, normalNegative, normalNegative, normalNotNegative, normalNotNegative, normalNotPositive, normalNotPositive, normalPositive, normalPositive, notBlank, notEmpty, notEmpty, notEmpty, notEmpty, notEmpty, notEmpty, notEmpty, notEmpty, notEmpty, notEmpty, notEmpty, notInfinite, notInfinite, notNaN, notNaN, notNegative, notNegative, notNegative, notNegative, notNegative, notNegative, notNull, notPositive, notPositive, notPositive, notPositive, notPositive, notPositive, notZero, notZero, notZero, notZero, notZero, notZero, positive, positive, positive, positive, positive, positive, state, unmodifiable, unmodifiable, validDirectory, validFile, validIndex, validIndex, validIndex, validIndex, validIndex, validIndex, validIndex, validIndex, validIndex, validIndex, validOffsetLength, validPort, validProbability, zero, zero, zero, zero, zero, zero |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
assertEnabled
static final boolean assertEnabled
Check.Assert
public Check.Assert()
- Constructor.
onFailure
public void onFailure(String errMsg,
Throwable throwable)
throws AssertionError
- Called whenever a check fails and the code has both errMsg and throwable to report.
- Specified by:
onFailure
in class Check
- Throws:
AssertionError
- with errMsg as its message