Assert Object is Not Empty - Java java.lang

Java examples for java.lang:Assert

Description

Assert Object is Not Empty

Demo Code


//package com.java2s;
import java.util.Collection;

import java.util.Map;

public class Main {
    public static <E> boolean isNotEmpty(E... array) {
        return !isEmpty(array);
    }/*from w w  w. j  ava 2s.  c om*/

    public static boolean isNotEmpty(String string) {
        return !isEmpty(string);
    }

    public static <E> boolean isNotEmpty(Collection<E> list) {
        return !isEmpty(list);
    }

    public static <K, V> boolean isNotEmpty(Map<K, V> map) {
        return !isEmpty(map);
    }

    public static boolean isEmpty(String string) {
        return (isNull(string) || string.trim().length() == 0);
    }

    public static <E> boolean isEmpty(Collection<E> list) {
        return (isNull(list) || list.size() == 0);
    }

    public static <E> boolean isEmpty(E... array) {
        return (isNull(array) || array.length == 0);
    }

    public static <K, V> boolean isEmpty(Map<K, V> map) {
        return (isNull(map) || map.size() == 0);
    }

    public static boolean isNull(Object object) {
        return object == null;
    }

    public static <E> E isNull(E object, E defaultValue) {
        return isNull(object) ? defaultValue : object;
    }
}

Related Tutorials