Java Object NVL nvl(Object value, Object substituteWhenNull)

Here you can find the source of nvl(Object value, Object substituteWhenNull)

Description

nvl method lets you substitute a value when a null value is encountered.

License

LGPL

Parameter

Parameter Description
value the value to test
substituteWhenNull substitute value when value is null

Return

substitute when value is null

Declaration

public static Object nvl(Object value, Object substituteWhenNull) 

Method Source Code

//package com.java2s;
/*/*  w  ww .  j  a  v a 2 s . c o m*/
 *   This software is distributed under the terms of the FSF 
 *   Gnu Lesser General Public License (see lgpl.txt). 
 *
 *   This program is distributed WITHOUT ANY WARRANTY. See the
 *   GNU General Public License for more details.
 */

public class Main {
    /**
     * <tt>nvl</tt> method lets you substitute a value when a null value is 
     * encountered.
     * 
     * @param value                 the value to test
     * @param substituteWhenNull    substitute value when value is null
     * @return substitute when value is null
     */
    public static Object nvl(Object value, Object substituteWhenNull) {
        return (value != null) ? value : substituteWhenNull;
    }

    /**
     * <tt>nvl</tt> method lets you substitute a value when a null value is 
     * encountered.
     * 
     * @param value                 the value to test
     * @param substituteWhenNull    substitute value when value is null
     * @return substitute when value is null
     */
    public static String nvl(String value, String substituteWhenNull) {
        return (value != null) ? value : substituteWhenNull;
    }

    /**
     * <tt>nvl</tt> method lets you substitute a value when a null value is 
     * encountered as well as when a non-null value is encountered.
     * 
     * @param value                 the value to test
     * @param substituteWhenNotNull substitute value when value is not null
     * @param substituteWhenNull    substitute value when value is null
     * @return substitute when value is null
     */
    public static Object nvl(Object value, Object substituteWhenNotNull,
            Object substituteWhenNull) {
        return (value != null) ? substituteWhenNotNull : substituteWhenNull;
    }

    /**
     * <tt>nvl</tt> method lets you substitute a value when a null value is 
     * encountered as well as when a non-null value is encountered.
     * 
     * @param value                 the value to test
     * @param substituteWhenNotNull substitute value when value is not null
     * @param substituteWhenNull    substitute value when value is null
     * @return substitute when value is null
     */
    public static String nvl(String value, String substituteWhenNotNull,
            String substituteWhenNull) {
        return (value != null) ? substituteWhenNotNull : substituteWhenNull;
    }
}

Related

  1. nvl(Object inputObject, Object defaultObject)
  2. NVL(Object obj, String defaultVaue)
  3. nvl(Object objInput, Object objOutput)
  4. nvl(Object source, Object alernative)
  5. NVL(Object str)
  6. nvl(Object value, String defaultValue)
  7. nvl(Object value, String valueWhenNull)
  8. nvl(S obj, U nullObject)
  9. nvl(String instr, String defaultValue)