我有以下代碼,它是較長(zhǎng)代碼段的一部分,旨在將對(duì)象圖轉(zhuǎn)換為平面樹(shù),以便現(xiàn)有代碼可以進(jìn)一步處理該樹(shù):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));}如您所見(jiàn),除了獲取迭代器外,我從不與 projectTreeView.getProjectStreamList() 交互,而且我從不在任何列表上調(diào)用 .remove() 或 .add()。我所做的唯一改變事物的事情是樹(shù)圖上的 put() 和本地 HashSet() 上的 .add。我也不以任何方式更改原始 projectTreeView,并且我只讀取使用迭代器檢索的 projectStreamView 的屬性。
1 回答

RISEBY
TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超5個(gè)贊
我做了一些檢查,我發(fā)現(xiàn)了是什么原因造成的。原來(lái)是里面有bug projectTreeView.getLevelList()
。我在使用 返回之前對(duì)我的列表進(jìn)行排序Collections.sort()
,而不是levelList
在那里排序,我排序projectStreamList
......
添加回答
舉報(bào)
0/150
提交
取消