Package org.apache.fop.util
Class CompareUtil
- java.lang.Object
-
- org.apache.fop.util.CompareUtil
-
public final class CompareUtil extends java.lang.Object
A utility class that provides helper methods for implementing equals and hashCode.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.Object
TIE_LOCK
-
Constructor Summary
Constructors Modifier Constructor Description private
CompareUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
equal(double n1, double n2)
Compares two numbers for equality.static boolean
equal(java.lang.Object o1, java.lang.Object o2)
Compares two objects for equality.static int
getHashCode(double number)
Returns a hash code for the given number.static int
getHashCode(java.lang.Object object)
Returns the hash code of the given object.
-
-
-
Method Detail
-
equal
public static boolean equal(java.lang.Object o1, java.lang.Object o2)
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
public static int getHashCode(java.lang.Object object)
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
-
-