亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Arraylist.iterator().next() 上獲取 Concurrent

在 Arraylist.iterator().next() 上獲取 Concurrent

holdtom 2023-06-04 17:34:13
我有以下代碼,它是較長代碼段的一部分,旨在將對象圖轉換為平面樹,以便現有代碼可以進一步處理該樹: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......



查看完整回答
反對 回復 2023-06-04
  • 1 回答
  • 0 關注
  • 144 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號