IDEA-166896 Simplify stream chain in case of *match used with Boolean::booleanValue

This commit is contained in:
Tagir Valeev
2017-01-23 17:21:44 +07:00
parent ec72347510
commit 5cdeace236
18 changed files with 273 additions and 0 deletions
@@ -0,0 +1,10 @@
// "Merge with previous 'map' call" "true"
import java.util.List;
import java.util.function.Function;
public class Test {
public <T extends Boolean> boolean test(List<String> list, Function<String, T> fn) {
return list.stream().allMatch(fn::apply);
}
}
@@ -0,0 +1,10 @@
// "Merge with previous 'map' call" "true"
import java.util.List;
import java.util.function.Function;
public class Test {
public <T extends Boolean> boolean test(List<String> list, Function<String, T> fn, Function<String, Boolean> fn2, boolean b, boolean b2) {
return list.stream().allMatch((b ? fn : b2 ? fn2 : fn)::apply);
}
}
@@ -0,0 +1,10 @@
// "Merge with previous 'map' call" "true"
import java.util.List;
import java.util.function.Function;
public class Test {
public <T extends Boolean> boolean test(List<String> list, Function<String, T> fn, Function<String, Boolean> fn2, boolean b) {
return list.stream().allMatch((b ? fn : fn2)::apply);
}
}
@@ -0,0 +1,10 @@
// "Merge with previous 'map' call" "true"
import java.util.List;
import java.util.function.Function;
public class Test {
public <T extends Boolean> boolean test(List<String> list, boolean b, boolean b2) {
return list.stream().allMatch(b ? String::isEmpty : b2 ? "foo"::equals : "bar"::equals);
}
}
@@ -0,0 +1,9 @@
// "Merge with previous 'map' call" "true"
import java.util.List;
public class Test {
public boolean test(List<String> list) {
return list.stream().allMatch(String::isEmpty);
}
}
@@ -0,0 +1,10 @@
// "Merge with previous 'map' call" "true"
import java.util.List;
public class Test {
public boolean test(List<String> list) {
/* ditto boolean!*/
return list.stream().anyMatch(String::isEmpty);
}
}
@@ -0,0 +1,9 @@
// "Merge with previous 'map' call" "true"
import java.util.List;
public class Test {
public boolean test(List<String> list) {
return list.stream().noneMatch(String::isEmpty);
}
}
@@ -0,0 +1,10 @@
// "Merge with previous 'map' call" "true"
import java.util.List;
import java.util.function.Function;
public class Test {
public <T extends Boolean> boolean test(List<String> list, Function<String, T> fn) {
return list.stream().map(fn).all<caret>Match(Boolean::booleanValue);
}
}
@@ -0,0 +1,16 @@
// "Merge with previous 'map' call" "false"
import java.util.List;
import java.util.function.Function;
public class Test {
interface MyFunction extends Function<Object, Boolean> {};
MyFunction fn3 = "xyz"::equals;
public <T extends Boolean> boolean test(List<String> list, Function<String, T> fn, Function<String, Boolean> fn2, boolean b, boolean b2) {
// neither "b ? fn : b2 ? fn2 : fn3" nor "(b ? fn : b2 ? fn2 : fn3)::apply" can serve as predicate
// all possible replacements are longer
return list.stream().map(b ? fn : b2 ? fn2 : fn3).all<caret>Match(Boolean::booleanValue);
}
}
@@ -0,0 +1,10 @@
// "Merge with previous 'map' call" "true"
import java.util.List;
import java.util.function.Function;
public class Test {
public <T extends Boolean> boolean test(List<String> list, Function<String, T> fn, Function<String, Boolean> fn2, boolean b, boolean b2) {
return list.stream().map(b ? fn : b2 ? fn2 : fn).allM<caret>atch(Boolean::booleanValue);
}
}
@@ -0,0 +1,10 @@
// "Merge with previous 'map' call" "true"
import java.util.List;
import java.util.function.Function;
public class Test {
public <T extends Boolean> boolean test(List<String> list, Function<String, T> fn, Function<String, Boolean> fn2, boolean b) {
return list.stream().map(b ? fn : fn2).all<caret>Match(Boolean::booleanValue);
}
}
@@ -0,0 +1,12 @@
// "Merge with previous 'map' call" "false"
import java.util.List;
import java.util.function.Function;
public class Test {
public <T extends Boolean> boolean test(List<String> list, Function<String, T> fn, boolean b) {
// neither "b ? String::isEmpty : fn" nor "(b ? String::isEmpty : fn)::apply" can serve as predicate
// all possible replacements are longer
return list.stream().map(b ? String::isEmpty : fn).all<caret>Match(Boolean::booleanValue);
}
}
@@ -0,0 +1,10 @@
// "Merge with previous 'map' call" "true"
import java.util.List;
import java.util.function.Function;
public class Test {
public <T extends Boolean> boolean test(List<String> list, boolean b, boolean b2) {
return list.stream().map(b ? String::isEmpty : b2 ? "foo"::equals : "bar"::equals).allM<caret>atch(Boolean::booleanValue);
}
}
@@ -0,0 +1,11 @@
// "Merge with previous 'map' call" "true"
import java.util.List;
public class Test {
public boolean test(List<String> list) {
return list.stream().map(String::isEmpty).allMa<caret>tch(b -> {
return Boolean.valueOf(b);
});
}
}
@@ -0,0 +1,9 @@
// "Merge with previous 'map' call" "true"
import java.util.List;
public class Test {
public boolean test(List<String> list) {
return list.stream().map(String::isEmpty).a<caret>nyMatch(/* ditto boolean!*/Boolean::booleanValue);
}
}
@@ -0,0 +1,9 @@
// "Merge with previous 'map' call" "true"
import java.util.List;
public class Test {
public boolean test(List<String> list) {
return list.stream().map(String::isEmpty).none<caret>Match(b -> b);
}
}