001package components.utilities;
002
003/**
004 * {@code Reporter} utility class with methods to report various kinds of
005 * notifications.
006 */
007public final class Reporter {
008
009    /*
010     * Private members --------------------------------------------------------
011     */
012
013    /**
014     * No-argument constructor--private to prevent instantiation.
015     */
016    private Reporter() {
017        // no code needed here
018    }
019
020    /*
021     * Public members ---------------------------------------------------------
022     */
023
024    /**
025     * Prints the given error message to the console and terminates the
026     * application.
027     *
028     * @param msg
029     *            the error message
030     * @ensures [msg is printed to the console and the application terminates]
031     */
032    public static void fatalErrorToConsole(String msg) {
033        assert msg != null : "Violation of: msg is not null";
034        throw new RuntimeException(msg);
035    }
036
037    /**
038     * If the given condition is false, prints the given error message to the
039     * console and terminates the application; otherwise it just returns.
040     *
041     * @param b
042     *            the boolean condition
043     * @param msg
044     *            the error message
045     * @ensures <pre>
046     * [if the condition is false, msg is printed to the console and
047     *   the application terminates; otherwise it just returns]
048     * </pre>
049     */
050    public static void assertElseFatalError(boolean b, String msg) {
051        assert msg != null : "Violation of: msg is not null";
052        if (!b) {
053            fatalErrorToConsole(msg);
054        }
055    }
056
057}