testdata IDEA-131282

This commit is contained in:
Anna Kozlova
2015-11-20 18:56:11 +01:00
parent 31aeea2a1f
commit 6bec6fdf0f
3 changed files with 132 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collector;
import java.util.stream.Collectors;
class Reducer {
private final Map<String, Dto> dtos = new HashMap<>();
private void publishToOpxl() {
Collector<Intermediate, ?, Map<String, Integer>> reducer =
Collectors.groupingBy(Intermediate::name, Collectors.summingInt(Intermediate::value));
Map<String, Map<String,Integer>> green = dtos.values()
.stream()
.flatMap(dto -> dto.getNestedThings()
.values()
.stream()
.map(ppd -> new Intermediate(dto.getName(),
ppd.getKey(),
ppd.getValue())))
.collect(
Collectors.groupingBy(
Intermediate::key,
reducer
));
Map<String, Map<String,Integer>> red = dtos.values()
.stream()
.flatMap(dto -> dto.getNestedThings()
.values()
.stream()
.map(ppd -> new Intermediate(dto.getName(),
ppd.getKey(),
ppd.getValue())))
.collect(
Collectors.groupingBy(
Intermediate::key,
Collectors.groupingBy(Intermediate::name, Collectors.summingInt(Intermediate::value))
));
}
public static class Intermediate {
public final String name;
public final String key;
public final int value;
public Intermediate(String name, String key, int value) {
this.name = name;
this.key = key;
this.value = value;
}
public String name() {
return name;
}
public String key() {
return key;
}
public int value() {
return value;
}
}
}
interface Dto {
String getName();
Map<String, Dto2> getNestedThings();
}
interface Dto2 {
String getKey();
int getValue();
}

View File

@@ -0,0 +1,45 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
class MyTest {
public static void main(String[] args) {
List<Test> data = new ArrayList<>();
Map<String, Map<String, Integer>> result = data.stream().collect(
Collectors.groupingBy(
Test::getName,
Collectors.groupingBy(
Test::getMonth,
Collectors.summingInt(Test::getAmount))
)
);
}
private static class Test{
private String name;
private String month;
private int amount;
public Test(String name, String month, int amount) {
this.name = name;
this.month = month;
this.amount = amount;
}
public String getName() {
return name;
}
public String getMonth() {
return month;
}
public int getAmount() {
return amount;
}
}
}

View File

@@ -67,6 +67,14 @@ public class Java8RegressionTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testIDEA131282() throws Exception {
doTest(false);
}
public void testIDEA134945() throws Exception {
doTest(false);
}
private void doTest() {
doTest(false);
}