add support for binary operation reduction in stream migration

This commit is contained in:
Roman Ivanov
2017-07-20 17:15:07 +07:00
parent 5ce1ab82c5
commit dd4ba58889
39 changed files with 762 additions and 121 deletions
@@ -0,0 +1,11 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testBitwiseAnd() {
int[] arr = new int[]{1, 2, 3, 4};
int acc = 12443;
acc &= Arrays.stream(arr).reduce(-1, (a, b) -> a & b);
}
}
@@ -0,0 +1,10 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testBitwiseAndHighestBit() {
int[] arr = {0x80000000, 0xffffffff};
int acc = Arrays.stream(arr).reduce(-1, (a, b) -> a & b);
}
}
@@ -0,0 +1,10 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testBitwiseAndReplacingInitializer() {
int[] arr = new int[]{1, 2, 3, 4};
int acc = Arrays.stream(arr).reduce(0xFFFFFFFF, (a, b) -> a & b);
}
}
@@ -0,0 +1,10 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testBitwiseAndReplacingInitializer() {
int[] arr = new int[]{1, 2, 3, 4};
int acc = Arrays.stream(arr).reduce(-1, (a, b) -> a & b);
}
}
@@ -0,0 +1,10 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testBitwiseAndReplacingLongInitializer() {
long[] arr = new long[]{1, 2, 3, 4};
long acc = Arrays.stream(arr).reduce(-1l, (a, b) -> a & b);
}
}
@@ -0,0 +1,10 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testConjunction() {
List<Boolean> booleans = new ArrayList<>();
boolean acc = booleans.stream().reduce(true, (a, b) -> a && b);
}
}
@@ -0,0 +1,10 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testConjunctionBoxed() {
List<Boolean> booleans = new ArrayList<>();
Boolean acc = booleans.stream().reduce(true, (a, b) -> a && b);
}
}
@@ -0,0 +1,10 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testDisjunction() {
List<Boolean> booleans = new ArrayList<>();
boolean acc = booleans.stream().reduce(false, (a, b) -> a || b);
}
}
@@ -0,0 +1,10 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testMultiply() {
int[] arr = new int[]{1, 2, 3, 4};
int acc = Arrays.stream(arr).reduce(1, (a, b) -> a * b);
}
}
@@ -0,0 +1,12 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testMultiplyWithComplexInitializer() {
int[] arr = new int[]{1, 2, 3, 4};
int x = 10;
int acc = 12 + x;
acc *= Arrays.stream(arr).reduce(1, (a, b) -> a * b);
}
}
@@ -0,0 +1,13 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testMultiplyWithConflictingNamesInScope() {
int a = 1;
int b = 2;
int b1 = 3;
int[] arr = new int[]{1, 2, 3, 4};
int acc = Arrays.stream(arr).reduce(1, (a1, b2) -> a1 * b2);
}
}
@@ -0,0 +1,11 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testMultiplyWithNarrowingTypeInitializer() {
int[] arr = new int[]{1, 2, 3, 4};
short acc = (byte) 12;
acc *= Arrays.stream(arr).map(i -> (short) i).reduce(1, (a, b) -> a * b);
}
}
@@ -0,0 +1,11 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testMultiplyWithNotOneInitializerConstant() {
int[] arr = new int[]{1, 2, 3, 4};
int acc = 12;
acc *= Arrays.stream(arr).reduce(1, (a, b) -> a * b);
}
}
@@ -0,0 +1,10 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testMultiplyWithMapping() {
int[] arr = new int[]{1, 2, 3, 4};
int acc = Arrays.stream(arr).map(i -> i + 2).reduce(1, (a, b) -> a * b);
}
}
@@ -0,0 +1,11 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testBitwiseOr() {
int[] arr = new int[]{1, 2, 3, 4};
int acc = 12443;
acc |= Arrays.stream(arr).reduce(0, (a, b) -> a | b);
}
}
@@ -0,0 +1,11 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testBitwiseXor() {
int[] arr = new int[]{1, 2, 3, 4};
int acc = 12443;
acc ^= Arrays.stream(arr).reduce(0, (a, b) -> a ^ b);
}
}
@@ -0,0 +1,11 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testBitwiseXorLong() {
int[] arr = new int[]{1, 2, 3, 4};
long acc = 12443;
acc ^= Arrays.stream(arr).asLongStream().reduce(0, (a, b) -> a ^ b);
}
}
@@ -0,0 +1,13 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testBitwiseAnd() {
int[] arr = new int[]{1, 2, 3, 4};
int acc = 12443;
for <caret> (int i: arr) {
acc &= i;
}
}
}
@@ -0,0 +1,13 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testBitwiseAndHighestBit() {
int[] arr = {0x80000000, 0xffffffff};
int acc = -1;
for <caret> (int i: arr) {
acc &= i;
}
}
}
@@ -0,0 +1,13 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testBitwiseAndReplacingInitializer() {
int[] arr = new int[]{1, 2, 3, 4};
int acc = 0xFFFFFFFF;
for <caret> (int i: arr) {
acc &= i;
}
}
}
@@ -0,0 +1,13 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testBitwiseAndReplacingInitializer() {
int[] arr = new int[]{1, 2, 3, 4};
int acc = -1;
for <caret> (int i: arr) {
acc &= i;
}
}
}
@@ -0,0 +1,13 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testBitwiseAndReplacingLongInitializer() {
long[] arr = new long[]{1, 2, 3, 4};
long acc = -1l;
for <caret> (long i: arr) {
acc &= i;
}
}
}
@@ -0,0 +1,13 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testConjunction() {
List<Boolean> booleans = new ArrayList<>();
boolean acc = true;
for <caret> (Boolean bool : booleans) {
acc &= bool;
}
}
}
@@ -0,0 +1,13 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testConjunctionBoxed() {
List<Boolean> booleans = new ArrayList<>();
Boolean acc = true;
for <caret> (Boolean bool : booleans) {
acc &= bool;
}
}
}
@@ -0,0 +1,13 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testDisjunction() {
List<Boolean> booleans = new ArrayList<>();
boolean acc = false;
for <caret> (Boolean bool : booleans) {
acc |= bool;
}
}
}
@@ -0,0 +1,13 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testMultiply() {
int[] arr = new int[]{1, 2, 3, 4};
int acc = 1;
for <caret> (int i : arr) {
acc *= i;
}
}
}
@@ -0,0 +1,14 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testMultiplyWithComplexInitializer() {
int[] arr = new int[]{1, 2, 3, 4};
int x = 10;
int acc = 12 + x;
for <caret> (int i : arr) {
acc *= i;
}
}
}
@@ -0,0 +1,16 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testMultiplyWithConflictingNamesInScope() {
int a = 1;
int b = 2;
int b1 = 3;
int[] arr = new int[]{1, 2, 3, 4};
int acc = 1;
for <caret> (int i : arr) {
acc *= i;
}
}
}
@@ -0,0 +1,13 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testMultiplyWithNarrowingTypeInitializer() {
int[] arr = new int[]{1, 2, 3, 4};
short acc = (byte) 12;
for <caret> (int i : arr) {
acc *= i;
}
}
}
@@ -0,0 +1,13 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testMultiplyWithNotOneInitializerConstant() {
int[] arr = new int[]{1, 2, 3, 4};
int acc = 12;
for <caret> (int i : arr) {
acc *= i;
}
}
}
@@ -0,0 +1,13 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testMultiplyWithMapping() {
int[] arr = new int[]{1, 2, 3, 4};
int acc = 1;
for <caret> (int i : arr) {
acc *= i + 2;
}
}
}
@@ -0,0 +1,13 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testBitwiseOr() {
int[] arr = new int[]{1, 2, 3, 4};
int acc = 12443;
for <caret> (int i: arr) {
acc |= i;
}
}
}
@@ -0,0 +1,13 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testBitwiseXor() {
int[] arr = new int[]{1, 2, 3, 4};
int acc = 12443;
for <caret> (int i: arr) {
acc ^= i;
}
}
}
@@ -0,0 +1,13 @@
// "Replace with reduce()" "true"
import java.util.*;
public class Main {
public void testBitwiseXorLong() {
int[] arr = new int[]{1, 2, 3, 4};
long acc = 12443;
for <caret> (int i: arr) {
acc ^= i;
}
}
}