在Java中保持瞬态映射
方案
class A{
String aId;
;}
class B{
String bId;
;}
class C{
String bId;
;}
class D{
B b;
C c;
;}
i hava a 列表< a>
。我使用for循环浏览此列表,执行一些数据库操作并创建list< b>
。我需要从a到b的映射,因此我还创建了map< a,b>
。
从此列表< b>
,我进行批量API调用并获取list< d>
。我还需要从B到C的映射,因此我遍历此list< d>
并创建map&lt< b,c>
。
我的主要要求是从A到C的映射。我无法删除批量API调用,而要删除维护两个地图的额外开销。是否有某种方法可以维护瞬态映射,直接在Java中的a映射到c?
Scenario
class A{
String aId;
;}
class B{
String bId;
;}
class C{
String bId;
;}
class D{
B b;
C c;
;}
I hava a List<A>
. I traverse this list using a for loop, perform some DB operations and create a List<B>
. I need a mapping from A to B, so I create a Map<A,B>
also.
From this List<B>
, I make a bulk API call and fetch a List<D>
. I require a mapping from B to C also, so I traverse over this List<D>
and create a Map<B,C>
.
My main requirement is a mapping from A to C. I can't remove the bulk API call but want to remove the extra overhead of maintaining two maps. Is there some way of maintaining a transitive mapping, a mapping of A to C directly in JAVA?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以按以下方式生成它:
对于循环
流
编辑:根据要求,即使我更喜欢第一个版本,也可以使用流添加一个版本。
You can generate it as follows:
for loop
streams
Edit: As requested, added a version using streams, even though I prefer the first version.