Java Type Coalesce coalesce(T... tests)

Here you can find the source of coalesce(T... tests)

Description

Returns the first non-null value in the passed array

License

Open Source License

Declaration

public static <T extends Object> T coalesce(T... tests) 

Method Source Code

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

public class Main {
    /**/*  w  w w  . j  av  a  2 s  .  co  m*/
     * Returns the first non-null value in the passed array
     */
    public static <T extends Object> T coalesce(T... tests) {
        if (tests != null) {
            for (int i = 0; i < tests.length; i++) {
                if (notNull(tests[i])) {
                    return tests[i];
                }
            }
        }
        return null;
    }

    /**
     * Returns true if object is not null and not empty string
     */
    public static boolean notNull(Object o) {
        return !isNull(o);
    }

    /**
     * Returns true if object is null or empty String
     */
    public static boolean isNull(Object o) {
        return o == null || o.equals("");
    }
}

Related

  1. coalesce(T preferred, T alternative)
  2. coalesce(T value, T whenNullValue)
  3. coalesce(T... args)
  4. coalesce(T... objects)
  5. coalesce(T... objs)
  6. coalesce(T... ts)
  7. coalesce(T... values)
  8. coalesceString(String... objects)