This class contains static methods, which are used throughout the project. The methods are used for dumping error output, debugging information, getting the application path, etc. @author BaseX Team, BSD License @author Christian Gruen
| 26 | * @author Christian Gruen |
| 27 | */ |
| 28 | public final class Util { |
| 29 | /** Flag for using default standard input. */ |
| 30 | private static final boolean NOCONSOLE = System.console() == null; |
| 31 | |
| 32 | /** Hidden constructor. */ |
| 33 | private Util() { } |
| 34 | |
| 35 | /** |
| 36 | * Returns an information string for an unexpected exception. |
| 37 | * @param throwable exception |
| 38 | * @return dummy object |
| 39 | */ |
| 40 | public static String bug(final Throwable throwable) { |
| 41 | final TokenBuilder tb = new TokenBuilder().add(S_BUGINFO).add(NL); |
| 42 | tb.add("Contact: ").add(MAILING_LIST).add(NL); |
| 43 | tb.add("Version: ").add(TITLE).add(NL); |
| 44 | tb.add("Java: ").add(Prop.JAVA_VENDOR).add(", ").add(Prop.JAVA_VERSION).add(NL); |
| 45 | tb.add("OS: ").add(Prop.OS).add(", ").add(Prop.OS_ARCH).add(NL); |
| 46 | tb.add("Stack Trace:"); |
| 47 | for(final String string : toArray(throwable)) tb.add(NL).add(string); |
| 48 | return tb.toString(); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Throws a runtime exception for an unexpected exception. |
| 53 | * @return runtime exception (indicates that an error is raised) |
| 54 | */ |
| 55 | public static RuntimeException notExpected() { |
| 56 | return new RuntimeException("Not Expected."); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Throws a runtime exception for an unexpected exception. |
| 61 | * @param message message |
| 62 | * @param ext optional extension |
| 63 | * @return runtime exception (indicates that an error is raised) |
| 64 | */ |
| 65 | public static RuntimeException notExpected(final Object message, final Object... ext) { |
| 66 | return new RuntimeException(info(message, ext)); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Returns the class name of the specified object, excluding its path. |
| 71 | * @param object object |
| 72 | * @return class name |
| 73 | */ |
| 74 | public static String className(final Object object) { |
| 75 | return className(object.getClass()); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Returns the name of the specified class, excluding its path. |
| 80 | * @param clazz class |
| 81 | * @return class name |
| 82 | */ |
| 83 | public static String className(final Class<?> clazz) { |
| 84 | return clazz.getSimpleName(); |
| 85 | } |