Java Object NVL nvl(T value, T defaultValue)

Here you can find the source of nvl(T value, T defaultValue)

Description

Returns the default value if the value is null.

License

Apache License

Parameter

Parameter Description
value the value to test for nullness
defaultValue if value is null, return this
T the value type

Return

the value or defaultValue

Declaration

public static <T> T nvl(T value, T defaultValue) 

Method Source Code

//package com.java2s;
/*//  w  ww  .  j  ava2s  .c om
 * Copyright 2012-2014 David Karnok
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Returns the default value if the value is null.
     * @param value the value to test for nullness
     * @param defaultValue if {@code value} is null, return this
     * @return the value or defaultValue
     * @param <T> the value type
     */
    public static <T> T nvl(T value, T defaultValue) {
        return value != null ? value : defaultValue;
    }
}

Related

  1. nvl(T object, T defaultValue)
  2. nvl(T s, T def)
  3. nvl(T t, String message)
  4. nvl(T t, String message)
  5. nvl(T value, String defValue)
  6. nvl(T value, T ifnull)
  7. nvl(T value, T replacement)
  8. nvl(T value, T replacement)
  9. nvl(T value, T value2)