mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 00:11:26 +07:00
IDEA-173177 Inspection: Comparing 'compareTo()` or 'Comparator.compare()' result with 1 / -1
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace with '> 0'" "true"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
void test(String str) {
|
||||
if(str.compareTo("xyz") > 0) {
|
||||
System.out.println("Oops");
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Fix all 'Comparison of compare method result with specific constant' problems in file" "true"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
String test(Comparable<?> c1, Comparable<?> c2) {
|
||||
int result = c1.compareTo(c2);
|
||||
if(0 == result) {
|
||||
return "equal";
|
||||
} else if(0 > result) {
|
||||
return "less";
|
||||
} else if(0 < result) {
|
||||
return "greater";
|
||||
} else {
|
||||
return "impossible";
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace with '>= 0'" "true"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
void test(Comparator<String> cmp) {
|
||||
if(cmp.compare("a", "b") >= 0) {
|
||||
System.out.println("Oops");
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace with '> 0'" "true"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
void test(String str) {
|
||||
if(str.compareTo("xyz") =<caret>= 1) {
|
||||
System.out.println("Oops");
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Fix all 'Comparison of compare method result with specific constant' problems in file" "true"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
String test(Comparable<?> c1, Comparable<?> c2) {
|
||||
int result = c1.compareTo(c2);
|
||||
if(0 == result) {
|
||||
return "equal";
|
||||
} else if(-1 =<caret>= result) {
|
||||
return "less";
|
||||
} else if(1 == result) {
|
||||
return "greater";
|
||||
} else {
|
||||
return "impossible";
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Replace with '>= 0'" "true"
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
void test(Comparator<String> cmp) {
|
||||
if(cmp.compare("a", "b") !<caret>= -1) {
|
||||
System.out.println("Oops");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user