ExtractStreamMapAction: made stream-agnostic (with ability to extend to other chaining lambda APIs like Guava, RxJava, etc.); implemented for CompletableFuture; existing lambda is always preserved now.

This commit is contained in:
Tagir Valeev
2017-03-06 15:32:16 +07:00
parent bd3c0ddfba
commit 504a5727d6
43 changed files with 444 additions and 232 deletions
@@ -1,10 +1,10 @@
// "Extract variable 'lowerCase' to separate stream step" "true"
// "Extract variable 'lowerCase' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
public class Test {
boolean test(List<String> list) {
return list.stream().map(String::toLowerCase)
.anyMatch(lowerCase -> "test".equals(lowerCase));
.anyMatch(lowerCase -> "test".equals(lowerCase));
}
}
@@ -1,4 +1,4 @@
// "Extract variable 'arr' to separate stream step" "true"
// "Extract variable 'arr' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
@@ -1,9 +1,9 @@
// "Extract variable 'l' to separate stream step" "true"
// "Extract variable 'l' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
public class Test {
long[] testAsLongStream(int[] x) {
return Arrays.stream(x).map(i -> i * 2).asLongStream().toArray();
return Arrays.stream(x).map(i -> i * 2).mapToLong(l -> l).toArray();
}
}
@@ -1,9 +1,9 @@
// "Extract variable 'l' to separate stream step" "true"
// "Extract variable 'l' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
public class Test {
Object[] testBoxed(int[] x) {
return Arrays.stream(x).asLongStream().boxed().toArray();
return Arrays.stream(x).asLongStream().mapToObj(l -> l).toArray();
}
}
@@ -1,9 +1,9 @@
// "Extract variable 'y' to separate stream step" "true"
// "Extract variable 'y' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
public class Test {
void testFlatMap() {
Stream.of("xyz").mapToInt(String::length).flatMap(y -> IntStream.range(0, y)).forEach(System.out::println);
Stream.of("xyz").mapToInt(String::length).flatMap(y -> IntStream.range(0, y)).forEach(System.out::println);
}
}
@@ -1,9 +1,9 @@
// "Extract variable 'y' to separate stream step" "true"
// "Extract variable 'y' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
public class Test {
void testFlatMap() {
Stream.of("xyz").map(String::length).flatMapToInt(y -> IntStream.range(0, y)).forEach(System.out::println);
Stream.of("xyz").map(String::length).flatMapToInt(y -> IntStream.range(0, y)).forEach(System.out::println);
}
}
@@ -1,9 +1,9 @@
// "Extract variable 's' to separate stream step" "true"
// "Extract variable 's' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
public class Test {
void testFlatMap() {
IntStream.of(1, 2, 3).mapToObj(String::valueOf).flatMapToInt(s -> IntStream.range(0, s.length())).forEach(System.out::println);
IntStream.of(1, 2, 3).mapToObj(String::valueOf).flatMapToInt(s -> IntStream.range(0, s.length())).forEach(System.out::println);
}
}
@@ -1,9 +1,9 @@
// "Extract variable 'i' to separate stream step" "true"
// "Extract variable 'i' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
public class Test {
void test2(List<String> list) {
list.stream().mapToInt(String::length).forEach(i -> System.out.println(i));
list.stream().mapToInt(String::length).forEach(i -> System.out.println(i));
}
}
@@ -1,10 +1,10 @@
// "Extract variable 'fn' to separate stream step" "true"
// "Extract variable 'fn' to separate mapping method" "true"
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Test {
void testFunction() {
Stream.of("a", "b", "c").<Supplier<String>>map(x -> x::trim).map(fn -> fn.get()).forEach(System.out::println);
Stream.of("a", "b", "c").<Supplier<String>>map(x -> x::trim).map(fn -> fn.get()).forEach(System.out::println);
}
}
@@ -1,9 +1,9 @@
// "Extract variable 'set' to separate stream step" "true"
// "Extract variable 'set' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
public class Test {
void testMap(List<Map<String, String>> list) {
list.stream().map(Map::keySet).flatMap(set -> set.stream()).forEach(System.out::println);
list.stream().map(Map::keySet).flatMap(set -> set.stream()).forEach(System.out::println);
}
}
@@ -1,9 +1,9 @@
// "Extract variable 'y' to separate stream step" "true"
// "Extract variable 'y' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
public class Test {
void testRemoveMap() {
Stream.of("xyz").map(x -> x + x).forEach(System.out::println);
Stream.of("xyz").map(x -> x + x).map(y -> y).forEach(System.out::println);
}
}
@@ -1,4 +1,4 @@
// "Extract variable 'l' to separate stream step" "true"
// "Extract variable 'l' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
@@ -0,0 +1,10 @@
// "Extract variable 'lc' to separate mapping method" "true"
import java.util.concurrent.CompletableFuture;
public class Test {
public static void main(String[] args) {
CompletableFuture.completedFuture(" XYZ ")
.thenApply(x -> x.trim() + "|" + x.trim()).thenApply(String::toLowerCase)
.thenAccept(lc -> System.out.println(lc));
}
}
@@ -1,4 +1,4 @@
// "Extract variable 'lowerCase' to separate stream step" "true"
// "Extract variable 'lowerCase' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
@@ -1,4 +1,4 @@
// "Extract variable 'lowerCase' to separate stream step" "false"
// "Extract variable 'lowerCase' to separate mapping method" "false"
import java.util.*;
import java.util.stream.*;
@@ -1,4 +1,4 @@
// "Extract variable 'arr' to separate stream step" "true"
// "Extract variable 'arr' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
@@ -1,4 +1,4 @@
// "Extract variable 'l' to separate stream step" "true"
// "Extract variable 'l' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
@@ -1,4 +1,4 @@
// "Extract variable 'l' to separate stream step" "true"
// "Extract variable 'l' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
@@ -1,4 +1,4 @@
// "Extract variable 'y' to separate stream step" "true"
// "Extract variable 'y' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
@@ -1,4 +1,4 @@
// "Extract variable 'y' to separate stream step" "false"
// "Extract variable 'y' to separate mapping method" "false"
import java.util.*;
import java.util.stream.*;
@@ -1,4 +1,4 @@
// "Extract variable 'y' to separate stream step" "true"
// "Extract variable 'y' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
@@ -1,4 +1,4 @@
// "Extract variable 's' to separate stream step" "true"
// "Extract variable 's' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
@@ -1,4 +1,4 @@
// "Extract variable 'i' to separate stream step" "true"
// "Extract variable 'i' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
@@ -1,4 +1,4 @@
// "Extract variable 'i' to separate stream step" "false"
// "Extract variable 'i' to separate mapping method" "false"
import java.util.*;
import java.util.stream.*;
@@ -1,4 +1,4 @@
// "Extract variable 'fn' to separate stream step" "true"
// "Extract variable 'fn' to separate mapping method" "true"
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
@@ -1,4 +1,4 @@
// "Extract variable 'set' to separate stream step" "true"
// "Extract variable 'set' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
@@ -1,4 +1,4 @@
// "Extract variable 'y' to separate stream step" "true"
// "Extract variable 'y' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
@@ -1,4 +1,4 @@
// "Extract variable 'l' to separate stream step" "true"
// "Extract variable 'l' to separate mapping method" "true"
import java.util.*;
import java.util.stream.*;
@@ -0,0 +1,13 @@
// "Extract variable 'lc' to separate mapping method" "true"
import java.util.concurrent.CompletableFuture;
public class Test {
public static void main(String[] args) {
CompletableFuture.completedFuture(" XYZ ")
.thenApply(x -> x.trim()+"|"+x.trim())
.thenAccept(s -> {
String <caret>lc = s.toLowerCase();
System.out.println(lc);
});
}
}