package com.utils;
import java.util.Collection;
import java.util.Map;
/**
* ClassName: RuntimeExceptionUtil
* Description:
* date:
*
* @author
*/
public class RuntimeExceptionUtil {
public RuntimeExceptionUtil() {
}
public static void check(boolean condition, String msg) {
if (!condition) {
fail(msg);
}
}
public static void stringNotEmpty(String value, String msg) {
if (isEmpty(value)) {
fail(msg);
}
}
public static void collectionNotEmpty(Collection<?> collection, String msg) {
if (isEmpty(collection)) {
fail(msg);
}
}
public static void notNull(Object obj, String msg) {
if (obj == null) {
fail(msg);
}
}
private static void fail(String msg) {
throw new RuntimeException(msg);
}
public static Boolean isEmpty(Object obj) {
if (obj == null) {
return Boolean.TRUE;
} else {
if (obj instanceof Map) {
Map map = (Map)obj;
if (map.isEmpty()) {
return Boolean.TRUE;
}
} else if (obj instanceof Collection) {
Collection collection = (Collection)obj;
if (collection.isEmpty()) {
return Boolean.TRUE;
}
}
return Boolean.FALSE;
}
}
}