Package org.apache.fop.util
Class CompareUtil
java.lang.Object
org.apache.fop.util.CompareUtil
A utility class that provides helper methods for implementing equals and hashCode.
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
equal
(double n1, double n2) Compares two numbers for equality.static boolean
Compares two objects for equality.static int
getHashCode
(double number) Returns a hash code for the given number.static int
getHashCode
(Object object) Returns the hash code of the given object.
-
Method Details
-
equal
Compares two objects for equality. In order to prevent lock-ordering deadlocks the following strategy is used: when two non null objects are passed to the method, the comparison is done by calling theObject.equals(Object)
method of the object with the lower hash code (System.identityHashCode(Object)
); in the rare case that two different objects have the same hash code, a lock is used.- Parameters:
o1
- an objecto2
- another object- Returns:
- true if either o1 and o2 are null or if o1.equals(o2)
-
getHashCode
Returns the hash code of the given object.- Parameters:
object
- an object- Returns:
- object.hashCode(), or 0 if object is null
-
equal
public static boolean equal(double n1, double n2) Compares two numbers for equality. Uses the same comparison algorithm as theDouble.equals(Object)
method.- Parameters:
n1
- a numbern2
- another number- Returns:
- true if the two numbers are equal, false otherwise
-
getHashCode
public static int getHashCode(double number) Returns a hash code for the given number. Applies the same algorithm as theDouble.hashCode()
method.- Parameters:
number
- a number- Returns:
- a hash code for that number
-