You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2018/02/15 19:48:35 UTC
svn commit: r1824351 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/TextPositionComparator.java
Author: tilman
Date: Thu Feb 15 19:48:34 2018
New Revision: 1824351
URL: http://svn.apache.org/viewvc?rev=1824351&view=rev
Log:
PDFBOX-4071: use of the relational operators < and > in compareTo methods is verbose and error-prone and no longer recommended (Effective Java 2018, p69)
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/TextPositionComparator.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/TextPositionComparator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/TextPositionComparator.java?rev=1824351&r1=1824350&r2=1824351&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/TextPositionComparator.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/text/TextPositionComparator.java Thu Feb 15 19:48:34 2018
@@ -32,13 +32,10 @@ public class TextPositionComparator impl
public int compare(TextPosition pos1, TextPosition pos2)
{
// only compare text that is in the same direction
- if (pos1.getDir() < pos2.getDir())
+ int cmp1 = Float.compare(pos1.getDir(), pos2.getDir());
+ if (cmp1 != 0)
{
- return -1;
- }
- else if (pos1.getDir() > pos2.getDir())
- {
- return 1;
+ return cmp1;
}
// get the text direction adjusted coordinates
@@ -59,22 +56,11 @@ public class TextPositionComparator impl
pos2YBottom >= pos1YTop && pos2YBottom <= pos1YBottom ||
pos1YBottom >= pos2YTop && pos1YBottom <= pos2YBottom)
{
- if (x1 < x2)
- {
- return -1;
- }
- else if (x1 > x2)
- {
- return 1;
- }
- else
- {
- return 0;
- }
+ return Float.compare(x1, x2);
}
else if (pos1YBottom < pos2YBottom)
{
- return - 1;
+ return -1;
}
else
{