📄 trace.java
字号:
* Note: this method must be used when throwing exception other * than <code>HsqlException</code>. * * @param errorCode the error code associated to the error message * @param substitute substitute the $$ tokens using data in the values * @param values value(s) to use to replace the token(s) * @return the error message associated with the error code * @see #sDescription */ public static String getMessage(final int errorCode, final boolean substitute, final Object[] values) { if (errorCode < 0) { return ""; } else { String key = String.valueOf(errorCode); if (errorCode < 10) { key = "00" + key; } else if (errorCode < 100) { key = "0" + key; } String mainErrorMessage = BundleHandler.getString(bundleHandle, key); if (!substitute) {// return sDescription[errorCode]; return mainErrorMessage; } else {// final String mainErrorMessage = sDescription[errorCode]; final StringBuffer sb = new StringBuffer(mainErrorMessage.length() + 32); int lastIndex = 0; int escIndex = mainErrorMessage.length(); if (values != null) { // removed test: i < add.length // because if mainErrorMessage is equal to "blabla $$" // then the statement escIndex = mainErrorMessage.length(); // is never reached! ??? for (int i = 0; i < values.length; i++) { escIndex = mainErrorMessage.indexOf(MESSAGE_TAG, lastIndex); if (escIndex == -1) { break; } sb.append(mainErrorMessage.substring(lastIndex, escIndex)); sb.append(values[i].toString()); lastIndex = escIndex + MESSAGE_TAG.length(); } } escIndex = mainErrorMessage.length(); sb.append(mainErrorMessage.substring(lastIndex, escIndex)); return sb.toString(); } } } /** * Method declaration * * * @param code * * @return */ public static HsqlException error(int code) { return error(code, null); } /** * Throws exception if condition is false * * @param condition * @param code * * @throws HsqlException */ public static void check(boolean condition, int code) throws HsqlException { check(condition, code, null, null, null, null); } /** * Throws exception if condition is false * * @param condition * @param code * @param add * * @throws HsqlException */ public static void check(boolean condition, int code, Object add) throws HsqlException { if (!condition) { throw error(code, add); } } /** * Method declaration * * * @param code * @param add * * @throws HsqlException */ static void throwerror(int code, Object add) throws HsqlException { throw error(code, add); } /** * Used to print messages to System.out * * * @param message message to print */ public static void printSystemOut(String message) { if (TRACESYSTEMOUT) { System.out.println(message); } } /** * Used to print messages to System.out * * * @param message1 message to print * @param message2 message to print */ public static void printSystemOut(String message1, long message2) { if (TRACESYSTEMOUT) { System.out.print(message1); System.out.println(message2); } } /** * Returns the stack trace for doAssert() */ private static String getStackTrace() { try { Exception e = new Exception(); throw e; } catch (Exception e) { HsqlByteArrayOutputStream os = new HsqlByteArrayOutputStream(); PrintWriter pw = new PrintWriter(os, true); e.printStackTrace(pw); return os.toString(); } } /** * Throws exception if condition is false * * @param condition * @param code * @param add1 * @param add2 * * @throws HsqlException */ static void check(boolean condition, int code, String add1, String add2) throws HsqlException { check(condition, code, add1, add2, null, null); } /** * Throws exception if condition is false * * @param condition * @param code * @param add1 * @param add2 * @param add3 * * @throws HsqlException */ static void check(boolean condition, int code, String add1, String add2, String add3) throws HsqlException { check(condition, code, add1, add2, add3, null); } /** * Throws exception if condition is false * * @param condition * @param code * @param add1 * @param add2 * @param add3 * @param add4 * * @throws HsqlException */ static void check(boolean condition, int code, String add1, String add2, String add3, String add4) throws HsqlException { if (!condition) { String add = ""; if (add1 != null) { add += add1; } if (add2 != null) { add += add2; } if (add3 != null) { add += add3; } if (add4 != null) { add += add4; } throw error(code, add.length() > 0 ? add : null); } } /** * Throws exception if assertion fails * * @param condition * @throws HsqlException */ static void doAssert(boolean condition) throws HsqlException { doAssert(condition, null); } /** * Throws exception if assertion fails * * @param condition * @param error * @throws HsqlException */ static void doAssert(boolean condition, String error) throws HsqlException { if (!condition) { if (error == null) { error = ""; } error += getStackTrace(); throw error(ASSERT_FAILED, error); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -