mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-09 20:42:52 +07:00
StreamToLoop tests grouped
This commit is contained in:
+49
@@ -0,0 +1,49 @@
|
||||
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
|
||||
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.stream.*;
|
||||
|
||||
public class Main {
|
||||
private static OptionalDouble testDouble(long... numbers) {
|
||||
double sum = 0;
|
||||
long count = 0;
|
||||
for (long x : numbers) {
|
||||
if (x > 0) {
|
||||
double v = x;
|
||||
sum += v;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count > 0 ? OptionalDouble.of(sum / count) : OptionalDouble.empty();
|
||||
}
|
||||
|
||||
private static OptionalDouble testInt(int... numbers) {
|
||||
long sum = 0;
|
||||
long count = 0;
|
||||
for (int x : numbers) {
|
||||
if (x > 0) {
|
||||
sum += x;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count > 0 ? OptionalDouble.of((double) sum / count) : OptionalDouble.empty();
|
||||
}
|
||||
|
||||
private static OptionalDouble testLong(long... numbers) {
|
||||
long sum = 0;
|
||||
long count = 0;
|
||||
for (long x : numbers) {
|
||||
if (x > 0) {
|
||||
sum += x;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count > 0 ? OptionalDouble.of((double) sum / count) : OptionalDouble.empty();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(testDouble(-1,-2,-3, Long.MAX_VALUE, Long.MAX_VALUE));
|
||||
System.out.println(testInt(-1,-2,-3));
|
||||
System.out.println(testLong(-1,-2,-3, Long.MAX_VALUE, Long.MAX_VALUE));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user