Use Integer.compare() where possible

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1808522 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2017-09-16 08:29:20 +00:00
parent 0297946834
commit 5dadfd7c18
11 changed files with 16 additions and 39 deletions

View File

@ -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);
}
} );
}

View File

@ -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

View File

@ -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;
}

View File

@ -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);
}
};

View File

@ -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);
}
}
}

View File

@ -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);

View File

@ -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

View File

@ -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);
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}

View File

@ -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 "