Java Object NVL isNullOrEmptyOrZero(Object object)

Here you can find the source of isNullOrEmptyOrZero(Object object)

Description

Returns true if the object specified is null or empty (e.g., an empty string, or an empty collection, or in this case a zero-valued number)

License

Open Source License

Parameter

Parameter Description
object the object to check

Return

true if the text specified is null or empty, false otherwise

Declaration

public final static boolean isNullOrEmptyOrZero(Object object) 

Method Source Code

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

import java.util.*;

public class Main {
    /**//from   w  ww . ja  va2 s  .  co  m
     * Returns true if the object specified is null or empty (e.g., an empty
     * string, or an empty collection, or in this case a zero-valued number)
     *
     * @param object the object to check
     * @return true if the text specified is null or empty, false otherwise
     */
    public final static boolean isNullOrEmptyOrZero(Object object) {
        return (isNullOrEmpty(object, true));
    }

    /**
     * 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 value)
  2. isEmpty(Object... obj)
  3. isNotEmpty(Object object)
  4. isNullOrEmpty(final Object obj)
  5. isNullOrEmpty(Object object, boolean zeroEqualsEmpty)
  6. nvl(Boolean b, boolean defaultValue)
  7. nvl(CharSequence source)
  8. nvl(E expr1, E expr2)
  9. nvl(final T t, final T def)