static
utility methods for operating
on objects, or checking certain conditions before operation. 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, and checking if indexes or sub-range values are out of bounds.
Access | Constructor and Description |
---|---|
private |
Modifier and Type | Method and Description |
---|---|
public static int | Returns: fromIndex if the sub-range within bounds of the rangethe lower-bound (inclusive) of the sub-interval fromIndex, int the size of the sub-range size, int the upper-bound (exclusive) of the range length)Checks if the sub-range from |
public static long | Returns: fromIndex if the sub-range within bounds of the rangethe lower-bound (inclusive) of the sub-interval fromIndex, long the size of the sub-range size, long the upper-bound (exclusive) of the range length)Checks if the sub-range from |
public static int | Returns: fromIndex if the sub-range within bounds of the rangethe lower-bound (inclusive) of the sub-range fromIndex, int the upper-bound (exclusive) of the sub-range toIndex, int the upper-bound (exclusive) the range length)Checks if the sub-range from |
public static long | Returns: fromIndex if the sub-range within bounds of the rangethe lower-bound (inclusive) of the sub-range fromIndex, long the upper-bound (exclusive) of the sub-range toIndex, long the upper-bound (exclusive) the range length)Checks if the sub-range from |
public static int | Returns: index if it is within bounds of the rangethe index index, int the upper-bound (exclusive) of the range length)Checks if the |
public static long | Returns: index if it is within bounds of the rangethe index index, long the upper-bound (exclusive) of the range length)Checks if the |
public static < the type of the objects being compared T> int | Returns: 0 if the arguments are identical andc.compare(a, b) otherwisean object a, T an object to be compared with b, Comparator<? super T> a the c)Comparator to compare the first two argumentsReturns 0 if the arguments are identical and |
public static boolean | Returns: true if the arguments are deeply equal to each other
and false otherwisean object a, Object an object to be compared with b)a for deep equalityReturns |
public static boolean | |
public static int | |
public static int | |
public static boolean | |
public static boolean | |
public static < the type of the reference T> T | Returns: obj if not null the object reference to check for nullity obj)Checks that the specified object reference is not |
public static < the type of the reference T> T | Returns: obj if not null the object reference to check for nullity obj, String detail message to be used in the event that a message)NullPointerException is thrownChecks that the specified object reference is not |
public static < the type of the reference T> T | Returns: obj if not null the object reference to check for nullity obj, Supplier<String> supplier of the detail message to be
used in the event that a messageSupplier)NullPointerException is thrownChecks that the specified object reference is not |
public static < the type of the reference T> T | Returns: the first argument if it is non-null and
otherwise the second argument if it is non-null an object obj, T a non- defaultObj)null object to return if the first argument
is null Returns the first argument if it is non- |
public static < the type of the first argument and return type T> T | Returns: the first argument if it is non-null and
otherwise the value from supplier.get() if it is
non-null an object obj, Supplier<? extends T> of a non- supplier)null object to return if the first argument
is null Returns the first argument if it is non- |
public static String | Returns: a string equivalent to the string returned byObject.toString if that method and hashCode are not
overriddenan object o)Returns a string equivalent to the string returned by |
public static String | |
public static String | Returns: the result of callingtoString on the first
argument if the first argument is not null and the
second argument otherwisean object o, String string to return if the first argument is
nullDefault)null Returns the result of calling |
Objects | back to summary |
---|---|
private Objects() |
checkFromIndexSize | back to summary |
---|---|
public static int checkFromIndexSize(int fromIndex, int size, int length) Checks if the sub-range from The sub-range is defined to be out of bounds if any of the following inequalities is true:
|
checkFromIndexSize | back to summary |
---|---|
public static long checkFromIndexSize(long fromIndex, long size, long length) Checks if the sub-range from The sub-range is defined to be out of bounds if any of the following inequalities is true:
|
checkFromToIndex | back to summary |
---|---|
public static int checkFromToIndex(int fromIndex, int toIndex, int length) Checks if the sub-range from The sub-range is defined to be out of bounds if any of the following inequalities is true:
|
checkFromToIndex | back to summary |
---|---|
public static long checkFromToIndex(long fromIndex, long toIndex, long length) Checks if the sub-range from The sub-range is defined to be out of bounds if any of the following inequalities is true:
|
checkIndex | back to summary |
---|---|
public static int checkIndex(int index, int length) Checks if the The
|
checkIndex | back to summary |
---|---|
public static long checkIndex(long index, long length) Checks if the The
|
compare | back to summary |
---|---|
public static <T> int compare(T a, T b, Comparator<? super T> c) Returns 0 if the arguments are identical and Note that if one of the arguments is
|
deepEquals | back to summary |
---|---|
public static boolean deepEquals(Object a, Object b) Returns
|
equals | back to summary |
---|---|
public static boolean equals(Object a, Object b) Returns
|
hash | back to summary |
---|---|
public static int hash(Object... values) Returns a hash code for a sequence of input values. The hash
code is generated as if all the input values were placed into an
array, and that array were hashed by calling This method is useful for implementing 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@Override public int hashCode() { return Objects.hash(x, y, z); } hashCode(Object) .
|
hashCode | back to summary |
---|---|
public static int hashCode(Object o) Returns the hash code of a non-
|
isNull | back to summary |
---|---|
public static boolean isNull(Object obj) Returns API Note This method exists to be used as a
|
nonNull | back to summary |
---|---|
public static boolean nonNull(Object obj) Returns API Note This method exists to be used as a
|
requireNonNull | back to summary |
---|---|
public static <T> T requireNonNull(T obj) Checks that the specified object reference is not public Foo(Bar bar) { this.bar = Objects.requireNonNull(bar); }
|
requireNonNull | back to summary |
---|---|
public static <T> T requireNonNull(T obj, String message) Checks that the specified object reference is not public Foo(Bar bar, Baz baz) { this.bar = Objects.requireNonNull(bar, "bar must not be null"); this.baz = Objects.requireNonNull(baz, "baz must not be null"); }
|
requireNonNull | back to summary |
---|---|
public static <T> T requireNonNull(T obj, Supplier<String> messageSupplier) Checks that the specified object reference is not Unlike the method
|
requireNonNullElse | back to summary |
---|---|
public static <T> T requireNonNullElse(T obj, T defaultObj) Returns the first argument if it is non-
|
requireNonNullElseGet | back to summary |
---|---|
public static <T> T requireNonNullElseGet(T obj, Supplier<? extends T> supplier) Returns the first argument if it is non-
|
toIdentityString | back to summary |
---|---|
public static String toIdentityString(Object o) Returns a string equivalent to the string returned by Implementation Note This method constructs a string for an object without calling any overridable methods of the object. Implementation Specification The method returns a string equivalent to:
|
toString | back to summary |
---|---|
public static String toString(Object o) Returns the result of calling
|
toString | back to summary |
---|---|
public static String toString(Object o, String nullDefault) Returns the result of calling
|