All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cz.jalasoft.util.ArgumentAssertion Maven / Gradle / Ivy

The newest version!
package cz.jalasoft.util;

/**
 * A utility class that allows checking of method parameters
 * and throwing {@link java.lang.IllegalArgumentException} in case
 * that an argument is not valid.
 *
 * Created by Honza Lastovicka on 19.4.15.
 */
public final class ArgumentAssertion {

    public static void mustNotBeNull(Object obj, String name) {
        if (obj == null) {
            throw new IllegalArgumentException(name + " must notbe null.");
        }
    }

    public static void mustNotBeNegative(int number, String name) {
        if (number < 0) {
            throw new IllegalArgumentException(name + " must not be negative.");
        }
    }

    public static void mustNotBeNullOrEmpty(String value, String name) {
        if (value == null || value.isEmpty()) {
            throw new IllegalArgumentException(name + " must not be null or empty.");
        }
    }

    public static void mustBeBetweenIncluding(int value, int lowerBoundary, int higherBoudary, String name) {
        if (value < lowerBoundary || value > higherBoudary) {
            throw new IllegalArgumentException(name + " must be >= than " + lowerBoundary + " and =< than " + higherBoudary);
        }
    }

    public static void mustBeTrue(boolean value, String name) {
        if (!value) {
            throw new IllegalArgumentException(name + " must be true");
        }
    }

    private ArgumentAssertion() {
        throw new RuntimeException();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy