public class ObjectUtil extends Object
Constructor and Description |
---|
ObjectUtil() |
Modifier and Type | Method and Description |
---|---|
static int |
compare(Comparable v1,
Comparable v2)
Null-safe comparison of two arbitrary comparables.
|
static int |
compare(Comparable v1,
Comparable v2,
boolean nullIsLow)
Null-safe comparison of two arbitrary comparables.
|
static <T> T |
defaultValue(T value,
ObjectFactory<T> fact)
Returns the passed
value , unless it's null, in which case
the objectFactory is queried for a value. |
static <T> T |
defaultValue(T value,
T defaultValue)
Returns the passed
value , unless it's null, in which case
the defaultValue is returned. |
static boolean |
equals(Integer v1,
int v2)
Tests for equality between an
Integer and an int . |
static boolean |
equals(int v1,
int v2)
Tests for equality between two
int values. |
static boolean |
equals(int v1,
Integer v2)
Tests for equality between an
int and an Integer . |
static boolean |
equals(long v1,
long v2)
Tests for equality between two
long values. |
static boolean |
equals(long v1,
Long v2)
Tests for equality between a
long and a Long . |
static boolean |
equals(Long v1,
long v2)
Tests for equality between a
Long and a long . |
static boolean |
equals(Object o1,
Object o2)
Tests two objects for equality.
|
static int |
hashCode(Object obj)
Returns the hashcode of the passed object, 0 if passed
null
. |
static String |
identityToString(Object obj)
Returns a string value of an object similar to that returned by
Object.toString() . |
public static boolean equals(Object o1, Object o2)
null
, and also
handles arrays (something that Jakarta ObjectUtils.equals()
does
not do).public static boolean equals(int v1, Integer v2)
int
and an Integer
.
This method and its sibling exists to avoid the accidental derefencing of a null for primitive comparison, or the needless creation of an auto-boxed wrapper for object comparison.
public static boolean equals(Integer v1, int v2)
Integer
and an int
.
This method and its sibling exists to avoid the accidental derefencing of a null for primitive comparison, or the needless creation of an auto-boxed wrapper for object comparison.
public static boolean equals(int v1, int v2)
int
values.
This method exists as a complement to the object/primitive tests, so that the same method name can be used regardless of the arguments.
public static boolean equals(long v1, Long v2)
long
and a Long
.
This method and its sibling exists to avoid the accidental derefencing of a null for primitive comparison, or the needless creation of an auto-boxed wrapper for object comparison.
public static boolean equals(Long v1, long v2)
Long
and a long
.
This method and its sibling exists to avoid the accidental derefencing of a null for primitive comparison, or the needless creation of an auto-boxed wrapper for object comparison.
public static boolean equals(long v1, long v2)
long
values.
This method exists as a complement to the object/primitive tests, so that the same method name can be used regardless of the arguments.
public static int hashCode(Object obj)
null
. This is a direct replacement for Jakarta's ObjectUtils.
hashCode()
method, existing simply to eliminate a dependency.public static int compare(Comparable v1, Comparable v2)
v1.compareTo(v2)
.ClassCastException
- if objects are not directly comparable.public static int compare(Comparable v1, Comparable v2, boolean nullIsLow)
nullIsLow
, two nulls
are equal, else v1.compareTo(v2)
.ClassCastException
- if objects are not directly comparable.public static String identityToString(Object obj)
Object.toString()
. The primary difference is that the numeric
part of the string is its identity hashcode, and it's in decimal (so as
not to be confused with the default toString()
).
This method is null-safe: if passed null
, it returns
"null".
public static <T> T defaultValue(T value, T defaultValue)
value
, unless it's null, in which case
the defaultValue
is returned.public static <T> T defaultValue(T value, ObjectFactory<T> fact)
value
, unless it's null, in which case
the objectFactory
is queried for a value.