IDEA-162875 Stream API migration: support conversion to BufferedReader.lines()

This commit is contained in:
Tagir Valeev
2016-10-21 12:10:10 +07:00
parent bc8f03f8ff
commit 8c6088647b
14 changed files with 328 additions and 54 deletions
@@ -0,0 +1,15 @@
// "Replace with collect" "true"
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
List<String> test(BufferedReader br) throws IOException {
List<String> result;
result = br.lines().map(String::trim).collect(Collectors.toList());
return result;
}
}
@@ -0,0 +1,19 @@
// "Replace with collect" "true"
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class Main {
List<String> test(List<BufferedReader> readers) throws IOException {
for(BufferedReader br : readers) {
List<String> result;
result = br.lines().map(String::trim).collect(Collectors.toList());
if(result.size() > 10) {
return result;
}
}
}
}
@@ -0,0 +1,11 @@
// "Replace with sum()" "true"
import java.io.BufferedReader;
import java.io.IOException;
public class Main {
void test(BufferedReader br) throws IOException {
long count = br.lines().map(String::trim).mapToLong(String::length).sum();
System.out.println(count);
}
}
@@ -0,0 +1,17 @@
// "Replace with collect" "true"
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Main {
List<String> test(BufferedReader br) throws IOException {
List<String> result = new ArrayList<>();
String line = "";
wh<caret>ile(null != (line = br.readLine())) {
result.add(line.trim());
}
return result;
}
}
@@ -0,0 +1,19 @@
// "Replace with collect" "false"
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Main {
List<String> test(List<BufferedReader> readers) throws IOException {
List<String> result = new ArrayList<>();
for(BufferedReader br : readers) {
String line = "";
wh<caret>ile (null != (line = br.readLine())) {
result.add(line.trim());
}
}
return result;
}
}
@@ -0,0 +1,21 @@
// "Replace with collect" "true"
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Main {
List<String> test(List<BufferedReader> readers) throws IOException {
for(BufferedReader br : readers) {
List<String> result = new ArrayList<>();
String line = "";
wh<caret>ile (null != (line = br.readLine())) {
result.add(line.trim());
}
if(result.size() > 10) {
return result;
}
}
}
}
@@ -0,0 +1,16 @@
// "Replace with sum()" "false"
import java.io.BufferedReader;
import java.io.IOException;
public class Main {
void test(BufferedReader br) throws IOException {
String line = "";
long count = 0;
wh<caret>ile((line = br.readLine()) != null) {
line = line.trim();
count+=line.length();
}
System.out.println(count);
}
}
@@ -0,0 +1,16 @@
// "Replace with sum()" "true"
import java.io.BufferedReader;
import java.io.IOException;
public class Main {
void test(BufferedReader br) throws IOException {
String line = "";
long count = 0;
wh<caret>ile((line = br.readLine()) != null) {
String trimmed = line.trim();
count+=trimmed.length();
}
System.out.println(count);
}
}
@@ -0,0 +1,16 @@
// "Replace with sum()" "false"
import java.io.BufferedReader;
import java.io.IOException;
public class Main {
void test(BufferedReader br) throws IOException {
String line = "";
long count = 0;
wh<caret>ile((line = br.readLine()) != null) {
String trimmed = line.trim();
count+=trimmed.length();
}
System.out.println(count+":"+line);
}
}