assert.java
来自「kaffe Java 解释器语言,源码,Java的子集系统,开放源代码」· Java 代码 · 共 130 行
JAVA
130 行
/* * Java core library component. * * Copyright (c) 1997, 1998 * Transvirtual Technologies, Inc. All rights reserved. * * See the file "license.terms" for information on usage and redistribution * of this file. */package kaffe.util;/** * This class consists of static methods that perform assertion checks. * If a check fails, we throw an error with a descriptive message. */public class Assert { private static final String MSG = "assertion failure"; /** * Throw an error if not <code>true</code>. * * @param x The value to test */ public static void that(boolean x) { if (!x) { fail(); } } /** * Throw an error if not <code>true</code>. * * @param x The value to test * @param msg Description of the failure */ public static void that(boolean x, String msg) { if (!x) { fail(msg); } } /** * Throw an error if equal to zero. * * @param x The value to test */ public static void that(long x) { if (x == 0) { fail(); } } /** * Throw an error if equal to zero. * * @param x The value to test * @param msg Description of the failure */ public static void that(long x, String msg) { if (x == 0) { fail(msg); } } /** * Throw an error if equal to zero. * * @param x The value to test */ public static void that(double x) { if (x == 0.0) { fail(); } } /** * Throw an error if equal to zero. * * @param x The value to test * @param msg Description of the failure */ public static void that(double x, String msg) { if (x == 0.0) { fail(msg); } } /** * Throw an error if equal to <code>null</code>. * * @param x The value to test */ public static void that(Object x) { if (x == null) { fail(); } } /** * Throw an error if equal to <code>null</code>. * * @param x The value to test * @param msg Description of the failure */ public static void that(Object x, String msg) { if (x == null) { fail(msg); } } /** * Abort execution due to some failure. */ public static void fail() { throw new Error(MSG); } /** * Abort execution due to some failure. * * @param msg Description of the failure */ public static void fail(String msg) { throw new Error(msg == null ? MSG : MSG + ": " + msg); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?