|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.common.base.Objects
public final class Objects
Helper functions for operating on Object
s.
Method Summary | ||
---|---|---|
static boolean |
deepEquals(Object o1,
Object o2)
Determines if two objects are equal as determined by Object.equals(Object) , or "deeply equal" if both are arrays. |
|
static int |
deepHashCode(Object o)
Gets hash code of an object, optionally returns hash code based on the "deep contents" of array if the object is an array. |
|
static String |
deepToString(Object o)
Gets string representation of an object, or the "deep content" of the array if the o is an array. |
|
static boolean |
equal(Object a,
Object b)
Determines whether two possibly-null objects are equal. |
|
static
|
firstNonNull(T first,
T second)
Returns the first of the given parameters that is not null if any,
or otherwise throws NullPointerException . |
|
static int |
hashCode(Object... objects)
Generates a hashcode for multiple values. |
|
static
|
nonNull(T o)
Checks that the specified object is not null . |
|
static
|
nonNull(T o,
String message)
Checks that the specified object is not null . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static int deepHashCode(@Nullable Object o)
If o
is null, 0 is returned; if o
is an array, the
corresponding Arrays.deepHashCode(Object[])
, or
Arrays.hashCode(int[])
or the like is used to calculate the hash
code.
public static String deepToString(@Nullable Object o)
o
is an array.
If o
is null, "null"
is returned; if o
is an
array, the corresponding Arrays.deepToString(Object[])
,
Arrays.toString(int[])
or the like is used to get the string.
public static boolean deepEquals(@Nullable Object o1, @Nullable Object o2)
Object.equals(Object)
, or "deeply equal" if both are arrays.
If both objects are null, true is returned; if both objects are array, the
corresponding Arrays.deepEquals(Object[], Object[])
, or
Arrays.equals(int[], int[])
or the like are called to determine
equality.
Note that this method does not "deeply" compare the fields of the objects.
public static boolean equal(@Nullable Object a, @Nullable Object b)
true
if a
and b
are both null.
true
if a
and b
are both non-null and they are
equal according to Object.equals(Object)
.
false
in all other situations.
This assumes that any non-null objects passed to this function conform
to the equals()
contract.
public static int hashCode(Object... objects)
Arrays.hashCode(Object[])
.
This is useful for implementing Object.hashCode()
. For example,
in an object that has three properties, x
, y
, and
z
, one could write:
public int hashCode() { return Objects.hashCode(getX(), getY(), getZ()); }Warning: When a single object is supplied, the returned hash code does not equal the hash code of that object.
public static <T> T nonNull(T o)
null
.
o
- the object to check for nullness.
o
if not null.
NullPointerException
- if o
is null.public static <T> T nonNull(T o, String message)
null
.
o
- the object to check for nullness.message
- exception message used in the event that a NullPointerException
is thrown.
o
if not null.
NullPointerException
- if o
is null.public static <T> T firstNonNull(@Nullable T first, @Nullable T second)
null
if any,
or otherwise throws NullPointerException
.
first
if first
is not null
, or
second
if first
is null
and second
is
not null
.
NullPointerException
- if both first
and second
were
null
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |