mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 15:27:45 +07:00
BoxForComparisonInspection enhanced -> UseCompareMethodInspection
Suggests to use Integer.compare(), etc. instead if ternary operator or if chain. Fixes IDEA-173766.
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Fix all 'Unnecessary boxing to compare primitives' problems in file" "true"
|
||||
// "Fix all ''compare()' method can be used to compare primitives' problems in file" "true"
|
||||
public class Test {
|
||||
public void test(int a, int b) {
|
||||
if(Integer.compare(a, b) > 0) {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Fix all 'Unnecessary boxing to compare primitives' problems in file" "true"
|
||||
// "Fix all ''compare()' method can be used to compare primitives' problems in file" "true"
|
||||
public class Test {
|
||||
public int test(String s1, String s2) {
|
||||
int res = Integer.compare(s1.length(), s2.length());
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Fix all ''compare()' method can be used to compare primitives' problems in file" "true"
|
||||
class Test {
|
||||
public void test(String s1, String s2) {
|
||||
int res;
|
||||
res = Integer.compare(s2.length(), s1.length())
|
||||
System.out.println(res);
|
||||
}
|
||||
|
||||
public void testMissingElse(String s1, String s2) {
|
||||
int res;
|
||||
if(s1.length() < s2.length()) res = 1;
|
||||
else if(s1.length() > s2.length()) res = -1;
|
||||
res = 0;
|
||||
System.out.println(res);
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Fix all ''compare()' method can be used to compare primitives' problems in file" "true"
|
||||
class Test {
|
||||
public int test(String s1, String s2) {
|
||||
return Integer.compare(s1.length(), s2.length());
|
||||
/*otherwise bigger*/
|
||||
}
|
||||
|
||||
public int test2(String s1, String s2) {
|
||||
return Integer.compare(s2.length(), s1.length());
|
||||
}
|
||||
|
||||
public int test3(String s1, String s2) {
|
||||
if(s1.length() > s2.length()) return -1;
|
||||
else if(s2.length() > s1.length()) return -1;
|
||||
else return 0;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Fix all ''compare()' method can be used to compare primitives' problems in file" "true"
|
||||
public class Test {
|
||||
public void test(String s1, String s2) {
|
||||
System.out.println(Integer.compare(s1.length(), s2.length()));
|
||||
System.out.println(Integer.compare(s2.length(), s1.length()));
|
||||
/*greater!*/
|
||||
/*less!*/
|
||||
/*equal!*/
|
||||
System.out.println(Integer.compare(s1.length(), s2.length()));
|
||||
System.out.println(Integer.compare(s2.length(), s1.length()));
|
||||
System.out.println(Integer.compare(s2.length(), s1.length()));
|
||||
|
||||
System.out.println(s1.length() < s2.length() ? -1 : s1.length() == s2.length() ? 0 : 2);
|
||||
System.out.println(s1.length() < s2.length() ? 1 : s2.length() < s1.length() ? 0 : 1);
|
||||
System.out.println(s1.length() == s2.length() ? 1 : s2.length() < s1.length() ? 0 : 1);
|
||||
System.out.println(s1.length() == s2.length() ? 0 : s2.length() < s2.length() ? -1 : 1);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Fix all 'Unnecessary boxing to compare primitives' problems in file" "true"
|
||||
// "Fix all ''compare()' method can be used to compare primitives' problems in file" "true"
|
||||
public class Test {
|
||||
public void test(int a, int b) {
|
||||
if(((Integer)a).compa<caret>reTo(b) > 0) {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Fix all 'Unnecessary boxing to compare primitives' problems in file" "true"
|
||||
// "Fix all ''compare()' method can be used to compare primitives' problems in file" "true"
|
||||
public class Test {
|
||||
public int test(String s1, String s2) {
|
||||
int res = new Integer(s1.length()).co<caret>mpareTo(s2.length());
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// "Fix all ''compare()' method can be used to compare primitives' problems in file" "true"
|
||||
class Test {
|
||||
public void test(String s1, String s2) {
|
||||
int res;
|
||||
i<caret>f(s1.length() < s2.length()) res = 1;
|
||||
else if(s1.length() > s2.length()) res = -1;
|
||||
else res = 0;
|
||||
System.out.println(res);
|
||||
}
|
||||
|
||||
public void testMissingElse(String s1, String s2) {
|
||||
int res;
|
||||
if(s1.length() < s2.length()) res = 1;
|
||||
else if(s1.length() > s2.length()) res = -1;
|
||||
res = 0;
|
||||
System.out.println(res);
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// "Fix all ''compare()' method can be used to compare primitives' problems in file" "true"
|
||||
class Test {
|
||||
public int test(String s1, String s2) {
|
||||
if(s1.length() < s2.length()) {
|
||||
return -1;
|
||||
}
|
||||
if((s1.length()) == s2.length()) return 0;
|
||||
else /*otherwise bigger*/ return +1;
|
||||
}
|
||||
|
||||
public int test2(String s1, String s2) {
|
||||
i<caret>f(s1.length() > s2.length()) return -1;
|
||||
else if(s2.length() > s1.length()) return 1;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
public int test3(String s1, String s2) {
|
||||
if(s1.length() > s2.length()) return -1;
|
||||
else if(s2.length() > s1.length()) return -1;
|
||||
else return 0;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Fix all ''compare()' method can be used to compare primitives' problems in file" "true"
|
||||
public class Test {
|
||||
public void test(String s1, String s2) {
|
||||
System.out.println(s1.<caret>length() < s2.length() ? -1 : s1.length() == s2.length() ? 0 : 1);
|
||||
System.out.println((s1.length() > s2.length()) ? -1 : s1.length() == s2.length() ? 0 : 1);
|
||||
System.out.println((s1.length() > s2.length()) ? /*greater!*/+1 : s1.length() < s2.length() ? /*less!*/-1 : /*equal!*/0);
|
||||
System.out.println(s1.length() == s2.length() ? 0 : s2.length() < s1.length() ? -1 : 1);
|
||||
System.out.println(s1.length() < s2.length() ? 1 : s2.length() < s1.length() ? -1 : 0);
|
||||
|
||||
System.out.println(s1.length() < s2.length() ? -1 : s1.length() == s2.length() ? 0 : 2);
|
||||
System.out.println(s1.length() < s2.length() ? 1 : s2.length() < s1.length() ? 0 : 1);
|
||||
System.out.println(s1.length() == s2.length() ? 1 : s2.length() < s1.length() ? 0 : 1);
|
||||
System.out.println(s1.length() == s2.length() ? 0 : s2.length() < s2.length() ? -1 : 1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user