FileDocCategorySizeDatePackage
Objects.javaAPI DocAndroid 5.1 API4304Thu Mar 12 22:22:44 GMT 2015com.android.tools.layoutlib.java

Objects

public final class Objects extends Object
Defines the same class as the java.util.Objects which is added in Java 7. This hack makes it possible to run the Android code which uses Java 7 features (API 18 and beyond) to run on Java 6.

Extracted from API level 19, file: platform/libcore/luni/src/main/java/java/util/Objects.java

Fields Summary
Constructors Summary
private Objects()

Methods Summary
public static intcompare(T a, T b, java.util.Comparator c)
Returns 0 if {@code a == b}, or {@code c.compare(a, b)} otherwise. That is, this makes {@code c} null-safe.

    if (a == b) {
      return 0;
    }
    return c.compare(a, b);
  
public static booleandeepEquals(java.lang.Object a, java.lang.Object b)
Returns true if both arguments are null, the result of {@link Arrays#equals} if both arguments are primitive arrays, the result of {@link Arrays#deepEquals} if both arguments are arrays of reference types, and the result of {@link #equals} otherwise.

    if (a == null || b == null) {
      return a == b;
    } else if (a instanceof Object[] && b instanceof Object[]) {
      return Arrays.deepEquals((Object[]) a, (Object[]) b);
    } else if (a instanceof boolean[] && b instanceof boolean[]) {
      return Arrays.equals((boolean[]) a, (boolean[]) b);
    } else if (a instanceof byte[] && b instanceof byte[]) {
      return Arrays.equals((byte[]) a, (byte[]) b);
    } else if (a instanceof char[] && b instanceof char[]) {
      return Arrays.equals((char[]) a, (char[]) b);
    } else if (a instanceof double[] && b instanceof double[]) {
      return Arrays.equals((double[]) a, (double[]) b);
    } else if (a instanceof float[] && b instanceof float[]) {
      return Arrays.equals((float[]) a, (float[]) b);
    } else if (a instanceof int[] && b instanceof int[]) {
      return Arrays.equals((int[]) a, (int[]) b);
    } else if (a instanceof long[] && b instanceof long[]) {
      return Arrays.equals((long[]) a, (long[]) b);
    } else if (a instanceof short[] && b instanceof short[]) {
      return Arrays.equals((short[]) a, (short[]) b);
    }
    return a.equals(b);
  
public static booleanequals(java.lang.Object a, java.lang.Object b)
Null-safe equivalent of {@code a.equals(b)}.

    return (a == null) ? (b == null) : a.equals(b);
  
public static inthash(java.lang.Object values)
Convenience wrapper for {@link Arrays#hashCode}, adding varargs. This can be used to compute a hash code for an object's fields as follows: {@code Objects.hash(a, b, c)}.

    return Arrays.hashCode(values);
  
public static inthashCode(java.lang.Object o)
Returns 0 for null or {@code o.hashCode()}.

    return (o == null) ? 0 : o.hashCode();
  
public static TrequireNonNull(T o)
Returns {@code o} if non-null, or throws {@code NullPointerException}.

    if (o == null) {
      throw new NullPointerException();
    }
    return o;
  
public static TrequireNonNull(T o, java.lang.String message)
Returns {@code o} if non-null, or throws {@code NullPointerException} with the given detail message.

    if (o == null) {
      throw new NullPointerException(message);
    }
    return o;
  
public static java.lang.StringtoString(java.lang.Object o, java.lang.String nullString)
Returns {@code nullString} for null or {@code o.toString()}.

    return (o == null) ? nullString : o.toString();
  
public static java.lang.StringtoString(java.lang.Object o)
Returns "null" for null or {@code o.toString()}.

    return (o == null) ? "null" : o.toString();