Java Object NVL isNullOrEmpty(Object object, boolean zeroEqualsEmpty)

Here you can find the source of isNullOrEmpty(Object object, boolean zeroEqualsEmpty)

Description

is Null Or Empty

License

Open Source License

Declaration

private final static boolean isNullOrEmpty(Object object,
            boolean zeroEqualsEmpty) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    /**/* w  w w .  j  ava  2  s.  c o m*/
     * Returns true if the object specified is null or empty (e.g., an empty
     * string, or an empty collection)
     *
     * @param object the object to check
     * @return true if the text specified is null or empty, false otherwise
     */
    public final static boolean isNullOrEmpty(Object object) {
        return (isNullOrEmpty(object, false));
    }

    private final static boolean isNullOrEmpty(Object object,
            boolean zeroEqualsEmpty) {
        if (object == null)
            return true;
        if (object instanceof Collection)
            return ((Collection) object).size() == 0;
        else if (object instanceof Map)
            return ((Map) object).size() == 0;
        else if (object.getClass().isArray())
            return ((Object[]) object).length == 0;
        else if (object instanceof Number && zeroEqualsEmpty)
            return ((Number) object).longValue() == 0;
        else
            return object.toString().length() == 0;
    }
}

Related

  1. isEmpty(Object obj)
  2. isEmpty(Object value)
  3. isEmpty(Object... obj)
  4. isNotEmpty(Object object)
  5. isNullOrEmpty(final Object obj)
  6. isNullOrEmptyOrZero(Object object)
  7. nvl(Boolean b, boolean defaultValue)
  8. nvl(CharSequence source)
  9. nvl(E expr1, E expr2)