package com.kickstarter.libs.utils;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import rx.functions.Func1;

public class ObjectUtils {
  private ObjectUtils(){}

  public static boolean isNull(@Nullable final Object object) {
    return object == null;
  }

  public static boolean isNotNull(@Nullable final Object object) {
    return object != null;
  }

  /**
   * Returns the first non-`null` value of its arguments.
   */
  @NonNull public static <T> T coalesce(@Nullable final T value, @NonNull final T theDefault) {
    if (value != null) {
      return value;
    }
    return theDefault;
  }

  /**
   * Returns a function `T -> T` that coalesces values with `theDefault`.
   */
  @NonNull public static <T> Func1<T, T> coalesceWith(@NonNull final T theDefault) {
    return (value) -> ObjectUtils.coalesce(value, theDefault);
  }

  /**
   * Converts an {@link Integer} to a {@link String}, or null of the integer is also null.
   */
  public static @Nullable String toString(@Nullable final Integer n) {
    if (n != null) {
      return Integer.toString(n);
    }

    return null;
  }

  /**
   * Converts a {@link Long} to a {@link String}, or null of the long is also null.
   */
  public static @Nullable String toString(@Nullable final Long n) {
    if (n != null) {
      return Long.toString(n);
    }

    return null;
  }

  /**
   * Converts a {@link Float} to a {@link String}, or null of the float is also null.
   */
  public static @Nullable String toString(@Nullable final Float n) {
    if (n != null) {
      return Float.toString(n);
    }

    return null;
  }

  /**
   * Converts a {@link Double} to a {@link String}, or null of the double is also null.
   */
  public static @Nullable String toString(@Nullable final Double n) {
    if (n != null) {
      return Double.toString(n);
    }

    return null;
  }
}

@@ -227,24 +227,30 @@
 lean isNull(
+final 
 @Nullable fi
@@ -239,38 +239,32 @@
 final @Nullable 
-final 
 Object object) %7B
@@ -330,16 +330,22 @@
 NotNull(
+final 
 @Nullabl
@@ -346,22 +346,16 @@
 ullable 
-final 
 Object o
@@ -505,16 +505,22 @@
 oalesce(
+final 
 @Nullabl
@@ -525,22 +525,16 @@
 ble 
-final 
 T value,
  @No
@@ -529,16 +529,22 @@
 T value,
+ final
  @NonNul
@@ -537,38 +537,32 @@
  final @NonNull 
-final 
 T theDefault) %7B%0A
@@ -780,16 +780,22 @@
 sceWith(
+final 
 @NonNull
@@ -795,22 +795,16 @@
 NonNull 
-final 
 T theDef
@@ -1016,32 +1016,38 @@
 String toString(
+final 
 @Nullable final 
@@ -1040,22 +1040,16 @@
 ullable 
-final 
 Integer 
@@ -1267,32 +1267,38 @@
 String toString(
+final 
 @Nullable final 
@@ -1291,22 +1291,16 @@
 ullable 
-final 
 Long n) 
@@ -1514,32 +1514,38 @@
 String toString(
+final 
 @Nullable final 
@@ -1538,22 +1538,16 @@
 ullable 
-final 
 Float n)
@@ -1773,16 +1773,22 @@
 oString(
+final 
 @Nullabl
@@ -1789,22 +1789,16 @@
 ullable 
-final 
 Double n

Swap annotation order