public final class ObjectHelper extends Object
Named as such to avoid clash with java.util.Objects.
Modifier and Type | Method and Description |
---|---|
static int |
compare(int v1,
int v2)
Compares two integer values similar to Integer.compare.
|
static int |
compare(long v1,
long v2)
Compares two long values similar to Long.compare.
|
static boolean |
equals(Object o1,
Object o2)
Compares two potentially null objects with each other using Object.equals.
|
static <T> BiPredicate<T,T> |
equalsPredicate()
Returns a BiPredicate that compares its parameters via Objects.equals().
|
static int |
hashCode(Object o)
Returns the hashCode of a non-null object or zero for a null object.
|
static long |
requireNonNull(long value,
String message)
Deprecated.
this method should not be used as there is no need
to check primitives for nullness.
|
static <T> T |
requireNonNull(T object,
String message)
Verifies if the object is not null and returns it or throws a NullPointerException
with the given message.
|
static int |
verifyPositive(int value,
String paramName)
Validate that the given value is positive or report an IllegalArgumentException with
the parameter name.
|
static long |
verifyPositive(long value,
String paramName)
Validate that the given value is positive or report an IllegalArgumentException with
the parameter name.
|
public static <T> T requireNonNull(T object, String message)
T
- the value typeobject
- the object to verifymessage
- the message to use with the NullPointerExceptionNullPointerException
- if object is nullpublic static boolean equals(Object o1, Object o2)
o1
- the first objecto2
- the second objectpublic static int hashCode(Object o)
o
- the object to get the hashCode for.public static int compare(int v1, int v2)
v1
- the first valuev2
- the second valuepublic static int compare(long v1, long v2)
v1
- the first valuev2
- the second valuepublic static <T> BiPredicate<T,T> equalsPredicate()
T
- the value typepublic static int verifyPositive(int value, String paramName)
value
- the value to validateparamName
- the parameter name of the valueIllegalArgumentException
- if bufferSize <= 0public static long verifyPositive(long value, String paramName)
value
- the value to validateparamName
- the parameter name of the valueIllegalArgumentException
- if bufferSize <= 0@Deprecated public static long requireNonNull(long value, String message)
value
- the value to checkmessage
- the message to printCopyright © 2019. All rights reserved.