support min/max in stream api migration, rearrange tests

This commit is contained in:
Roman Ivanov
2017-08-02 12:57:45 +07:00
parent dd4ba58889
commit 72bab18a58
561 changed files with 2091 additions and 17 deletions
@@ -0,0 +1,34 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person work() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = personList.stream().filter(p -> p.getAge() > 13).max(Comparator.comparing(Person::getName)).orElse(null);
return maxPerson;
}
}
@@ -0,0 +1,41 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person work() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = null;
for <caret>(Person p : personList) {
if(p.getAge() > 13) {
if (maxPerson == null || p.getName().compareTo(maxPerson.getName()) < 0) {
maxPerson = p;
}
}
}
return maxPerson;
}
}
@@ -0,0 +1,36 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person work() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson;
Comparator<Person> personComparator = Comparator.comparingInt(Person::getAge);
maxPerson = personList.stream().filter(p -> p.getAge() > 13).max(personComparator).orElse(null);
return maxPerson;
}
}
@@ -0,0 +1,9 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
public void work(int[] ints) {
int max = Arrays.stream(ints).filter(anInt -> anInt < 10).filter(anInt -> anInt >= 0).max().orElse(0);
}
}
@@ -0,0 +1,9 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
public void work(int[] ints) {
int max = Arrays.stream(ints).max().orElse(Integer.MIN_VALUE);
}
}
@@ -0,0 +1,32 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person work() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = personList.stream().filter(p -> p.getAge() > 13).max(Comparator.comparingInt(Person::getAge)).orElse(null);
}
}
@@ -0,0 +1,34 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person max() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = personList.stream().filter(p -> p.getAge() > 13).max(Comparator.comparingInt(Person::getAge)).orElse(null);
return maxPerson;
}
}
@@ -0,0 +1,34 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person max() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = personList.stream().filter(p -> p.getAge() > 13).max(Comparator.comparingInt(Person::getAge)).orElse(null);
return maxPerson;
}
}
@@ -0,0 +1,34 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person max() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = personList.stream().filter(p -> p.getAge() > 13).max(Comparator.comparingInt(p -> p.age)).orElse(null);
return maxPerson;
}
}
@@ -0,0 +1,34 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person max() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = personList.stream().filter(p -> p.getAge() > 13).filter(p -> p.getAge() >= 0).max(Comparator.comparingInt(Person::getAge)).orElse(null);
return maxPerson;
}
}
@@ -0,0 +1,34 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person max() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = personList.stream().filter(p -> p.getAge() > 13).filter(p -> p.getAge() >= 0).max(Comparator.comparingInt(Person::getAge)).orElse(null);
return maxPerson;
}
}
@@ -0,0 +1,9 @@
// "Replace with max()" "true"
import java.util.*;
class Main {
public void work(long[] ints) {
long max = Arrays.stream(ints).filter(anInt -> anInt < 10).max().orElse(Long.MIN_VALUE);
}
}
@@ -0,0 +1,9 @@
// "Replace with min()" "true"
import java.util.*;
public class Main {
public void work(int[] ints) {
int min = Arrays.stream(ints).filter(anInt -> anInt < 10).filter(anInt -> anInt <= 0).min().orElse(0);
}
}
@@ -0,0 +1,9 @@
// "Replace with min()" "true"
import java.util.*;
public class Main {
public void work(Integer[] ints) {
int min = Arrays.stream(ints).filter(anInt -> anInt < 10).mapToInt(anInt -> anInt).filter(anInt -> anInt <= 0).min().orElse(0);
}
}
@@ -0,0 +1,9 @@
// "Replace with min()" "true"
import java.util.*;
public class Main {
public void work(int[] ints) {
int min = Arrays.stream(ints).filter(anInt -> anInt < 10).map(anInt -> anInt + 2343).filter(anInt -> anInt <= 0).min().orElse(0);
}
}
@@ -0,0 +1,9 @@
// "Replace with min()" "true"
import java.util.Arrays;
public class Main {
public void work(int[] ints) {
int min = Arrays.stream(ints).filter(anInt -> anInt < 10).map(anInt -> anInt + anInt * 2 - 10).filter(anInt -> anInt <= 0).min().orElse(0);
}
}
@@ -0,0 +1,34 @@
// "Replace with min()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person work() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person minPerson = personList.stream().filter(p -> p.getAge() > 13).min(Comparator.comparingInt(Person::getAge)).orElse(null);
return minPerson;
}
}
@@ -0,0 +1,33 @@
// "Replace with min()" "true"
import java.util.*;
class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person work() {
Person minPerson;
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
minPerson = personList.stream().filter(p -> p.getAge() > 13).min(Comparator.comparingInt(Person::getAge)).orElse(null);
}
}
@@ -0,0 +1,41 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person work() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = null;
for <caret>(Person p : personList) {
if(p.getAge() > 13) {
if (maxPerson == null || maxPerson.getName().compareTo(p.getName()) < 0) {
maxPerson = p;
}
}
}
return maxPerson;
}
}
@@ -0,0 +1,41 @@
// "Replace with max()" "false"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person work() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = null;
for <caret>(Person p : personList) {
if(p.getAge() > 13) {
if (maxPerson == null || p.getName().compareTo(maxPerson.getName()) < 0) {
maxPerson = p;
}
}
}
return maxPerson;
}
}
@@ -0,0 +1,42 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person work() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = null;
Comparator<Person> personComparator = Comparator.comparingInt(Person::getAge);
for<caret>(Person p : personList) {
if(p.getAge() > 13) {
if (maxPerson == null || personComparator.compare(maxPerson, p) < 0) {
maxPerson = p;
}
}
}
return maxPerson;
}
}
@@ -0,0 +1,16 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
public void work(int[] ints) {
int max = 0;
for <caret> (int anInt : ints) {
if(anInt < 10) {
if(max < anInt) {
max = anInt;
}
}
}
}
}
@@ -0,0 +1,13 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
public void work(int[] ints) {
int max = Integer.MIN_VALUE;
for<caret> (int i : ints) {
if(i < max) continue;
max = i;
}
}
}
@@ -0,0 +1,17 @@
// "Replace with max()" "false"
import java.util.*;
public class Main {
public void max(int[] ints) {
int another;
int max = 0;
for <caret> (int anInt : ints) {
if(anInt < 10) {
if(max < another) {
max = anInt;
}
}
}
}
}
@@ -0,0 +1,17 @@
// "Replace with max()" "false"
import java.util.*;
public class Main {
public void max(int[] ints) {
int another = 1;
int max = 0;
for <caret> (int anInt : ints) {
if(anInt < 10) {
if(max < another) {
max = another;
}
}
}
}
}
@@ -0,0 +1,39 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person work() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = null;
for <caret>(Person p : personList) {
if(p.getAge() > 13) {
if (maxPerson == null || maxPerson.getAge() < p.getAge()) {
maxPerson = p;
}
}
}
}
}
@@ -0,0 +1,44 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person max() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = null;
for <caret>(Person p : personList) {
if(p.getAge() > 13) {
if (maxPerson == null) {
maxPerson = p;
}
else if (maxPerson.getAge() < p.getAge()) {
maxPerson = p;
}
}
}
return maxPerson;
}
}
@@ -0,0 +1,41 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person max() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = null;
for <caret>(Person p : personList) {
if(p.getAge() > 13) {
if (maxPerson == null || p.getAge() > maxPerson.getAge()) {
maxPerson = p;
}
}
}
return maxPerson;
}
}
@@ -0,0 +1,41 @@
// "Replace with max()" "false"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person max() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = null;
for <caret>(Person p : personList) {
if(p.getAge() > 13) {
if (p.getAge() > maxPerson.getAge() || maxPerson == null) {
maxPerson = p;
}
}
}
return maxPerson;
}
}
@@ -0,0 +1,41 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person max() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = null;
for <caret>(Person p : personList) {
if(p.getAge() > 13) {
if (maxPerson == null || p.age > maxPerson.age) {
maxPerson = p;
}
}
}
return maxPerson;
}
}
@@ -0,0 +1,41 @@
// "Replace with max()" "false"
import java.util.*;
public class Main {
static class Person {
String name;
short age;
public String getName() {
return name;
}
public short getAge() {
return age;
}
public Person(String name, short age) {
this.name = name;
this.age = age;
}
}
public Person max() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = null;
for <caret>(Person p : personList) {
if(p.getAge() > 13) {
if (p.getAge() > maxPerson.getAge() || maxPerson == null) {
maxPerson = p;
}
}
}
return maxPerson;
}
}
@@ -0,0 +1,43 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person max() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = null;
int maxAge = 0;
for <caret>(Person p : personList) {
if(p.getAge() > 13) {
if (maxPerson == null || maxAge < p.getAge()) {
maxAge = p.getAge()
maxPerson = p;
}
}
}
return maxPerson;
}
}
@@ -0,0 +1,43 @@
// "Replace with max()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person max() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person maxPerson = null;
int maxAge = 0;
for <caret>(Person p : personList) {
if(p.getAge() > 13) {
if (((maxPerson) == null) || ((maxAge < p.getAge()))) {
maxAge = (p.getAge());
maxPerson = (p);
}
}
}
return maxPerson;
}
}
@@ -0,0 +1,16 @@
// "Replace with max()" "true"
import java.util.*;
class Main {
public void work(long[] ints) {
long max = Long.MIN_VALUE;
for <caret>(long anInt : ints) {
if(anInt < 10) {
if(max < anInt) {
max = anInt;
}
}
}
}
}
@@ -0,0 +1,16 @@
// "Replace with min()" "true"
import java.util.*;
public class Main {
public void work(int[] ints) {
int min = 0;
for <caret> (int anInt : ints) {
if(anInt < 10) {
if(min > anInt) {
min = anInt;
}
}
}
}
}
@@ -0,0 +1,16 @@
// "Replace with min()" "true"
import java.util.*;
public class Main {
public void work(Integer[] ints) {
int min = 0;
for <caret> (Integer anInt : ints) {
if(anInt < 10) {
if(min > anInt) {
min = anInt;
}
}
}
}
}
@@ -0,0 +1,16 @@
// "Replace with min()" "true"
import java.util.*;
public class Main {
public void work(int[] ints) {
int min = 0;
for <caret> (int anInt : ints) {
if(anInt < 10) {
if(min > anInt + 2343) {
min = anInt + 2343;
}
}
}
}
}
@@ -0,0 +1,14 @@
// "Replace with min()" "true"
public class Main {
public void work(int[] ints) {
int min = 0;
for <caret> ( int anInt :ints){
if (anInt < 10) {
if (min > anInt + anInt * 2 - 10) {
min = anInt + anInt * 2 - 10;
}
}
}
}
}
@@ -0,0 +1,41 @@
// "Replace with min()" "true"
import java.util.*;
public class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person work() {
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
Person minPerson = null;
for <caret>(Person p : personList) {
if(p.getAge() > 13) {
if (minPerson == null || minPerson.getAge() > p.getAge()) {
minPerson = p;
}
}
}
return minPerson;
}
}
@@ -0,0 +1,39 @@
// "Replace with min()" "true"
import java.util.*;
class Main {
static class Person {
String name;
int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
public Person(String name, int age) {
this.name = name;
this.age = age;
}
}
public Person work() {
Person minPerson = null;
List<Person> personList = Arrays.asList(
new Person("Roman", 21),
new Person("James", 25),
new Person("Kelly", 12)
);
for <caret>(Person p : personList) {
if(p.getAge() > 13) {
if (minPerson == null || minPerson.getAge() > p.getAge()) {
minPerson = p;
}
}
}
}
}