@NonNull public static DeviceListComparisonResult compare(@NonNull List<? extends Device> previous, @NonNull List<? extends Device> current) { current = new ArrayList<>(current); final Map<Device,DeviceState> updated = new HashMap<>(current.size()); final List<Device> added = new ArrayList<>(1); final List<Device> removed = new ArrayList<>(1); for (Device device : previous) { Device currentDevice = find(current, device); if (currentDevice != null) { if (currentDevice.getState() != device.getState()) { updated.put(device, currentDevice.getState()); } current.remove(currentDevice); } else { removed.add(device); } } added.addAll(current); return new DeviceListComparisonResult(updated, added, removed); }