@Test @SuppressWarnings("NullAway") public void testMultipleSibling() throws Exception { final Notification n1 = Notification.create("1"); final Notification n2 = Notification.create("2"); final Notification n3 = Notification.create("3"); final Notification n4 = Notification.create("4"); final Notification n5 = Notification.create("5"); final Notification n6 = Notification.create("6"); final NotificationListObject list1 = new NotificationListObject("test"); list1.addNotification(n1); list1.addNotification(n4); list1.addNotification(n2); list1.addNotification(n3); final NotificationListObject list2 = new NotificationListObject("test"); list2.addNotification(n2); list2.addNotification(n3); list2.addNotification(n5); final NotificationListObject list3 = new NotificationListObject("test"); list3.addNotification(n6); list3.addNotification(n2); list3.addNotification(n5); final List<NotificationListObject> siblings = Arrays.asList(list1, list2, list3); final NotificationListObject expected = new NotificationListObject("test"); expected.addNotification(n1); expected.addNotification(n2); expected.addNotification(n3); expected.addNotification(n4); expected.addNotification(n5); expected.addNotification(n6); final NotificationListObject actual = resolver.resolve(siblings); assertThat(actual).isEqualTo(expected); assertThat(actual.getNotifications()).containsExactly(n6, n5, n4, n3, n2, n1); assertThat(actual.getDeletedIds()).isEmpty(); }
@Override @Nullable public NotificationListObject resolve(final List<NotificationListObject> siblings) throws UnresolvedConflictException { LOGGER.debug("Found {} siblings", siblings.size()); siblingCounts.update(siblings.size()); if (siblings.size() > 1) { final Iterator<NotificationListObject> iterator = siblings.iterator(); final NotificationListObject resolved = iterator.next(); final Set<String> deletedIds = resolved.getDeletedIds(); while (iterator.hasNext()) { final NotificationListObject sibling = iterator.next(); resolved.addNotifications(sibling.getNotifications()); deletedIds.addAll(sibling.getDeletedIds()); } if (!deletedIds.isEmpty()) { LOGGER.debug("IDs to delete: {}", deletedIds); removeNotifications(resolved.getNotifications(), deletedIds); } return resolved; } else if (siblings.size() == 1) { final NotificationListObject resolved = siblings.get(0); if (!resolved.getDeletedIds().isEmpty()) { LOGGER.debug("IDs to delete: {}", resolved.getDeletedIds()); removeNotifications(resolved.getNotifications(), resolved.getDeletedIds()); } return resolved; } else { return null; } }
NotificationListResolver implements ConflictResolver<NotificationListObject> { @Override @Nullable public NotificationListObject resolve(final List<NotificationListObject> siblings) throws UnresolvedConflictException { LOGGER.debug("Found {} siblings", siblings.size()); siblingCounts.update(siblings.size()); if (siblings.size() > 1) { final Iterator<NotificationListObject> iterator = siblings.iterator(); final NotificationListObject resolved = iterator.next(); final Set<String> deletedIds = resolved.getDeletedIds(); while (iterator.hasNext()) { final NotificationListObject sibling = iterator.next(); resolved.addNotifications(sibling.getNotifications()); deletedIds.addAll(sibling.getDeletedIds()); } if (!deletedIds.isEmpty()) { LOGGER.debug("IDs to delete: {}", deletedIds); removeNotifications(resolved.getNotifications(), deletedIds); } return resolved; } else if (siblings.size() == 1) { final NotificationListObject resolved = siblings.get(0); if (!resolved.getDeletedIds().isEmpty()) { LOGGER.debug("IDs to delete: {}", resolved.getDeletedIds()); removeNotifications(resolved.getNotifications(), resolved.getDeletedIds()); } return resolved; } else { return null; } } }
NotificationListResolver implements ConflictResolver<NotificationListObject> { @Override @Nullable public NotificationListObject resolve(final List<NotificationListObject> siblings) throws UnresolvedConflictException { LOGGER.debug("Found {} siblings", siblings.size()); siblingCounts.update(siblings.size()); if (siblings.size() > 1) { final Iterator<NotificationListObject> iterator = siblings.iterator(); final NotificationListObject resolved = iterator.next(); final Set<String> deletedIds = resolved.getDeletedIds(); while (iterator.hasNext()) { final NotificationListObject sibling = iterator.next(); resolved.addNotifications(sibling.getNotifications()); deletedIds.addAll(sibling.getDeletedIds()); } if (!deletedIds.isEmpty()) { LOGGER.debug("IDs to delete: {}", deletedIds); removeNotifications(resolved.getNotifications(), deletedIds); } return resolved; } else if (siblings.size() == 1) { final NotificationListObject resolved = siblings.get(0); if (!resolved.getDeletedIds().isEmpty()) { LOGGER.debug("IDs to delete: {}", resolved.getDeletedIds()); removeNotifications(resolved.getNotifications(), resolved.getDeletedIds()); } return resolved; } else { return null; } } NotificationListResolver(); }
NotificationListResolver implements ConflictResolver<NotificationListObject> { @Override @Nullable public NotificationListObject resolve(final List<NotificationListObject> siblings) throws UnresolvedConflictException { LOGGER.debug("Found {} siblings", siblings.size()); siblingCounts.update(siblings.size()); if (siblings.size() > 1) { final Iterator<NotificationListObject> iterator = siblings.iterator(); final NotificationListObject resolved = iterator.next(); final Set<String> deletedIds = resolved.getDeletedIds(); while (iterator.hasNext()) { final NotificationListObject sibling = iterator.next(); resolved.addNotifications(sibling.getNotifications()); deletedIds.addAll(sibling.getDeletedIds()); } if (!deletedIds.isEmpty()) { LOGGER.debug("IDs to delete: {}", deletedIds); removeNotifications(resolved.getNotifications(), deletedIds); } return resolved; } else if (siblings.size() == 1) { final NotificationListObject resolved = siblings.get(0); if (!resolved.getDeletedIds().isEmpty()) { LOGGER.debug("IDs to delete: {}", resolved.getDeletedIds()); removeNotifications(resolved.getNotifications(), resolved.getDeletedIds()); } return resolved; } else { return null; } } NotificationListResolver(); @Override @Nullable NotificationListObject resolve(final List<NotificationListObject> siblings); static void removeNotifications(
      final Collection<Notification> notifications, final Collection<String> ids); }
NotificationListResolver implements ConflictResolver<NotificationListObject> { @Override @Nullable public NotificationListObject resolve(final List<NotificationListObject> siblings) throws UnresolvedConflictException { LOGGER.debug("Found {} siblings", siblings.size()); siblingCounts.update(siblings.size()); if (siblings.size() > 1) { final Iterator<NotificationListObject> iterator = siblings.iterator(); final NotificationListObject resolved = iterator.next(); final Set<String> deletedIds = resolved.getDeletedIds(); while (iterator.hasNext()) { final NotificationListObject sibling = iterator.next(); resolved.addNotifications(sibling.getNotifications()); deletedIds.addAll(sibling.getDeletedIds()); } if (!deletedIds.isEmpty()) { LOGGER.debug("IDs to delete: {}", deletedIds); removeNotifications(resolved.getNotifications(), deletedIds); } return resolved; } else if (siblings.size() == 1) { final NotificationListObject resolved = siblings.get(0); if (!resolved.getDeletedIds().isEmpty()) { LOGGER.debug("IDs to delete: {}", resolved.getDeletedIds()); removeNotifications(resolved.getNotifications(), resolved.getDeletedIds()); } return resolved; } else { return null; } } NotificationListResolver(); @Override @Nullable NotificationListObject resolve(final List<NotificationListObject> siblings); static void removeNotifications(
      final Collection<Notification> notifications, final Collection<String> ids);  }