Java Type Coalesce coalesce(T... values)

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

Description

Returns the first non- null value among the given values .

License

Open Source License

Declaration

@Deprecated
public static <T> T coalesce(T... values) 

Method Source Code

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

public class Main {
    /**/*  w ww . j  av a2  s.  c  o  m*/
     * Returns the first non-{@code null} value among the given
     * {@code values}.
     *
     * @deprecated Use {@link #firstNonNull} instead.
     */
    @Deprecated
    public static <T> T coalesce(T... values) {
        return firstNonNull(values);
    }

    /**
     * Returns the first non-{@code null} value among the given
     * {@code values}.
     *
     * @param values If {@code null}, returns {@code null}.
     * @return May be {@code null}.
     */
    public static <T> T firstNonNull(T... values) {
        if (values != null) {
            for (T value : values) {
                if (value != null) {
                    return value;
                }
            }
        }

        return null;
    }
}

Related

  1. coalesce(T... args)
  2. coalesce(T... objects)
  3. coalesce(T... objs)
  4. coalesce(T... tests)
  5. coalesce(T... ts)
  6. coalesceString(String... objects)