んJava8が便利なことがjava8コンバート地図<X,Y>は+ <X,Z>
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);
である私が知りたいのいくつかのより便利ですこの要件を実装する方法は?