합니까 Java8을지도하는지도
Map<X,Y> + Map<Y,Z> = Map<X,Z>
지금 내 코드
내가 알고 싶은ArrayList<String> couponCodes = newArrayList("aaa", "bbb", "ccc");
// couponCode -- shopId
ArrayList<ShopCoupon> shopCoupons = newArrayList(new ShopCoupon("aaa", 1), new ShopCoupon("bbb", 2), new ShopCoupon("ccc", 3));
Map<String, Integer> couponCodeShopIdMap = shopCoupons.stream().collect(toMap(sc -> sc.getCouponCode(), sc -> sc.getShopId()));
// shopId -- name
ArrayList<Shop> shops = newArrayList(new Shop(1, "zhangsan"), new Shop(2, "lisi"), new Shop(3, "wangwu"));
Map<Integer, String> shopIdNameMap = shops.stream().collect(toMap(s -> s.getId(), s -> s.getName()));
//couponCode -- name
Map<String, String> couponCodeNameMap = couponCodes.stream().collect(toMap(c -> c, c -> shopIdNameMap.get(couponCodeShopIdMap.get(c))));
System.out.println(couponCodeNameMap);
좀 더 편리입니다 이 요구 사항을 구현하는 방식?