public final class MoreObjects extends Object
static utility methods for operating on objects. These utilities
include null-safe or null-tolerant methods for computing the hash code of an
object, returning a string for an object, comparing two objects, etc.
Cut and modified version from Guava (needed to minimize dependency tree for client).
| Modifier and Type | Class and Description |
|---|---|
static class |
MoreObjects.ToStringHelper
Simple decorator to encapsulate actual toString helper implementation.
|
static class |
MoreObjects.ToStringHelperImpl
Support class for
toStringHelper(java.lang.Object). |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
clone(byte[] array)
Creates shallow copy of input array.
|
static <T> T[] |
clone(T[] array)
Creates shallow copy of input array.
|
static boolean |
deepEquals(Object a,
Object b)
Returns
true if the arguments are deeply equal to each other and false
otherwise. |
static boolean |
equals(Object a,
Object b)
Returns
true if the arguments are equal to each other and false otherwise. |
static int |
hash(Object... values)
Generates a hash code for a sequence of input values.
|
static int |
hashCode(Object o)
Returns the hash code of a non-
null argument and 0 for a null argument. |
static MoreObjects.ToStringHelper |
toStringHelper(Class<?> clazz)
Returns helper to generate string representation of given input class.
|
static MoreObjects.ToStringHelper |
toStringHelper(Class<?> clazz,
boolean outputFullDetails)
Returns helper to generate string representation of given input class.
|
static MoreObjects.ToStringHelper |
toStringHelper(Object self)
Returns helper to generate string representation of given input object.
|
static MoreObjects.ToStringHelper |
toStringHelper(Object self,
boolean outputFullDetails)
Returns helper to generate string representation of given input object.
|
static MoreObjects.ToStringHelper |
toStringHelper(String className)
Returns helper to generate string representation of class with given className.
|
static MoreObjects.ToStringHelper |
toStringHelper(String className,
boolean outputFullDetails)
Returns helper to generate string representation of class with given className.
|
public static boolean equals(Object a, Object b)
true if the arguments are equal to each other and false otherwise.
Consequently, if both arguments are null, true is returned and if exactly one
argument is null, false is returned. Otherwise, equality is determined by using
the equals method of the first argument.a - an objectb - an object to be compared with a for equalitytrue if the arguments are equal to each other and false otherwiseObject.equals(Object)public static boolean deepEquals(Object a, Object b)
true if the arguments are deeply equal to each other and false
otherwise.
Two null values are deeply equal. If both arguments are arrays, the algorithm in
Arrays.deepEquals is used to determine equality.
Otherwise, equality is determined by using the equals method of the first
argument.
a - an objectb - an object to be compared with a for deep equalitytrue if the arguments are deeply equal to each other and false
otherwiseArrays.deepEquals(Object[], Object[]),
equals(Object, Object)public static int hashCode(Object o)
null argument and 0 for a null argument.o - an objectnull argument and 0 for a null argumentObject.hashCode()public static int hash(Object... values)
Arrays.hashCode(Object[]).
This method is useful for implementing Object.hashCode() on objects containing
multiple fields. For example, if an object that has three fields, x, y, and
z, one could write:
@Override public int hashCode() {
return Objects.hash(x, y, z);
}
Warning: When a single object reference is supplied, the returned value does not equal the
hash code of that object reference. This value can be computed by calling hashCode(Object).values - the values to be hashedArrays.hashCode(Object[])public static <T> T[] clone(T[] array)
T - type of passed array elementsarray - the array to be copiedpublic static byte[] clone(byte[] array)
array - the array to be copiedpublic static MoreObjects.ToStringHelper toStringHelper(Object self)
self - the object to be represented as stringpublic static MoreObjects.ToStringHelper toStringHelper(Object self, boolean outputFullDetails)
self - the object to be represented as stringoutputFullDetails - the flag to be set to output all elements of container (list, set,
queue, map) or array of objectspublic static MoreObjects.ToStringHelper toStringHelper(Class<?> clazz)
clazz - the class to be represented as stringpublic static MoreObjects.ToStringHelper toStringHelper(Class<?> clazz, boolean outputFullDetails)
clazz - the class to be represented as stringoutputFullDetails - the flag to be set to output all elements of container (list, set,
queue, map) or array of objectspublic static MoreObjects.ToStringHelper toStringHelper(String className)
className - the name of class to be represented as stringpublic static MoreObjects.ToStringHelper toStringHelper(String className, boolean outputFullDetails)
className - the name of class to be represented as stringoutputFullDetails - the flag to be set to output all elements of container (list, set,
queue, map) or array of objectsCopyright © 2022. All rights reserved.