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

io.github.thunderz99.cosmos.util.Checker Maven / Gradle / Ivy

There is a newer version: 0.7.11
Show newest version
package io.github.thunderz99.cosmos.util;

import org.apache.commons.lang3.StringUtils;

import java.util.Collection;

public class Checker {

	Checker(){
	}

	public static void check(boolean result, String message) {

		if (!result) {
			throw new IllegalArgumentException(message);
		}

	}

	public static void checkNotNull(Object target, String name) {

		if (target == null) {
			throw new IllegalArgumentException(String.format("%s should not be null", name));
		}

	}

	public static void checkNotBlank(String target, String name) {

		if (StringUtils.isBlank(target)) {
			throw new IllegalArgumentException(String.format("%s should be non-blank", name));
		}

	}

	public static void checkNotEmpty(String target, String name) {

		if (StringUtils.isEmpty(target)) {
			throw new IllegalArgumentException(String.format("%s should be non-empty", name));
		}

	}

    public static void checkNotEmpty(Collection target, String name) {

        if (target == null || target.isEmpty()) {
            throw new IllegalArgumentException(String.format("%s should not be empty collection", name));
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy