我有以下代碼,它是較長代碼段的一部分,旨在將對象圖轉換為平面樹,以便現有代碼可以進一步處理該樹: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
提交
取消