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

org.enodeframework.common.utilities.Ensure Maven / Gradle / Ivy

There is a newer version: 1.1.10
Show newest version
package org.enodeframework.common.utilities;

import com.google.common.base.Strings;

/**
 * @author [email protected]
 */
public class Ensure {
    public static  void notNull(T argument, String argumentName) {
        if (argument == null) {
            throw new IllegalArgumentException(String.format("%s should not be null.", argumentName));
        }
    }

    public static void notNullOrEmpty(String argument, String argumentName) {
        if (Strings.isNullOrEmpty(argument)) {
            throw new IllegalArgumentException(String.format("%s should not be null or empty.", argumentName));
        }
    }

    public static void equal(int expected, int actual, String argumentName) {
        if (expected != actual) {
            throw new IllegalArgumentException(String.format("%s expected value: %d, actual value: %d", argumentName, expected, actual));
        }
    }

    public static void equal(long expected, long actual, String argumentName) {
        if (expected != actual) {
            throw new IllegalArgumentException(String.format("%s expected value: %d, actual value: %d", argumentName, expected, actual));
        }
    }

    public static void equal(boolean expected, boolean actual, String argumentName) {
        if (expected != actual) {
            throw new IllegalArgumentException(String.format("%s expected value: %d, actual value: %d", argumentName, expected, actual));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy