Class EqualityUtils
PdfObject
avoiding infinity recursions in case when the same indirect objects stores itself as a part of internal state.
Note that it is expected that compared objects are valid PdfObjects. It means that only indirect objects (PdfObject.isIndirect()
is true) may be a reason of the recursion. Therefore certain checks done only for them. It can be possible to create a PdfObject manually for which equals / hashCode calculation will not work correctly.
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
areEqual
(com.itextpdf.kernel.pdf.PdfObject obj1, com.itextpdf.kernel.pdf.PdfObject obj2) Checks the equality of two object.static int
getHashCode
(com.itextpdf.kernel.pdf.PdfObject object) Calculates a hash for the object.
-
Method Details
-
getHashCode
public static int getHashCode(com.itextpdf.kernel.pdf.PdfObject object) Calculates a hash for the object. IfObject.hashCode()
is overridden for the class then it will be called. Otherwise custom calculation will be done.Two instances will have equal hashCode if they are considered as equal by
areEqual(PdfObject, PdfObject)
method.Note that checks to avoid infinity recursions are done only for indirect objects (
PdfObject.isIndirect()
is true).- Parameters:
-
object
- is aPdfObject
whose content-based hash code to compute - Returns:
- a content-based hash code
-
areEqual
public static boolean areEqual(com.itextpdf.kernel.pdf.PdfObject obj1, com.itextpdf.kernel.pdf.PdfObject obj2) Checks the equality of two object. IfObject.equals(Object)
()} is overridden for the class then it will be called. Otherwise custom calculation will be done.If is possible that two objects cannot be compared because they are nested in each other or each into itself. In such case equality check for objects obj1 and obj2 may depend on the equality check for the same objects. To avoid infinity recursion in such cases equality check of nested objects will return true.
For example if array A contains as its only element array B and array B contains as its only element array B then equals(A, B) will return true. It is because the first elements of each array are B and A respectively and during the whole process of comparison of A and B arrays any nested pair of A and B will be considered as equal. As the only elements of each array are considered as equal the result of equality check of two arrays will be true.
However if array A contains array B and a PdfNumber 1 and array B contains array A and a PdfNumber 2 then will be considered as not equal. Equality check for the first elements of each array will return true as above but the second elements are different: 1 is not equal to 2. That is the reason why arrays A and B will be considered as not equal.
Note that checks to avoid inifinity recursions are done only for indirect objects (
PdfObject.isIndirect()
is true).- Parameters:
-
obj1
- is the firstPdfObject
to compare -
obj2
- is the secondPdfObject
to compare - Returns:
- true if objects are considered as equal
-