You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (JIRA)" <ji...@apache.org> on 2017/05/17 13:38:04 UTC

[jira] [Comment Edited] (PDFBOX-3794) Problem in TextPosition implementation

    [ https://issues.apache.org/jira/browse/PDFBOX-3794?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16014048#comment-16014048 ] 

Tilman Hausherr edited comment on PDFBOX-3794 at 5/17/17 1:37 PM:
------------------------------------------------------------------

{quote}
I don't know the reason of the late assignment to direction
{quote}
generation by an IDE.

How about removing this line from the hash code calculation?
{code}
result = 31 * result + Float.floatToIntBits(direction);
{code}
The direction isn't a "core" field, it is cached for speed.


was (Author: tilman):
{quote}
I don't know the reason of the late assignment to direction
{quote}
generation by an IDE.

How about removing this line from the hash code calculation?
{code}
result = 31 * result + Float.floatToIntBits(direction);
{code}
The direction isn't a "core" field, it is cached for speed reasons.

> Problem in TextPosition implementation
> --------------------------------------
>
>                 Key: PDFBOX-3794
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3794
>             Project: PDFBox
>          Issue Type: Bug
>            Reporter: Miro Mannino
>              Labels: easyfix
>
> In 2.0.3 there wasn't hashCode implemented in TextPosition, and for me that was fine. Same instance, same hashCode.
> In 2.0.6 the hashCode is now checking the fields values, which is reasonable. But, the hashCode in the same instance can have different results.
> The problem is in the `direction` field, which is -1.0 and initialised only when getDir is called the first time.
> For now as workaround, anytime (or just the first time) I need the textPosition's hashCode I call getDir before that. 
> Quick example:
> {code}
> Object getObjectFromTextPos(TextPosition textPos) {
>     textPos.getDir();
>     return someHashMap.get(textPos);
> }
> {code}
> I don't know the reason of the late assignment to direction, but if that is necessary, I would say that the hashCode should call getDir() instead of using the field.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org