From 2600c60fb509b0e4b5f95b7e61721106134d1587 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sat, 16 Sep 2017 08:29:20 +0000 Subject: [PATCH] Use Integer.compare() where possible git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1808522 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/ddf/AbstractEscherOptRecord.java | 2 +- .../formula/EvaluationConditionalFormatRule.java | 6 +++--- .../org/apache/poi/ss/util/NumberComparer.java | 2 +- .../org/apache/poi/xssf/util/CTColComparator.java | 2 +- .../apache/poi/hsmf/datatypes/RecipientChunks.java | 8 +------- .../src/org/apache/poi/hsmf/dev/TypesLister.java | 4 +--- .../poi/hwpf/converter/AbstractWordConverter.java | 2 +- .../org/apache/poi/hwpf/model/PropertyNode.java | 14 +++----------- .../org/apache/poi/hwpf/model/TextPieceTable.java | 11 ++--------- .../org/apache/poi/hwpf/usermodel/FieldsImpl.java | 2 +- .../org/apache/poi/ss/util/TestNumberComparer.java | 2 +- 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 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, 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 all = new ArrayList<>(MAPIProperty.getAll()); Collections.sort(all, new Comparator() { 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> 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> 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> 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, 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 " -- 2.39.5