assert.java

来自「这个是perst-269.zip下面的SOURCECODE,和大家分享了。」· Java 代码 · 共 49 行

JAVA
49
字号
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 + =
减小字号Ctrl + -
显示快捷键?