mirror of https://github.com/apache/poi.git
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:
parent
0297946834
commit
5dadfd7c18
|
@ -142,7 +142,7 @@ public abstract class AbstractEscherOptRecord extends EscherRecord
|
||||||
{
|
{
|
||||||
short s1 = p1.getPropertyNumber();
|
short s1 = p1.getPropertyNumber();
|
||||||
short s2 = p2.getPropertyNumber();
|
short s2 = p2.getPropertyNumber();
|
||||||
return s1 < s2 ? -1 : s1 == s2 ? 0 : 1;
|
return Short.compare(s1, s2);
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,16 +242,16 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
|
||||||
final int x = getPriority();
|
final int x = getPriority();
|
||||||
final int y = o.getPriority();
|
final int y = o.getPriority();
|
||||||
// logic from Integer.compare()
|
// logic from Integer.compare()
|
||||||
cmp = (x < y) ? -1 : ((x == y) ? 0 : 1);
|
cmp = Integer.compare(x, y);
|
||||||
if (cmp != 0) {
|
if (cmp != 0) {
|
||||||
return cmp;
|
return cmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmp = new Integer(getFormattingIndex()).compareTo(new Integer(o.getFormattingIndex()));
|
cmp = Integer.compare(getFormattingIndex(), o.getFormattingIndex());
|
||||||
if (cmp != 0) {
|
if (cmp != 0) {
|
||||||
return cmp;
|
return cmp;
|
||||||
}
|
}
|
||||||
return new Integer(getRuleIndex()).compareTo(new Integer(o.getRuleIndex()));
|
return Integer.compare(getRuleIndex(), o.getRuleIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -131,7 +131,7 @@ public final class NumberComparer {
|
||||||
* If both numbers are subnormal, Excel seems to use standard comparison rules
|
* If both numbers are subnormal, Excel seems to use standard comparison rules
|
||||||
*/
|
*/
|
||||||
private static int compareSubnormalNumbers(long fracA, long fracB, boolean isNegative) {
|
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;
|
return isNegative ? -cmp : cmp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class CTColComparator {
|
||||||
public int compare(CTCol col1, CTCol col2) {
|
public int compare(CTCol col1, CTCol col2) {
|
||||||
long col1max = col1.getMax();
|
long col1max = col1.getMax();
|
||||||
long col2max = col2.getMax();
|
long col2max = col2.getMax();
|
||||||
return col1max < col2max ? -1 : col1max > col2max ? 1 : 0;
|
return Long.compare(col1max, col2max);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -222,13 +222,7 @@ public final class RecipientChunks implements ChunkGroupWithProperties {
|
||||||
implements Comparator<RecipientChunks>, Serializable {
|
implements Comparator<RecipientChunks>, Serializable {
|
||||||
@Override
|
@Override
|
||||||
public int compare(RecipientChunks a, RecipientChunks b) {
|
public int compare(RecipientChunks a, RecipientChunks b) {
|
||||||
if (a.recipientNumber < b.recipientNumber) {
|
return Integer.compare(a.recipientNumber, b.recipientNumber);
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (a.recipientNumber > b.recipientNumber) {
|
|
||||||
return +1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,9 +43,7 @@ public class TypesLister {
|
||||||
ArrayList<MAPIProperty> all = new ArrayList<>(MAPIProperty.getAll());
|
ArrayList<MAPIProperty> all = new ArrayList<>(MAPIProperty.getAll());
|
||||||
Collections.sort(all, new Comparator<MAPIProperty>() {
|
Collections.sort(all, new Comparator<MAPIProperty>() {
|
||||||
public int compare(MAPIProperty a, MAPIProperty b) {
|
public int compare(MAPIProperty a, MAPIProperty b) {
|
||||||
if(a.id < b.id) return -1;
|
return Integer.compare(a.id, b.id);
|
||||||
if(a.id > b.id) return +1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
list(all, out);
|
list(all, out);
|
||||||
|
|
|
@ -102,7 +102,7 @@ public abstract class AbstractWordConverter
|
||||||
|
|
||||||
public int compareTo( Structure o )
|
public int compareTo( Structure o )
|
||||||
{
|
{
|
||||||
return start < o.start ? -1 : start == o.start ? 0 : 1;
|
return Integer.compare(start, o.start);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -43,8 +43,7 @@ public abstract class PropertyNode<T extends PropertyNode<T>> implements Compara
|
||||||
public int compare(PropertyNode<?> o1, PropertyNode<?> o2) {
|
public int compare(PropertyNode<?> o1, PropertyNode<?> o2) {
|
||||||
int thisVal = o1.getEnd();
|
int thisVal = o1.getEnd();
|
||||||
int anotherVal = o2.getEnd();
|
int anotherVal = o2.getEnd();
|
||||||
return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0
|
return (Integer.compare(thisVal, anotherVal));
|
||||||
: 1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,8 +54,7 @@ public abstract class PropertyNode<T extends PropertyNode<T>> implements Compara
|
||||||
public int compare(PropertyNode<?> o1, PropertyNode<?> o2) {
|
public int compare(PropertyNode<?> o1, PropertyNode<?> o2) {
|
||||||
int thisVal = o1.getStart();
|
int thisVal = o1.getStart();
|
||||||
int anotherVal = o2.getStart();
|
int anotherVal = o2.getStart();
|
||||||
return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0
|
return (Integer.compare(thisVal, anotherVal));
|
||||||
: 1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,12 +173,6 @@ public abstract class PropertyNode<T extends PropertyNode<T>> implements Compara
|
||||||
*/
|
*/
|
||||||
public int compareTo(T o) {
|
public int compareTo(T o) {
|
||||||
int cpEnd = o.getEnd();
|
int cpEnd = o.getEnd();
|
||||||
if (_cpEnd == cpEnd) {
|
return Integer.compare(_cpEnd, cpEnd);
|
||||||
return 0;
|
|
||||||
} else if (_cpEnd < cpEnd) {
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -449,15 +449,8 @@ public class TextPieceTable implements CharIndexTranslator {
|
||||||
|
|
||||||
protected static class FCComparator implements Comparator<TextPiece>, Serializable {
|
protected static class FCComparator implements Comparator<TextPiece>, Serializable {
|
||||||
public int compare(TextPiece textPiece, TextPiece textPiece1) {
|
public int compare(TextPiece textPiece, TextPiece textPiece1) {
|
||||||
if (textPiece.getPieceDescriptor().fc > textPiece1
|
return Integer.compare(textPiece.getPieceDescriptor().fc, textPiece1
|
||||||
.getPieceDescriptor().fc) {
|
.getPieceDescriptor().fc);
|
||||||
return 1;
|
|
||||||
} else if (textPiece.getPieceDescriptor().fc < textPiece1
|
|
||||||
.getPieceDescriptor().fc) {
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,7 +267,7 @@ public class FieldsImpl implements Fields
|
||||||
{
|
{
|
||||||
int thisVal = o1.getFcStart();
|
int thisVal = o1.getFcStart();
|
||||||
int anotherVal = o2.getFcStart();
|
int anotherVal = o2.getFcStart();
|
||||||
return thisVal < anotherVal ? -1 : thisVal == anotherVal ? 0 : 1;
|
return Integer.compare(thisVal, anotherVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ public final class TestNumberComparer {
|
||||||
private static boolean confirm(int i, double a, double b, int expRes) {
|
private static boolean confirm(int i, double a, double b, int expRes) {
|
||||||
int actRes = NumberComparer.compare(a, b);
|
int actRes = NumberComparer.compare(a, b);
|
||||||
|
|
||||||
int sgnActRes = actRes < 0 ? -1 : actRes > 0 ? +1 : 0;
|
int sgnActRes = Integer.compare(actRes, 0);
|
||||||
if (sgnActRes != expRes) {
|
if (sgnActRes != expRes) {
|
||||||
System.err.println("Mismatch example[" + i + "] ("
|
System.err.println("Mismatch example[" + i + "] ("
|
||||||
+ formatDoubleAsHex(a) + ", " + formatDoubleAsHex(b) + ") expected "
|
+ formatDoubleAsHex(a) + ", " + formatDoubleAsHex(b) + ") expected "
|
||||||
|
|
Loading…
Reference in New Issue