aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2017-09-16 08:29:20 +0000
committerDominik Stadler <centic@apache.org>2017-09-16 08:29:20 +0000
commit5dadfd7c186030130ac2b13777a0e98bb2b80b8b (patch)
treeb7646c51ef9e0b09b2d32d713a069daaff46b978 /src
parent0297946834c1c6be6a98bdc789ad97da6f67e430 (diff)
downloadpoi-5dadfd7c186030130ac2b13777a0e98bb2b80b8b.tar.gz
poi-5dadfd7c186030130ac2b13777a0e98bb2b80b8b.zip
Use Integer.compare() where possible
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1808522 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java2
-rw-r--r--src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java6
-rw-r--r--src/java/org/apache/poi/ss/util/NumberComparer.java2
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/util/CTColComparator.java2
-rw-r--r--src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java8
-rw-r--r--src/scratchpad/src/org/apache/poi/hsmf/dev/TypesLister.java4
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java2
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java14
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java11
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/usermodel/FieldsImpl.java2
-rw-r--r--src/testcases/org/apache/poi/ss/util/TestNumberComparer.java2
11 files changed, 16 insertions, 39 deletions
diff --git a/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java b/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java
index 6009b00522..ff4a3e80de 100644
--- a/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java
+++ b/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java
@@ -142,7 +142,7 @@ public abstract class AbstractEscherOptRecord extends EscherRecord
{
short s1 = p1.getPropertyNumber();
short s2 = p2.getPropertyNumber();
- return s1 < s2 ? -1 : s1 == s2 ? 0 : 1;
+ return Short.compare(s1, s2);
}
} );
}
diff --git a/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java b/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java
index 6c39634117..ecd61ace5e 100644
--- a/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java
+++ b/src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java
@@ -242,16 +242,16 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
final int x = getPriority();
final int y = o.getPriority();
// logic from Integer.compare()
- cmp = (x < y) ? -1 : ((x == y) ? 0 : 1);
+ cmp = Integer.compare(x, y);
if (cmp != 0) {
return cmp;
}
- cmp = new Integer(getFormattingIndex()).compareTo(new Integer(o.getFormattingIndex()));
+ cmp = Integer.compare(getFormattingIndex(), o.getFormattingIndex());
if (cmp != 0) {
return cmp;
}
- return new Integer(getRuleIndex()).compareTo(new Integer(o.getRuleIndex()));
+ return Integer.compare(getRuleIndex(), o.getRuleIndex());
}
@Override
diff --git a/src/java/org/apache/poi/ss/util/NumberComparer.java b/src/java/org/apache/poi/ss/util/NumberComparer.java
index 56648126e6..bf903ffa92 100644
--- a/src/java/org/apache/poi/ss/util/NumberComparer.java
+++ b/src/java/org/apache/poi/ss/util/NumberComparer.java
@@ -131,7 +131,7 @@ public final class NumberComparer {
* If both numbers are subnormal, Excel seems to use standard comparison rules
*/
private static int compareSubnormalNumbers(long fracA, long fracB, boolean isNegative) {
- int cmp = fracA > fracB ? +1 : fracA < fracB ? -1 : 0;
+ int cmp = Long.compare(fracA, fracB);
return isNegative ? -cmp : cmp;
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/util/CTColComparator.java b/src/ooxml/java/org/apache/poi/xssf/util/CTColComparator.java
index 5368eb0e6e..ef8e526a43 100644
--- a/src/ooxml/java/org/apache/poi/xssf/util/CTColComparator.java
+++ b/src/ooxml/java/org/apache/poi/xssf/util/CTColComparator.java
@@ -30,7 +30,7 @@ public class CTColComparator {
public int compare(CTCol col1, CTCol col2) {
long col1max = col1.getMax();
long col2max = col2.getMax();
- return col1max < col2max ? -1 : col1max > col2max ? 1 : 0;
+ return Long.compare(col1max, col2max);
}
};
diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java
index 6680cde922..e9241845fd 100644
--- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java
+++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java
@@ -222,13 +222,7 @@ public final class RecipientChunks implements ChunkGroupWithProperties {
implements Comparator<RecipientChunks>, Serializable {
@Override
public int compare(RecipientChunks a, RecipientChunks b) {
- if (a.recipientNumber < b.recipientNumber) {
- return -1;
- }
- if (a.recipientNumber > b.recipientNumber) {
- return +1;
- }
- return 0;
+ return Integer.compare(a.recipientNumber, b.recipientNumber);
}
}
}
diff --git a/src/scratchpad/src/org/apache/poi/hsmf/dev/TypesLister.java b/src/scratchpad/src/org/apache/poi/hsmf/dev/TypesLister.java
index a3bc793ac8..663b806147 100644
--- a/src/scratchpad/src/org/apache/poi/hsmf/dev/TypesLister.java
+++ b/src/scratchpad/src/org/apache/poi/hsmf/dev/TypesLister.java
@@ -43,9 +43,7 @@ public class TypesLister {
ArrayList<MAPIProperty> all = new ArrayList<>(MAPIProperty.getAll());
Collections.sort(all, new Comparator<MAPIProperty>() {
public int compare(MAPIProperty a, MAPIProperty b) {
- if(a.id < b.id) return -1;
- if(a.id > b.id) return +1;
- return 0;
+ return Integer.compare(a.id, b.id);
}
});
list(all, out);
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java
index 0a29f0b7dc..b5ec864ff1 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java
@@ -102,7 +102,7 @@ public abstract class AbstractWordConverter
public int compareTo( Structure o )
{
- return start < o.start ? -1 : start == o.start ? 0 : 1;
+ return Integer.compare(start, o.start);
}
@Override
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java
index 2b307e1995..a0e0fec6e4 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java
@@ -43,8 +43,7 @@ public abstract class PropertyNode<T extends PropertyNode<T>> implements Compara
public int compare(PropertyNode<?> o1, PropertyNode<?> o2) {
int thisVal = o1.getEnd();
int anotherVal = o2.getEnd();
- return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0
- : 1));
+ return (Integer.compare(thisVal, anotherVal));
}
}
@@ -55,8 +54,7 @@ public abstract class PropertyNode<T extends PropertyNode<T>> implements Compara
public int compare(PropertyNode<?> o1, PropertyNode<?> o2) {
int thisVal = o1.getStart();
int anotherVal = o2.getStart();
- return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0
- : 1));
+ return (Integer.compare(thisVal, anotherVal));
}
}
@@ -175,12 +173,6 @@ public abstract class PropertyNode<T extends PropertyNode<T>> implements Compara
*/
public int compareTo(T o) {
int cpEnd = o.getEnd();
- if (_cpEnd == cpEnd) {
- return 0;
- } else if (_cpEnd < cpEnd) {
- return -1;
- } else {
- return 1;
- }
+ return Integer.compare(_cpEnd, cpEnd);
}
}
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
index 16c78e6e1a..ee14b50e1e 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
@@ -449,15 +449,8 @@ public class TextPieceTable implements CharIndexTranslator {
protected static class FCComparator implements Comparator<TextPiece>, Serializable {
public int compare(TextPiece textPiece, TextPiece textPiece1) {
- if (textPiece.getPieceDescriptor().fc > textPiece1
- .getPieceDescriptor().fc) {
- return 1;
- } else if (textPiece.getPieceDescriptor().fc < textPiece1
- .getPieceDescriptor().fc) {
- return -1;
- } else {
- return 0;
- }
+ return Integer.compare(textPiece.getPieceDescriptor().fc, textPiece1
+ .getPieceDescriptor().fc);
}
}
}
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/FieldsImpl.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/FieldsImpl.java
index b4c972d87f..90a629235b 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/FieldsImpl.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/FieldsImpl.java
@@ -267,7 +267,7 @@ public class FieldsImpl implements Fields
{
int thisVal = o1.getFcStart();
int anotherVal = o2.getFcStart();
- return thisVal < anotherVal ? -1 : thisVal == anotherVal ? 0 : 1;
+ return Integer.compare(thisVal, anotherVal);
}
}
diff --git a/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java b/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java
index 33cf09ad75..b48ebee5a7 100644
--- a/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java
+++ b/src/testcases/org/apache/poi/ss/util/TestNumberComparer.java
@@ -93,7 +93,7 @@ public final class TestNumberComparer {
private static boolean confirm(int i, double a, double b, int expRes) {
int actRes = NumberComparer.compare(a, b);
- int sgnActRes = actRes < 0 ? -1 : actRes > 0 ? +1 : 0;
+ int sgnActRes = Integer.compare(actRes, 0);
if (sgnActRes != expRes) {
System.err.println("Mismatch example[" + i + "] ("
+ formatDoubleAsHex(a) + ", " + formatDoubleAsHex(b) + ") expected "