UpdatableInspectorList extends InspectorList<InspectorType> { public void update(final Collection<InspectedType> updates) { final ArrayList<UUIDKey> originalItems = new ArrayList<>(map.keySet()); for (final InspectedType updatable : updates) { final InspectorType inspector = map.get(updatable.getUuidKey()); if (inspector != null) { originalItems.remove(updatable.getUuidKey()); continue; } else { final InspectorType newInspector = inspectorFactory.make(updatable); add(newInspector); map.put(updatable.getUuidKey(), newInspector); } } for (final UUIDKey originalItem : originalItems) { remove(map.remove(originalItem)); } } UpdatableInspectorList(final InspectorFactory<InspectorType, InspectedType> inspectorFactory,
                                  final AnalyzerConfiguration configuration); void update(final Collection<InspectedType> updates);  }
@Test public void add() throws Exception { final ArrayList<Item> updates = new ArrayList<>(); updates.add(new Item()); list.update(updates); assertEquals(1, list.size()); }
@Test public void reAdd() throws Exception { final ArrayList<Item> updates = new ArrayList<>(); updates.add(new Item()); list.update(updates); assertEquals(1, list.size()); list.update(updates); assertEquals(1, list.size()); }
@Test public void reAddNew() throws Exception { final ArrayList<Item> updates = new ArrayList<>(); updates.add(new Item()); list.update(updates); assertEquals(1, list.size()); updates.add(new Item()); list.update(updates); assertEquals(2, list.size()); }
@Test public void remove() throws Exception { final ArrayList<Item> updates = new ArrayList<>(); updates.add(new Item()); final Item removeMe = new Item(); updates.add(removeMe); list.update(updates); assertEquals(2, list.size()); updates.remove(removeMe); list.update(updates); assertEquals(1, list.size()); }