StreamAPI migration: limited sorting support

This commit is contained in:
Tagir Valeev
2016-10-04 15:55:00 +07:00
parent 73849b0d19
commit a53a0f3d61
6 changed files with 102 additions and 0 deletions
@@ -0,0 +1,15 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Collect {
class Person {
String getName() {
return "";
}
}
void collectNames(List<Person> persons){
List<String> names = persons.stream().map(Person::getName).sorted(Comparator.comparing(Person::getName)).collect(Collectors.toList());
}
}
@@ -0,0 +1,10 @@
// "Replace with collect" "true"
import java.util.*;
import java.util.stream.Collectors;
public class Collect {
void collectNames(List<String> persons){
List<String> names = persons.stream().map(String::toLowerCase).sorted().collect(Collectors.toList());
// sort
}
}
@@ -0,0 +1,18 @@
// "Replace with collect" "true"
import java.util.*;
public class Collect {
class Person {
String getName() {
return "";
}
}
void collectNames(List<Person> persons){
List<String> names = new ArrayList<>();
for (Person person : pers<caret>ons) {
names.add(person.getName());
}
Collections.sort(names, Comparator.comparing(Person::getName));
}
}
@@ -0,0 +1,13 @@
// "Replace with collect" "true"
import java.util.*;
public class Collect {
void collectNames(List<String> persons){
List<String> names = new ArrayList<>();
for (String person : pers<caret>ons) {
names.add(person.toLowerCase());
}
// sort
Collections.sort(names);
}
}