Java Object NVL isEmpty(Object value)

Here you can find the source of isEmpty(Object value)

Description

Check that value wasn't set by json parser.

License

Open Source License

Parameter

Parameter Description
value - value to check

Return

- true if value is useless for factory (0 for primitives or empty collection or map), false otherwise

Declaration

static boolean isEmpty(Object value) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012-2015 Codenvy, S.A.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from ww  w.j  a v a  2 s.c o m
 *   Codenvy, S.A. - initial API and implementation
 *******************************************************************************/

import java.util.*;

public class Main {
    /**
     * Check that value wasn't set by json parser.
     *
     * @param value
     *         - value to check
     * @return - true if value is useless for factory (0 for primitives or empty collection or map), false otherwise
     */
    static boolean isEmpty(Object value) {
        return (null == value) || (value.getClass().equals(Boolean.class) && !((Boolean) value))
                || (value.getClass().equals(Integer.class) && (Integer) value == 0)
                || (value.getClass().equals(Long.class) && (Long) value == 0)
                || (Collection.class.isAssignableFrom(value.getClass()) && ((Collection) value).isEmpty())
                || (Map.class.isAssignableFrom(value.getClass()) && ((Map) value).isEmpty())
                || (value.getClass().equals(Byte.class) && (Byte) value == 0)
                || (value.getClass().equals(Short.class) && (Short) value == 0)
                || (value.getClass().equals(Double.class) && (Double) value == 0)
                || (value.getClass().equals(Float.class) && (Float) value == 0);
    }
}

Related

  1. isEmpty(Object obj)
  2. isEmpty(Object... obj)
  3. isNotEmpty(Object object)
  4. isNullOrEmpty(final Object obj)
  5. isNullOrEmpty(Object object, boolean zeroEqualsEmpty)