Java Object NVL nvl(Integer value, Number valueWhenNull)

Here you can find the source of nvl(Integer value, Number valueWhenNull)

Description

Imitates the nvl function of Oracle SQL.

License

Open Source License

Parameter

Parameter Description
value a parameter
valueWhenNull a parameter

Return

value if value is not null, otherwise valueWhenNull

Declaration

public static int nvl(Integer value, Number valueWhenNull) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2010-2015 BSI Business Systems Integration AG.
 * 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:/*w ww  . j a  va  2s.c om*/
 *     BSI Business Systems Integration AG - initial API and implementation
 ******************************************************************************/

public class Main {
    /**
     * Imitates the <code>nvl</code> function of Oracle SQL.
     *
     * @param value
     * @param valueWhenNull
     * @return value if value is not <code>null</code>, otherwise valueWhenNull.
     */
    public static <T> T nvl(T value, T valueWhenNull) {
        if (value != null) {
            return value;
        } else {
            return valueWhenNull;
        }
    }

    /**
     * Imitates the <code>nvl</code> function of Oracle SQL.
     *
     * @param value
     * @param valueWhenNull
     * @return value if value is not <code>null</code>, otherwise valueWhenNull
     */
    public static int nvl(Integer value, Number valueWhenNull) {
        if (value != null) {
            return value;
        } else {
            return valueWhenNull.intValue();
        }
    }

    /**
     * Imitates the <code>nvl</code> function of Oracle SQL.
     *
     * @param value
     * @param valueWhenNull
     * @return value if value is not <code>null</code>, otherwise valueWhenNull
     */
    public static long nvl(Long value, Number valueWhenNull) {
        if (value != null) {
            return value;
        } else {
            return valueWhenNull.longValue();
        }
    }
}

Related

  1. isNullOrEmptyOrZero(Object object)
  2. nvl(Boolean b, boolean defaultValue)
  3. nvl(CharSequence source)
  4. nvl(E expr1, E expr2)
  5. nvl(final T t, final T def)
  6. NVL(Long l)
  7. nvl(Object a, Object b, Object c)
  8. nvl(Object arg0, Object arg1)
  9. nvl(Object inputObject, Object defaultObject)