Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. public class GroupingByStreamTest {
  2. class Double<A, B> {
  3. A a;
  4. B b;
  5.  
  6. public Double(A a, B b) {
  7. this.a = a;
  8. this.b = b;
  9. }
  10. }
  11.  
  12. class Triple<A, B, C> extends Double<A, B> {
  13. C c;
  14.  
  15. public Triple(A a, B b, C c) {
  16. super(a, b);
  17. this.c = c;
  18. }
  19. }
  20.  
  21. @Test
  22. public void shouldGroupToMap() throws Exception {
  23. List<Triple<String, String, String>> listOfTriples = asList(
  24. new Triple<>("a-1", "b-1", "c-1"),
  25. new Triple<>("a-1", "b-2", "c-2"),
  26. new Triple<>("a-1", "b-3", "c-3"),
  27. new Triple<>("a-2", "b-4", "c-4"),
  28. new Triple<>("a-2", "b-5", "c-5"));
  29.  
  30. // This code below compiles and executes OK. If I put a breakpoint
  31. // in my EDI I can even see the expected Map being created. However
  32. // if you uncomment the line below and comment the one after it the
  33. // code will no longer compile.
  34.  
  35. // Map<String, List<Double<String, String>>> myMap =
  36. Map<Object, List<Double<Object, Object>>> myMap =
  37. listOfTriples.stream().collect(groupingBy(t -> t.a,
  38. mapping((Triple t) -> new Double<>(t.b, t.c),toList())));
  39.  
  40. assertEquals(2, myMap.size());
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement