我寫了一個關于將基本映射轉換為另一個結構映射的邏輯,但是SonarLint評論它需要重構,這里是代碼:public static Map<List<String>, String> toStockMap(List<Map<String, Object>> rows) { Map<List<String>, String> stockMap = new HashMap<>(); if (CollectionUtils.isEmpty(rows)) { return stockMap; } for (Map<String, Object> row : rows) { String stock = null; String itemId = null; String modelId = null; for (Map.Entry<String, Object> cell : row.entrySet()) { if (cell.getKey().equals("stock")) { stock = cell.getValue().toString(); } if (cell.getKey().equals("itemid")) { itemId = cell.getValue().toString(); } if (cell.getKey().equals("modelid")) { modelId = cell.getValue().toString(); } } if (stock != null && itemId != null && modelId != null) { stockMap.put(Arrays.asList(modelId, itemId), stock); } } return stockMap;}下面是 sonarlint 的評論:我應該如何改進呢?謝謝
如何重構地圖轉換操作
慕田峪9158850
2023-07-19 15:47:37