mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-30 10:20:15 +07:00
IDEA-165942 Inspection to replace method call in a loop with bulk operation
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public void test(Integer[] arr) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
result.add(1);
|
||||
result.addAll(Arrays.asList(arr));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
class Person {}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
List<Person> names = new ArrayList<>();
|
||||
names.addAll(persons);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
static class MyList extends AbstractCollection<String> {
|
||||
@Override
|
||||
public Iterator<String> iterator() {
|
||||
return Collections.emptyIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean myAdd(Collection<? extends String> c) {
|
||||
this.addAll(c);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
class Person {}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
List<Person> names = new ArrayList<>();
|
||||
names.addAll(persons);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class Sample {
|
||||
List<String> foo = new ArrayList<>();
|
||||
String foo(){
|
||||
Sample sm = new Sample();
|
||||
sm.foo.addAll(foo);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void test(Integer[] arr) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
result.add(1);
|
||||
result.addAll(Arrays.asList(arr));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void test(Integer[] arr) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
result.add(1);
|
||||
result.addAll(Arrays.asList(arr));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
public void test(Integer[] arr) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
result.add(1);
|
||||
result.addAll(Arrays.asList(arr));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
class Person {}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
List<Person> names = new ArrayList<>();
|
||||
names.addAll(persons);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Replace iteration with bulk 'CrudRepository.save' call" "true"
|
||||
package org.springframework.data.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
interface CrudRepository<T,ID extends Serializable> {
|
||||
<S extends T> Iterable<S> save(Iterable<S> entities);
|
||||
<S extends T> S save(S entity);
|
||||
}
|
||||
|
||||
public class Main {
|
||||
public void test(CrudRepository<CharSequence, Integer> repo, Iterable<String> stringsToSave) {
|
||||
repo.save(stringsToSave);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// "Replace iteration with bulk 'CrudRepository.save' call" "true"
|
||||
package org.springframework.data.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
interface CrudRepository<T,ID extends Serializable> {
|
||||
<S extends T> Iterable<S> save(Iterable<S> entities);
|
||||
<S extends T> S save(S entity);
|
||||
}
|
||||
|
||||
public class Main {
|
||||
public void test(CrudRepository<Iterable<String>, Integer> repo, Iterable<List<String>> stringsToSave) {
|
||||
repo.save(stringsToSave);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Replace iteration with bulk 'List.removeAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
static class Person {}
|
||||
|
||||
void collectNames(List<Person> persons, Collection<Person> toRemove){
|
||||
persons.removeAll(toRemove);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Replace iteration with bulk 'List.removeAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
static class Person {}
|
||||
|
||||
void collectNames(List<Person> persons, Collection<Person> toRemove){
|
||||
persons.removeAll(toRemove);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
public void test(Integer[] arr) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
result.add(1);
|
||||
Arrays.stream(arr).forEach(result<caret>::add);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
class Person {}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
List<Person> names = new ArrayList<>();
|
||||
for(int i = 0; i<persons.size(); i = i + 1) {
|
||||
Person p = persons.get(i);
|
||||
names.<caret>add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "false"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
static class MyList extends AbstractCollection<String> {
|
||||
@Override
|
||||
public Iterator<String> iterator() {
|
||||
return Collections.emptyIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends String> c) {
|
||||
for (String e : c) {
|
||||
a<caret>dd(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
static class MyList extends AbstractCollection<String> {
|
||||
@Override
|
||||
public Iterator<String> iterator() {
|
||||
return Collections.emptyIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean myAdd(Collection<? extends String> c) {
|
||||
for (String e : c) {
|
||||
this.<caret>add(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "false"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
class Person {}
|
||||
|
||||
void collectNames(Iterable<Person> persons){
|
||||
List<Person> names = new ArrayList<>();
|
||||
persons.forEach(p -> {
|
||||
names<caret>.add(p);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
class Person {}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
List<Person> names = new ArrayList<>();
|
||||
persons.forEach(p -> {
|
||||
names<caret>.add(p);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class Sample {
|
||||
List<String> foo = new ArrayList<>();
|
||||
String foo(){
|
||||
Sample sm = new Sample();
|
||||
for (String s : foo) {
|
||||
<caret>sm.foo.add(s);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void test(Integer[] arr) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
result.add(1);
|
||||
for(Integer i : arr)
|
||||
result.<caret>add(i);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public void test(Integer[] arr) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
result.add(1);
|
||||
for (int idx = 0; idx < arr.length; idx++) {
|
||||
result.<caret>add(arr[idx]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
public void test(Integer[] arr) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
result.add(1);
|
||||
Stream.of(arr).forEachOrdered(<caret>result::add);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Replace iteration with bulk 'Collection.addAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
class Person {}
|
||||
|
||||
void collectNames(List<Person> persons){
|
||||
List<Person> names = new ArrayList<>();
|
||||
for (Person person : persons) {
|
||||
<caret>names.add(person);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Replace iteration with bulk 'CrudRepository.save' call" "true"
|
||||
package org.springframework.data.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
interface CrudRepository<T,ID extends Serializable> {
|
||||
<S extends T> Iterable<S> save(Iterable<S> entities);
|
||||
<S extends T> S save(S entity);
|
||||
}
|
||||
|
||||
public class Main {
|
||||
public void test(CrudRepository<CharSequence, Integer> repo, Iterable<String> stringsToSave) {
|
||||
stringsToSave.forEach(<caret>repo::save);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// "Replace iteration with bulk 'CrudRepository.save' call" "false"
|
||||
package org.springframework.data.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
interface CrudRepository<T,ID extends Serializable> {
|
||||
<S extends T> Iterable<S> save(Iterable<S> entities);
|
||||
<S extends T> S save(S entity);
|
||||
}
|
||||
|
||||
public class Main {
|
||||
public void test(CrudRepository<CharSequence, Integer> repo, Iterable<List<String>> stringsToSave) {
|
||||
stringsToSave.forEach(<caret>repo::save);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// "Replace iteration with bulk 'CrudRepository.save' call" "true"
|
||||
package org.springframework.data.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
interface CrudRepository<T,ID extends Serializable> {
|
||||
<S extends T> Iterable<S> save(Iterable<S> entities);
|
||||
<S extends T> S save(S entity);
|
||||
}
|
||||
|
||||
public class Main {
|
||||
public void test(CrudRepository<Iterable<String>, Integer> repo, Iterable<List<String>> stringsToSave) {
|
||||
stringsToSave.forEach(<caret>repo::save);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace iteration with bulk 'List.removeAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
static class Person {}
|
||||
|
||||
void collectNames(List<Person> persons, Collection<Person> toRemove){
|
||||
for (Iterator<Person> it = toRemove.iterator(); it.hasNext(); )
|
||||
persons<caret>.remove(it.next());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Replace iteration with bulk 'List.removeAll' call" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Collect {
|
||||
static class Person {}
|
||||
|
||||
void collectNames(List<Person> persons, Collection<Person> toRemove){
|
||||
Iterator<Person> it = toRemove.iterator();
|
||||
while (it.hasNext()) {
|
||||
Person person = it.next();
|
||||
persons<caret>.remove(person);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user