我有以下代码,它是较长代码段的一部分,旨在将对象图转换为平面树,以便现有代码可以进一步处理该树:private void addProjectStreamsFromGraphToTree(String parentIndex, Map<String, Object> objectTree, ProjectTreeView projectTreeView) { Set<Integer> allConnectedLevelOids = new HashSet<Integer>(); // Set in the tree + add everything underneath projectStream: int index = 1; String treeIndex =""; for (Iterator<ExportableProjectStreamView> iter = projectTreeView.getProjectStreamList().iterator(); iter.hasNext(); index++) { // Getting the concurrentModificationException on the below line ProjectStreamView projectStreamView = (ProjectStreamView) iter.next(); treeIndex = parentIndex + "." + index; objectTree.put(treeIndex, projectStreamView); addLifeCyclesFromGraphToTree(allConnectedLevelOids, projectStreamView , treeIndex, objectTree, projectTreeView); } }private void addLifeCyclesFromGraphToTree(Set<Integer> allConnectedLevelOids, ProjectStreamView projectStreamView, String parentIndex, Map<String, Object> objectTree, ProjectTreeView projectTreeView) { int index = 1; String treeIndex =""; ExportableLifecycleView lifecycleView = projectTreeView.getLifecycleList().stream().filter(lcv -> projectStreamView.getLifecycleOid().equals(lcv.getOid())).findFirst().get(); treeIndex = parentIndex + "." + index; objectTree.put(treeIndex, lifecycleView); // add the levels that are linked to this lifecycle and at once add all oids of the levels, // connected to this lifecycle, to the allconnectedLevelOids. allConnectedLevelOids.addAll(addConnectedLevelsFromGraphToTree(lifecycleView, treeIndex, objectTree, projectTreeView));}如您所见,除了获取迭代器外,我从不与 projectTreeView.getProjectStreamList() 交互,而且我从不在任何列表上调用 .remove() 或 .add()。我所做的唯一改变事物的事情是树图上的 put() 和本地 HashSet() 上的 .add。我也不以任何方式更改原始 projectTreeView,并且我只读取使用迭代器检索的 projectStreamView 的属性。
1 回答
RISEBY
TA贡献1856条经验 获得超5个赞
我做了一些检查,我发现了是什么原因造成的。原来是里面有bug projectTreeView.getLevelList()
。我在使用 返回之前对我的列表进行排序Collections.sort()
,而不是levelList
在那里排序,我排序projectStreamList
......
添加回答
举报
0/150
提交
取消