ModificationsUtil { public static <T> Modifications<T> joinModifications(Collection<? extends Modifications<T>> modificationSet) { if (modificationSet.size() == 1) { return modificationSet.iterator().next(); } ModificationsImpl<T> result = new ModificationsImpl<T>(); for (Modifications<T> m : modificationSet) { registerAddedItems(result, m.getAddedItems()); registerUpdatedItems(result, m.getUpdatedItems()); registerRemovedItems(result, m.getRemovedItems()); } return result; } private  ModificationsUtil(); static Modifications<T2> convertModifications(Modifications<T1> src, Converter<T1, T2> converter); static Modifications<T> createModfications(Collection<T> added, Collection<T> updated,
      Collection<T> removed); static boolean isModified(Modifications<T> modifications, T item); static void registerAddedItems(ModificationsImpl<T> modifications, Iterable<T> items); static void registerUpdatedItems(ModificationsImpl<T> modifications, Iterable<T> items); static void registerRemovedItems(ModificationsImpl<T> modifications, Iterable<T> items); static Modifications<T> joinModifications(Collection<? extends Modifications<T>> modificationSet);  }
@Test public void testJoinModifications() { ModificationsImpl<String> m1 = new ModificationsImpl<String>(); ModificationsImpl<String> m2 = new ModificationsImpl<String>(); m1.registerAddedItem("a1"); m1.registerUpdatedItem("u1", true); m1.setRemovedItems(new ItemSetSelection<String>("r1")); m2.registerAddedItem("a2"); m2.registerUpdatedItem("u2", true); m2.setRemovedItems(new ItemSetSelection<String>("r2")); Modifications<String> m3 = ModificationsUtil.joinModifications(Arrays.asList(m1, m2)); assertEquals("{added: 2, updated: 2, removed: 2}", m3.toString()); assertEquals("[a1, a2]", m3.getAddedItems().toString()); assertEquals("[u1, u2]", m3.getUpdatedItems().toString()); assertEquals("[r1, r2]", m3.getRemovedItems().toString()); }
@Test public void testJoinSingleModification() { modifications.registerAddedItem("a"); Modifications<String> m = ModificationsUtil.joinModifications(Arrays.asList(modifications)); assertEquals("{added: 1, updated: 0, removed: 0}", m.toString()); assertEquals("[a]", m.getAddedItems().toString()); }