我有地图的结构图,如:
Map<Center, Map<Product, Value>> given
Run Code Online (Sandbox Code Playgroud)
而且我想得到
Map<Product, Map<Center, Value>> result
Run Code Online (Sandbox Code Playgroud)
我使用过Java流
Map<Product, Map<Center, Value>> result = given.entrySet().stream()
.flatMap(entry -> entry.getValue()
.entrySet().stream()
.map(e -> Triple(entry.getKey(), e.getKey(), e.getValue())))
.collect(Collectors.groupingBy(Triple::getProduct,
Collectors.toMap(Triple::getCenter, Triple::getValue)));
Run Code Online (Sandbox Code Playgroud)
哪里Triple是简单的价值类.我的问题是,如果有可能做到这一点的功能,而无需使用额外的类,如Triple或如Table从番石榴?