com.ewcms.common.lang.EmptyUtil.java Source code

Java tutorial

Introduction

Here is the source code for com.ewcms.common.lang.EmptyUtil.java

Source

/**
 * Copyright (c)2010-2011 Enterprise Website Content Management System(EWCMS), All rights reserved.
 * EWCMS PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * http://www.ewcms.com
 */

package com.ewcms.common.lang;

import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Map;
import org.apache.commons.lang.StringUtils;

/**
 * 
 * 
 * @author WangWei
 */
public class EmptyUtil {

    /**
     * null
     * 
     * @param value 
     * @return true is null
     */
    public static boolean isNull(Object value) {
        return value == null ? true : false;
    }

    /**
     * ?null
     * 
     * @param value
     * @return true is not null
     */
    public static boolean isNotNull(Object value) {
        return !isNull(value);
    }

    /**
     * 
     * 
     * @param value
     * @return 
     */
    public static boolean isArrayEmpty(Object[] value) {
        if (isNull(value)) {
            return true;
        }
        return Array.getLength(value) == 0 ? true : false;
    }

    /**
     * ?
     * 
     * @param value
     * @return 
     */
    public static boolean isArrayNotEmpty(Object[] value) {
        return !isArrayEmpty(value);
    }

    /**
     * ?
     * 
     * @param value
     * @return
     */
    public static boolean isCollectionEmpty(Collection<?> value) {
        if (isNull(value)) {
            return true;
        }
        return value.isEmpty();
    }

    /**
     * ??
     * 
     * @param value
     * @return
     */
    public static boolean isCollectionNotEmpty(Collection<?> value) {
        return !isCollectionEmpty(value);
    }

    /**
     * Map
     * 
     * @param value
     * @return
     */
    public static boolean isMapEmpty(Map<?, ?> value) {
        if (isNull(value)) {
            return true;
        }
        return value.isEmpty();
    }

    /**
     * Map?
     * 
     * @param value
     * @return
     */
    public static boolean isMapNotEmpty(Map<?, ?> value) {
        return !isMapEmpty(value);
    }

    /**
     * 
     *
     * <pre>
     * isEmpty(null)=true
     * isEmpty("") =true
     * isEmpty("  ")=true
     * isEmpty("test")=false
     * isEmpty(" test  ")=false
     *
     * <p>?String</p>
     *
     * <pre>
     * isEmpty(null)=true
     *
     * @param value
     * @return
     */
    public static boolean isStringEmpty(final Object value) {
        if (isNull(value)) {
            return true;
        }
        return StringUtils.isBlank((String) value);
    }

    /**
     *?
     * 
     * @param value
     * @return
     */
    public static boolean isStringNotEmpty(final Object value) {
        return !isStringEmpty(value);
    }
}