Java Type Coalesce coalesce(Object... args)

Here you can find the source of coalesce(Object... args)

Description

Coalesce all of the arguments passed to this function and return the first non-null argument passed.

License

Open Source License

Parameter

Parameter Description
args Variable length list of arguments

Return

The first non-null argument, or null if all arguments are null

Declaration

public static Object coalesce(Object... args) 

Method Source Code

//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;
    }
}

Related

  1. coalesce(final T... argv)
  2. coalesce(final T... objects)
  3. coalesce(final T... ts)
  4. coalesce(float... p)
  5. coalesce(Object src, Object defaultValue)
  6. coalesce(Object... items)
  7. coalesce(String str1, String str2)
  8. coalesce(String... strings)
  9. coalesce(String... strings)