mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 03:13:40 +07:00
add support for binary operation reduction in stream migration
This commit is contained in:
+11
@@ -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);
|
||||
}
|
||||
}
|
||||
+10
@@ -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);
|
||||
}
|
||||
}
|
||||
+10
@@ -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);
|
||||
}
|
||||
}
|
||||
+10
@@ -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);
|
||||
}
|
||||
}
|
||||
+10
@@ -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);
|
||||
}
|
||||
}
|
||||
+10
@@ -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);
|
||||
}
|
||||
}
|
||||
+10
@@ -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);
|
||||
}
|
||||
}
|
||||
+10
@@ -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);
|
||||
}
|
||||
}
|
||||
+10
@@ -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);
|
||||
}
|
||||
}
|
||||
+12
@@ -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);
|
||||
}
|
||||
}
|
||||
+13
@@ -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);
|
||||
}
|
||||
}
|
||||
+11
@@ -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);
|
||||
}
|
||||
}
|
||||
+11
@@ -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);
|
||||
}
|
||||
}
|
||||
+10
@@ -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);
|
||||
}
|
||||
}
|
||||
+11
@@ -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);
|
||||
}
|
||||
}
|
||||
+11
@@ -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);
|
||||
}
|
||||
}
|
||||
+11
@@ -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);
|
||||
}
|
||||
}
|
||||
+13
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+16
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user