/** * Takes lists of TurboIssues and reconciles the changes between them, returning a list of * TurboIssues with updates from the second. * * @param existing * @param changed */ public static List<TurboIssue> reconcile(List<TurboIssue> existing, List<TurboIssue> changed) { List<TurboIssue> existingCopy = new ArrayList<>(existing); for (TurboIssue issue : changed) { int id = issue.getId(); Optional<Integer> correspondingIssueIndex = findIssueWithId(existingCopy, id); if (!correspondingIssueIndex.isPresent()) { existingCopy.add(new TurboIssue(issue)); } else { TurboIssue existingIssue = existingCopy.get(correspondingIssueIndex.get()); TurboIssue newIssue = new TurboIssue(issue); // newIssue is constructed from an external Issue object. // It won't have the transient state that its TurboIssue // counterpart has, so we have to explicitly transfer it. newIssue.transferTransientState(existingIssue); newIssue.reconcile(existingIssue); existingCopy.set(correspondingIssueIndex.get(), newIssue); } } return existingCopy; }