Java equals for object

Class Objects

This class consists of 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.

Method Summary

Checks if the sub-range from fromIndex (inclusive) to fromIndex + size (exclusive) is within the bounds of range from 0 (inclusive) to length (exclusive).

Checks if the sub-range from fromIndex (inclusive) to fromIndex + size (exclusive) is within the bounds of range from 0 (inclusive) to length (exclusive).

Checks if the sub-range from fromIndex (inclusive) to toIndex (exclusive) is within the bounds of range from 0 (inclusive) to length (exclusive).

Checks if the sub-range from fromIndex (inclusive) to toIndex (exclusive) is within the bounds of range from 0 (inclusive) to length (exclusive).

Checks that the specified object reference is not null and throws a customized NullPointerException if it is.

Checks that the specified object reference is not null and throws a customized NullPointerException if it is.

Returns the first argument if it is non- null and otherwise returns the non- null value of supplier.get() .

Returns the result of calling toString on the first argument if the first argument is not null and returns the second argument otherwise.

Methods declared in class java.lang.Object

Method Details

equals

Returns true if the arguments are equal to each other and false otherwise. Consequently, if both arguments are null , true is returned. Otherwise, if the first argument is not null , equality is determined by calling the equals method of the first argument with the second argument of this method. Otherwise, false is returned.

deepEquals

Returns true if the arguments are deeply equal to each other and false otherwise. Two null values are deeply equal. If both arguments are arrays, the algorithm in Arrays.deepEquals is used to determine equality. Otherwise, equality is determined by using the equals method of the first argument.

hashCode

hash

Generates 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 Arrays.hashCode(Object[]) . This method is useful for implementing Object.hashCode() on objects containing multiple fields. For example, if an object that has three fields, x , y , and z , one could write:

@Override public int hashCode()

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 hashCode(Object) .

toString

toString

Returns the result of calling toString on the first argument if the first argument is not null and returns the second argument otherwise.

compare

Returns 0 if the arguments are identical and c.compare(a, b) otherwise. Consequently, if both arguments are null 0 is returned. Note that if one of the arguments is null , a NullPointerException may or may not be thrown depending on what ordering policy, if any, the Comparator chooses to have for null values.

requireNonNull

Checks that the specified object reference is not null . This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:

requireNonNull

Checks that the specified object reference is not null and throws a customized NullPointerException if it is. This method is designed primarily for doing parameter validation in methods and constructors with multiple parameters, as demonstrated below:

public Foo(Bar bar, Baz baz)

isNull

nonNull

requireNonNullElse

requireNonNullElseGet

Returns the first argument if it is non- null and otherwise returns the non- null value of supplier.get() .

requireNonNull

Checks that the specified object reference is not null and throws a customized NullPointerException if it is. Unlike the method requireNonNull(Object, String) , this method allows creation of the message to be deferred until after the null check is made. While this may confer a performance advantage in the non-null case, when deciding to call this method care should be taken that the costs of creating the message supplier are less than the cost of just creating the string message directly.

checkIndex

Источник

Class Objects

This class consists of 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.

Method Summary

Checks if the sub-range from fromIndex (inclusive) to fromIndex + size (exclusive) is within the bounds of range from 0 (inclusive) to length (exclusive).

Checks if the sub-range from fromIndex (inclusive) to fromIndex + size (exclusive) is within the bounds of range from 0 (inclusive) to length (exclusive).

Checks if the sub-range from fromIndex (inclusive) to toIndex (exclusive) is within the bounds of range from 0 (inclusive) to length (exclusive).

Checks if the sub-range from fromIndex (inclusive) to toIndex (exclusive) is within the bounds of range from 0 (inclusive) to length (exclusive).

Checks that the specified object reference is not null and throws a customized NullPointerException if it is.

Checks that the specified object reference is not null and throws a customized NullPointerException if it is.

Returns the first argument if it is non- null and otherwise returns the non- null value of supplier.get() .

Returns a string equivalent to the string returned by Object.toString if that method and hashCode are not overridden.

Returns the result of calling toString on the first argument if the first argument is not null and returns the second argument otherwise.

Methods declared in class java.lang.Object

Method Details

equals

Returns true if the arguments are equal to each other and false otherwise. Consequently, if both arguments are null , true is returned. Otherwise, if the first argument is not null , equality is determined by calling the equals method of the first argument with the second argument of this method. Otherwise, false is returned.

deepEquals

Returns true if the arguments are deeply equal to each other and false otherwise. Two null values are deeply equal. If both arguments are arrays, the algorithm in Arrays.deepEquals is used to determine equality. Otherwise, equality is determined by using the equals method of the first argument.

hashCode

hash

Generates 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 Arrays.hashCode(Object[]) . This method is useful for implementing Object.hashCode() on objects containing multiple fields. For example, if an object that has three fields, x , y , and z , one could write:

@Override public int hashCode()

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 hashCode(Object) .

toString

toString

Returns the result of calling toString on the first argument if the first argument is not null and returns the second argument otherwise.

toIdentityString

Returns a string equivalent to the string returned by Object.toString if that method and hashCode are not overridden.

compare

Returns 0 if the arguments are identical and c.compare(a, b) otherwise. Consequently, if both arguments are null 0 is returned. Note that if one of the arguments is null , a NullPointerException may or may not be thrown depending on what ordering policy, if any, the Comparator chooses to have for null values.

requireNonNull

Checks that the specified object reference is not null . This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:

requireNonNull

Checks that the specified object reference is not null and throws a customized NullPointerException if it is. This method is designed primarily for doing parameter validation in methods and constructors with multiple parameters, as demonstrated below:

public Foo(Bar bar, Baz baz)

isNull

nonNull

requireNonNullElse

requireNonNullElseGet

Returns the first argument if it is non- null and otherwise returns the non- null value of supplier.get() .

requireNonNull

Checks that the specified object reference is not null and throws a customized NullPointerException if it is. Unlike the method requireNonNull(Object, String) , this method allows creation of the message to be deferred until after the null check is made. While this may confer a performance advantage in the non-null case, when deciding to call this method care should be taken that the costs of creating the message supplier are less than the cost of just creating the string message directly.

checkIndex

Источник

Читайте также:  Http tapk uvomintrans ru 222 tapk web2 login html
Оцените статью