Assert Object is Empty - Java java.lang

Java examples for java.lang:Assert

Description

Assert Object is Empty

Demo Code


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

import java.util.Map;

public class Main {
    public static void main(String[] argv) throws Exception {
        String string = "java2s.com";
        System.out.println(isEmpty(string));
    }//  w  w  w.j a  va 2  s  . co m

    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