1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
Description: Preserves the Objects.firstNonNull() method that was removed in Guava 21.
Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: not-needed
--- a/guava/src/com/google/common/base/Objects.java
+++ b/guava/src/com/google/common/base/Objects.java
@@ -78,4 +78,25 @@
public static int hashCode(@CheckForNull @Nullable Object... objects) {
return Arrays.hashCode(objects);
}
+
+ /**
+ * Returns the first of two given parameters that is not {@code null}, if either is, or otherwise
+ * throws a {@link NullPointerException}.
+ *
+ * <p><b>Note:</b> if {@code first} is represented as an {@link Optional}, this can be
+ * accomplished with {@linkplain Optional#or(Object) first.or(second)}. That approach also allows
+ * for lazy evaluation of the fallback instance, using {@linkplain Optional#or(Supplier)
+ * first.or(Supplier)}.
+ *
+ * @return {@code first} if {@code first} is not {@code null}, or {@code second} if {@code first}
+ * is {@code null} and {@code second} is not {@code null}
+ * @throws NullPointerException if both {@code first} and {@code second} were {@code null}
+ * @since 3.0
+ * @deprecated Use {@link MoreObjects#firstNonNull} instead. This method is scheduled for removal
+ * in Guava 21.0.
+ */
+ @Deprecated
+ public static <T> T firstNonNull(@Nullable T first, @Nullable T second) {
+ return MoreObjects.firstNonNull(first, second);
+ }
}
|