package org.robobinding.util; import java.util.Arrays; /** * Migrated from {@link com.google.common.base.Objects} * @since 1.0 * @author Cheng Wei * */ public class Objects { /** * Determines whether two possibly-null objects are equal. Returns: * * <ul> * <li>{@code true} if {@code a} and {@code b} are both null. * <li>{@code true} if {@code a} and {@code b} are both non-null and they are equal according to * {@link Object#equals(Object)}. * <li>{@code false} in all other situations. * </ul> * * <p>This assumes that any non-null objects passed to this function conform to the * {@code equals()} contract. * * <p><b>Note for Java 7 and later:</b> This method should be treated as deprecated; use * {@link java.util.Objects#equals} instead. */ public static boolean equal(Object a, Object b) { return a == b || (a != null && a.equals(b)); } /** * Generates a hash code for multiple values. The hash code is generated by calling * {@link Arrays#hashCode(Object[])}. Note that array arguments to this method, with the exception * of a single Object array, do not get any special handling; their hash codes are based on * identity and not contents. * * <p>This is useful for implementing {@link Object#hashCode()}. For example, in an object that * has three properties, {@code x}, {@code y}, and {@code z}, one could write: * * <pre> {@code * public int hashCode() { * return Objects.hashCode(getX(), getY(), getZ()); * }}</pre> * * <p><b>Warning:</b> When a single object is supplied, the returned hash code does not equal the * hash code of that object. * * <p><b>Note for Java 7 and later:</b> This method should be treated as deprecated; use * {@link java.util.Objects#hash} instead. */ public static int hashCode(Object... objects) { return Arrays.hashCode(objects); } }