Here you can find the source of coalesce(Object... args)
Parameter | Description |
---|---|
args | Variable length list of arguments |
null
if all arguments are null
public static Object coalesce(Object... args)
//package com.java2s; /*/* ww w. ja va 2 s. c om*/ Weave (Web-based Analysis and Visualization Environment) Copyright (C) 2008-2014 University of Massachusetts Lowell This file is a part of Weave. Weave is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License, Version 3, as published by the Free Software Foundation. Weave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Weave. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Coalesce all of the arguments passed to this function * and return the first non-null argument passed. * * @param args Variable length list of arguments * @return The first non-null argument, or <code>null</code> if all arguments are null */ public static Object coalesce(Object... args) { for (int i = 0; i < args.length; i++) if (args[i] != null) return args[i]; return null; } }