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

com.dexcoder.commons.utils.AssertUtils Maven / Gradle / Ivy

There is a newer version: 2.3.5
Show newest version
package com.dexcoder.commons.utils;

import java.util.Collection;

import org.apache.commons.collections.CollectionUtils;

import com.dexcoder.commons.enums.IEnum;
import com.dexcoder.commons.exceptions.CommonsAssistantException;

/**
 * Created by liyd on 2015-8-24.
 */
public class AssertUtils {

    public static void assertNull(Object obj, String message) {
        if (obj == null) {
            throw new CommonsAssistantException(message);
        }
    }

    public static void assertNull(Object obj, IEnum iEnum) {
        if (obj == null) {
            throw new CommonsAssistantException(iEnum);
        }
    }

    public static void assertEquals(String str1, String str2, String message) {
        if (!StrUtils.equals(str1, str2)) {
            throw new CommonsAssistantException(message);
        }
    }

    public static void assertBlank(String str, String message) {
        if (StrUtils.isBlank(str)) {
            throw new CommonsAssistantException(message);
        }
    }

    public static void assertEmpty(Collection collection, String message) {
        if (CollectionUtils.isEmpty(collection)) {
            throw new CommonsAssistantException(message);
        }
    }

    public static void assertNotEmpty(Collection collection, String message) {
        if (!CollectionUtils.isEmpty(collection)) {
            throw new CommonsAssistantException(message);
        }
    }

    public static void assertMinLength(String str, int length, String message) {
        if (StrUtils.length(str) < length) {
            throw new CommonsAssistantException(message);
        }
    }

    public static void assertRegex(String str, String regex, String message) {
        AssertUtils.assertBlank(str, message);
        boolean matches = str.matches(regex);
        if (!matches) {
            throw new CommonsAssistantException(message);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy