Java Object NVL nvl(String pArg1, String pArg2)

Here you can find the source of nvl(String pArg1, String pArg2)

Description

Returns arg2 if arg1 is null or empty, or arg1 otherwise.

License

Open Source License

Parameter

Parameter Description
pArg1 a parameter
pArg2 a parameter

Declaration

public static String nvl(String pArg1, String pArg2) 

Method Source Code

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

public class Main {
    /**/*  w ww .  j  a  v a 2 s. co  m*/
     * Returns arg2 if arg1 is null or empty, or arg1 otherwise.
     * @param pArg1
     * @param pArg2
     * @return
     */
    public static String nvl(String pArg1, String pArg2) {
        return !isNull(pArg1) ? pArg1 : pArg2;
    }

    /**
     * Returns arg2 if arg1 is null, or arg1 otherwise.
     * @param <T>
     * @param pArg1
     * @param pArg2
     * @return
     */
    public static <T> T nvl(T pArg1, T pArg2) {
        return pArg1 != null ? pArg1 : pArg2;
    }

    /**
     * Tests if a string is null or empty.
     * @param pArg1
     * @return True if null or empty.
     */
    public static boolean isNull(String pArg1) {
        return "".equals(pArg1 == null ? "" : pArg1);
    }
}

Related

  1. nvl(Object value, String defaultValue)
  2. nvl(Object value, String valueWhenNull)
  3. nvl(S obj, U nullObject)
  4. nvl(String instr, String defaultValue)
  5. nvl(String instr, String defaultValue)
  6. nvl(String pValue)
  7. nvl(String s)
  8. nvl(String s, String def)
  9. NVL(String s, String valorPorDefecto)