IDEA-187130 Inspection: Comparison of primitives with compareTo()

This commit is contained in:
Tagir Valeev
2018-03-01 12:31:51 +07:00
parent b65896dd2f
commit c4da8fdb79
8 changed files with 193 additions and 4 deletions

View File

@@ -0,0 +1,39 @@
// "Fix all" "true"
class CompareTest {
int testInteger(int a, int b) {
if(a < b) return 1;
if(a > b) return 2;
if(a >= b) return 3;
if(1 <= Integer.compare(a, b)) return 4;
if(a != b) return 5;
return 0;
}
int testShort(short a, byte b) {
if(a < b) return 1;
if(a >= b) return 2;
if(1 <= Short.compare(a, b)) return 4;
return 0;
}
int testByte(int a, int b) {
if((byte) a < (byte) b) return 1;
if(Byte.compare((byte)a, (byte)b) >= 1) return 2;
return 0;
}
int testLong(long a, long b, long c, int d) {
if(a + b < c + d) return 1;
/*2*/
/*3*/
/*4*/
/*5*/
/*8*/
/*9*/
/*10*/
/*11*/
/*12*/
if(/*1*/(d /*6*/ > 0 ? /*7*/a : b) < c/*13*/) return 1;
return 0;
}
}

View File

@@ -0,0 +1,30 @@
// "Fix all 'Redundant 'compare' method call' problems in file" "true"
class CompareTest {
int testInteger(int a, int b) {
if(Integer.c<caret>ompare(a, b) < 0) return 1;
if(Integer.compare(a, b) > 0) return 2;
if(0 <= Integer.compare(a, b)) return 3;
if(1 <= Integer.compare(a, b)) return 4;
if(0 != Integer.compare(a, b)) return 5;
return 0;
}
int testShort(short a, byte b) {
if(Short.compare(a, b) < 0) return 1;
if(Short.compare(a, b) >= 0) return 2;
if(1 <= Short.compare(a, b)) return 4;
return 0;
}
int testByte(int a, int b) {
if(Byte.compare((byte)a, (byte)b) < 0) return 1;
if(Byte.compare((byte)a, (byte)b) >= 1) return 2;
return 0;
}
int testLong(long a, long b, long c, int d) {
if(Long.compare(a + b, c + d) < 0) return 1;
if(/*1*/Long/*2*/./*3*/compare/*4*/(/*5*/d /*6*/> 0 ? /*7*/a : b/*8*/, /*9*/c/*10*/) /*11*/< /*12*/0/*13*/) return 1;
return 0;
}
}