Package ca.pgon.st.light6

Source Code of ca.pgon.st.light6.Assert

/*
    Small Tools - Some basic libraries for developing and testing http://www.pgon.ca/st
    Copyright (C) 2013-2014 Small Tools (info@pgon.ca)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/
package ca.pgon.st.light6;

import ca.pgon.st.light6.exception.StLightException;

/**
* To check some assumptions during execution.
*
* @author Simon Levesque
*
*/
public final class Assert {

    /**
     * Check that the value is false.
     *
     * @param actual
     *            the value
     */
    public static void assertFalse(boolean actual) {
        assertFalse(actual, "Value must be false");
    }

    /**
     * Check that the value is false.
     *
     * @param actual
     *            the value
     * @param message
     *            the error message to throw
     */
    public static void assertFalse(boolean actual, String message) {
        if (actual) {
            throw new StLightException(message);
        }
    }

    /**
     * Check that the value is not null.
     *
     * @param actual
     *            the value
     */
    public static void assertNotNull(Object actual) {
        assertNotNull(actual, "Value must not be null");
    }

    /**
     * Check that the value is not null.
     *
     * @param actual
     *            the value
     * @param message
     *            the error message to throw
     */
    public static void assertNotNull(Object actual, String message) {
        if (actual == null) {
            throw new StLightException(message);
        }
    }

    /**
     * Check that the value is null.
     *
     * @param actual
     *            the value
     */
    public static void assertNull(Object actual) {
        assertNull(actual, "Value must be null");
    }

    /**
     * Check that the value is null.
     *
     * @param actual
     *            the value
     * @param message
     *            the error message to throw
     */
    public static void assertNull(Object actual, String message) {
        if (actual != null) {
            throw new StLightException(message);
        }
    }

    /**
     * Check that the value is true.
     *
     * @param actual
     *            the value
     */
    public static void assertTrue(boolean actual) {
        assertTrue(actual, "Value must be true");
    }

    /**
     * Check that the value is true.
     *
     * @param actual
     *            the value
     * @param message
     *            the error message to throw
     */
    public static void assertTrue(boolean actual, String message) {
        if (!actual) {
            throw new StLightException(message);
        }
    }

    private Assert() {
    }

}
TOP

Related Classes of ca.pgon.st.light6.Assert

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.