mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 07:40:42 +07:00
RedundantCollectionOperation: remove by index and contains before add/remove
IDEA-182694 Inefficient uses of Collection/List.remove
This commit is contained in:
+9
@@ -0,0 +1,9 @@
|
||||
// "Remove the 'contains' check" "true"
|
||||
import java.util.List;
|
||||
|
||||
class Test {
|
||||
void test(List<String> list, String key) {
|
||||
/*contains!!!*/
|
||||
list.remove(/*remove!!!*/key);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Remove the 'contains' check" "true"
|
||||
import java.util.List;
|
||||
|
||||
class Test {
|
||||
void test(List<String> list, String key) {
|
||||
if(key != null) {
|
||||
list.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Remove the 'contains' check" "true"
|
||||
import java.util.List;
|
||||
|
||||
class Test {
|
||||
void test(List<String> list, String key) {
|
||||
if(key !=/*nullcheck*/ null && !key./*check*/isEmpty() /*and*/ /*key*/ //line comment
|
||||
) {
|
||||
list.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Use removal by object" "true"
|
||||
import java.util.List;
|
||||
|
||||
class Test {
|
||||
void test(List<String> list, String key) {
|
||||
list.remove(key);
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Use removal by object" "true"
|
||||
import java.util.List;
|
||||
|
||||
class Test {
|
||||
void test(List<String> list, String key) {
|
||||
list.remove(key);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Remove the 'contains' check" "true"
|
||||
import java.util.List;
|
||||
|
||||
class Test {
|
||||
void test(List<String> list, String key) {
|
||||
if(list.co<caret>ntains(/*contains!!!*/key)) {
|
||||
list.remove(/*remove!!!*/key);
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Remove the 'contains' check" "true"
|
||||
import java.util.List;
|
||||
|
||||
class Test {
|
||||
void test(List<String> list, String key) {
|
||||
if(key != null && list.co<caret>ntains(key)) {
|
||||
list.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Remove the 'contains' check" "true"
|
||||
import java.util.List;
|
||||
|
||||
class Test {
|
||||
void test(List<String> list, String key) {
|
||||
if(key !=/*nullcheck*/ null && !key./*check*/isEmpty() && /*and*/ list.co<caret>ntains(/*key*/key//line comment
|
||||
)) {
|
||||
list.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Remove the 'contains' check" "false"
|
||||
import java.util.List;
|
||||
|
||||
class Test {
|
||||
void test(List<String> list, String key) {
|
||||
if(list.co<caret>ntains(key) && key != null) {
|
||||
list.remove(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Use removal by object" "true"
|
||||
import java.util.List;
|
||||
|
||||
class Test {
|
||||
void test(List<String> list, String key) {
|
||||
list.r<caret>emove(list.indexOf(key));
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Use removal by object" "false"
|
||||
import java.util.List;
|
||||
|
||||
class Test {
|
||||
void test(List<String> list, String key) {
|
||||
int idx = list.indexOf(key);
|
||||
String x = list.r<caret>emove(idx);
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Use removal by object" "true"
|
||||
import java.util.List;
|
||||
|
||||
class Test {
|
||||
void test(List<String> list, String key) {
|
||||
int idx = list.indexOf(key);
|
||||
list.r<caret>emove(idx);
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Use removal by object" "false"
|
||||
import java.util.List;
|
||||
|
||||
class Test {
|
||||
void test(List<String> list, List<String> list2, String key) {
|
||||
int idx = list.indexOf(key);
|
||||
list2.r<caret>emove(idx);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user