public final class Objects extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T> int |
compare(T a,
T b,
Comparator<? super T> c)
Compares two objects with provided comparator.
|
static int |
compareInt(int x,
int y)
Compares two
int values. |
static int |
compareLong(long x,
long y)
Compares two
long values. |
static boolean |
deepEquals(Object a,
Object b)
Checks deep equality of two objects.
|
static boolean |
equals(Object a,
Object b)
Checks equality of two objects.
|
static int |
hash(Object... values)
Returns the hash code for objects.
|
static int |
hashCode(Object o)
Returns the hash code of object.
|
static boolean |
isNull(Object obj)
Checks that object reference is
null. |
static boolean |
nonNull(Object obj)
Checks that object reference is not
null. |
static <T> T |
requireNonNull(T obj)
Checks that object reference is not
null. |
static <T> T |
requireNonNull(T obj,
String message)
Checks that object reference is not
null. |
static <T> T |
requireNonNull(T obj,
Supplier<String> messageSupplier)
Checks that object reference is not
null. |
static <T> Collection<T> |
requireNonNullElements(Collection<T> collection)
Checks that collection and its elements are non-
null. |
static <T> T |
requireNonNullElse(T obj,
T defaultObj)
Returns the first object if it is non-
null,
returns the non-null second object otherwise. |
static <T> T |
requireNonNullElseGet(T obj,
Supplier<? extends T> supplier)
Returns the first object if it is non-
null,
returns the non-null supplier's result otherwise. |
static String |
toString(Object o,
String nullDefault)
Returns result of calling
toString on object or nullDefault if object is null. |
public static boolean equals(Object a, Object b)
a - an objectb - an objecttrue if objects are equals, false otherwisepublic static boolean deepEquals(Object a, Object b)
a - an objectb - an objecttrue if objects are deeply equals, false otherwiseArrays.deepEquals(Object[], Object[]),
equals(Object, Object)public static int hashCode(Object o)
o - an objectpublic static int hash(Object... values)
values - the valuespublic static String toString(Object o, String nullDefault)
toString on object or nullDefault if object is null.o - an objectnullDefault - a string to return if object is nulltoString on object or nullDefault if object is null.public static <T> int compare(T a,
T b,
Comparator<? super T> c)
T - the type of the argumentsa - an objectb - an objectc - the comparatorpublic static int compareInt(int x,
int y)
int values.x - the first int valuey - the second int valuepublic static int compareLong(long x,
long y)
long values.x - the first long valuey - the second long valuepublic static <T> T requireNonNull(T obj)
null.T - the type of the objectobj - an objectnullNullPointerException - if object is nullrequireNonNull(java.lang.Object, java.lang.String)public static <T> T requireNonNull(T obj,
String message)
null.T - the type of the objectobj - an objectmessage - a message to be used as exception detailsnullNullPointerException - if object is nullrequireNonNull(java.lang.Object)public static <T> T requireNonNull(T obj,
Supplier<String> messageSupplier)
null.T - the type of the objectobj - an objectmessageSupplier - a supplier of the detail message
for NullPointerException.nullNullPointerException - if object is nullrequireNonNull(java.lang.Object)public static <T> T requireNonNullElse(T obj,
T defaultObj)
null,
returns the non-null second object otherwise.T - the type of the objectsobj - an objectdefaultObj - a non-null object to return
if the first object is nullnull,
the non-null second object otherwise.public static <T> T requireNonNullElseGet(T obj,
Supplier<? extends T> supplier)
null,
returns the non-null supplier's result otherwise.T - the type of the first object and return typeobj - an objectsupplier - a supplier to return non-null object
if first object is nullnull,
the non-null supplier's result otherwisepublic static <T> Collection<T> requireNonNullElements(Collection<T> collection)
null.T - the type of the objects in the collectioncollection - a collection to be checked for non-null elementsNullPointerException - if collection or its elements are nullpublic static boolean isNull(Object obj)
null.obj - an objecttrue if the object reference is null, false otherwisePredicateCopyright © 2018. All rights reserved.