public final class Objects
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <T> int |
compare(T a,
T b,
java.util.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(java.lang.Object a,
java.lang.Object b)
Checks deep equality of two objects.
|
static boolean |
equals(java.lang.Object a,
java.lang.Object b)
Checks equality of two objects.
|
static int |
hash(java.lang.Object... values)
Returns the hash code for objects.
|
static int |
hashCode(java.lang.Object o)
Returns the hash code of object.
|
static boolean |
isNull(java.lang.Object obj)
Checks that object reference is
null. |
static boolean |
nonNull(java.lang.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,
java.lang.String message)
Checks that object reference is not
null. |
static <T> T |
requireNonNull(T obj,
Supplier<java.lang.String> messageSupplier)
Checks that object reference is not
null. |
static <T> java.util.Collection<T> |
requireNonNullElements(java.util.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 java.lang.String |
toString(java.lang.Object o,
java.lang.String nullDefault)
Returns result of calling
toString on object or nullDefault if object is null. |
@Contract(pure=true)
public static boolean equals(@Nullable
java.lang.Object a,
@Nullable
java.lang.Object b)
a - an objectb - an objecttrue if objects are equals, false otherwise@Contract(pure=true)
public static boolean deepEquals(@Nullable
java.lang.Object a,
@Nullable
java.lang.Object b)
a - an objectb - an objecttrue if objects are deeply equals, false otherwiseArrays.deepEquals(Object[], Object[]),
equals(Object, Object)@Contract(pure=true)
public static int hashCode(@Nullable
java.lang.Object o)
o - an object@Contract(pure=true)
public static int hash(@Nullable
java.lang.Object... values)
values - the values@NotNull
@Contract(value="null, _ -> param2")
public static java.lang.String toString(@Nullable
java.lang.Object o,
@NotNull
java.lang.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.@Contract(pure=true)
public static <T> int compare(@Nullable
T a,
@Nullable
T b,
@NotNull
java.util.Comparator<? super T> c)
T - the type of the argumentsa - an objectb - an objectc - the comparator@Contract(pure=true)
public static int compareInt(int x,
int y)
int values.x - the first int valuey - the second int value@Contract(pure=true)
public static int compareLong(long x,
long y)
long values.x - the first long valuey - the second long value@NotNull
@Contract(value="null -> fail; !null -> param1",
pure=true)
public static <T> T requireNonNull(@Nullable
T obj)
null.T - the type of the objectobj - an objectnulljava.lang.NullPointerException - if object is nullrequireNonNull(java.lang.Object, java.lang.String)@NotNull
@Contract(value="null, _ -> fail; !null, _ -> param1",
pure=true)
public static <T> T requireNonNull(@Nullable
T obj,
@NotNull
java.lang.String message)
null.T - the type of the objectobj - an objectmessage - a message to be used as exception detailsnulljava.lang.NullPointerException - if object is nullrequireNonNull(java.lang.Object)@NotNull
@Contract(value="null, _ -> fail; !null, _ -> param1")
public static <T> T requireNonNull(@Nullable
T obj,
@NotNull
Supplier<java.lang.String> messageSupplier)
null.T - the type of the objectobj - an objectmessageSupplier - a supplier of the detail message
for NullPointerException.nulljava.lang.NullPointerException - if object is nullrequireNonNull(java.lang.Object)@NotNull
@Contract(value="!null, _ -> param1; null, !null -> param2; null, null -> fail",
pure=true)
public static <T> T requireNonNullElse(@Nullable
T obj,
@NotNull
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.@NotNull
@Contract(value="!null, _ -> param1; null, null -> fail")
public static <T> T requireNonNullElseGet(@Nullable
T obj,
@NotNull
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 otherwise@NotNull
@Contract(value="null -> fail; !null -> param1")
public static <T> java.util.Collection<T> requireNonNullElements(@NotNull
java.util.Collection<T> collection)
null.T - the type of the objects in the collectioncollection - a collection to be checked for non-null elementsjava.lang.NullPointerException - if collection or its elements are null@Contract(value="null -> true; !null -> false",
pure=true)
public static boolean isNull(@Nullable
java.lang.Object obj)
null.obj - an objecttrue if the object reference is null, false otherwisePredicate@Contract(value="null -> false; !null -> true",
pure=true)
public static boolean nonNull(@Nullable
java.lang.Object obj)
null.obj - an objectfalse if the object reference is null, true otherwisePredicate,
Predicate.Util#notNull()