Source:
public void updateFromConfig(List<Device> newDevices, List<Folder> newFolders) { List<String> removedDevices = new ArrayList<>();; Boolean deviceFound; for (String deviceId : deviceFolderMap.keySet()) { deviceFound = false; for (Device device : newDevices) { if (device.deviceID.equals(deviceId)) { deviceFound = true; break; } } if (!deviceFound) { removedDevices.add(deviceId); } } for (String deviceId : removedDevices) { Log.v(TAG, "updateFromConfig: Remove device '" + deviceId + "' from cache model"); deviceFolderMap.remove(deviceId); } for (Device device : newDevices) { if (!deviceFolderMap.containsKey(device.deviceID)) { Log.v(TAG, "updateFromConfig: Add device '" + device.deviceID + "' to cache model"); deviceFolderMap.put(device.deviceID, new DefaultHashMap<String, CompletionInfo>()); } } List<String> removedFolders = new ArrayList<>();; Boolean folderFound; for (String deviceId : deviceFolderMap.keySet()) { for (String folderId : deviceFolderMap.get(deviceId).keySet()) { folderFound = false; for (Folder folder : newFolders) { if (folder.id.equals(folderId)) { folderFound = true; break; } } if (!folderFound) { removedFolders.add(folderId); } } } for (String folderId : removedFolders) { Log.v(TAG, "updateFromConfig: Remove folder '" + folderId + "' from cache model"); removeFolder(folderId); } for (Folder folder : newFolders) { for (Device device : newDevices) { if (folder.getDevice(device.deviceID) != null) { if (!deviceFolderMap.get(device.deviceID).containsKey(folder.id)) { Log.v(TAG, "updateFromConfig: Add folder '" + folder.id + "' shared with device '" + device.deviceID + "' to cache model."); deviceFolderMap.get(device.deviceID).put(folder.id, new CompletionInfo()); } } } } }

Target:
public void updateFromConfig(List<Device> newDevices, List<Folder> newFolders) { HashMap<String, CompletionInfo> folderMap; List<String> removedDevices = new ArrayList<>();; Boolean deviceFound; for (String deviceId : deviceFolderMap.keySet()) { deviceFound = false; for (Device device : newDevices) { if (device.deviceID.equals(deviceId)) { deviceFound = true; break; } } if (!deviceFound) { removedDevices.add(deviceId); } } for (String deviceId : removedDevices) { Log.v(TAG, "updateFromConfig: Remove device '" + deviceId + "' from cache model"); deviceFolderMap.remove(deviceId); } for (Device device : newDevices) { if (!deviceFolderMap.containsKey(device.deviceID)) { Log.v(TAG, "updateFromConfig: Add device '" + device.deviceID + "' to cache model"); deviceFolderMap.put(device.deviceID, new HashMap<String, CompletionInfo>()); } } List<String> removedFolders = new ArrayList<>();; Boolean folderFound; for (Map.Entry<String, HashMap<String, CompletionInfo>> device : deviceFolderMap.entrySet()) { for (String folderId : device.getValue().keySet()) { folderFound = false; for (Folder folder : newFolders) { if (folder.id.equals(folderId)) { folderFound = true; break; } } if (!folderFound) { removedFolders.add(folderId); } } } for (String folderId : removedFolders) { Log.v(TAG, "updateFromConfig: Remove folder '" + folderId + "' from cache model"); removeFolder(folderId); } for (Folder folder : newFolders) { for (Device device : newDevices) { if (folder.getDevice(device.deviceID) != null) { folderMap = deviceFolderMap.get(device.deviceID); if (!folderMap.containsKey(folder.id)) { Log.v(TAG, "updateFromConfig: Add folder '" + folder.id + "' shared with device '" + device.deviceID + "' to cache model."); folderMap.put(folder.id, new CompletionInfo()); } } } } }