📄 assert.java
字号:
package org.garret.perst;
/** Class for checking program invariants. Analog of C <code>assert()</code>
* macro. The Java compiler doesn't provide information about compiled
* file and line number, so the place of assertion failure can be located only
* by analyzing the stack trace of the thrown AssertionFailed exception.
*
* @see org.garret.perst.AssertionFailed
*/
public class Assert {
/** Check specified condition and raise <code>AssertionFailed</code>
* exception if it is not true.
*
* @param cond result of checked condition
*/
public static final void that(boolean cond) {
if (!cond) {
throw new AssertionFailed();
}
}
/** Check specified condition and raise <code>AssertionFailed</code>
* exception if it is not true.
*
* @param description string describing checked condition
* @param cond result of checked condition
*/
public static final void that(String description, boolean cond) {
if (!cond) {
throw new AssertionFailed(description);
}
}
/**
* Throw assertion failed exception.
*/
public static final void failed() {
throw new AssertionFailed();
}
/**
* Throw assertion failed exception with given description.
*/
public static final void failed(String description) {
throw new AssertionFailed(description);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -