@Test public void testShouldAddObjectsIfNotExist() throws Exception { final int sizeBefore = multimap.get(5).size(); final TestObject oldObject = multimap.get(5).get(1); final TestObject newObject1 = new TestObject(111); final TestObject newObject2 = new TestObject(123); final List<TestObject> objectsToAdd = Arrays.asList(oldObject, newObject1, newObject2); multimap.update(5, new ObjectsAddedUpdater<TestObject>(objectsToAdd)); final List<TestObject> actual = multimap.get(5); assertTrue(actual.contains(newObject1)); assertTrue(actual.contains(newObject2)); assertTrue(actual.contains(oldObject)); assertEquals(sizeBefore + 2, actual.size()); }
@Nullable @Override public List<V> update(@Nonnull List<V> values) { if (values == ThreadSafeMultimap.NO_VALUE) { return null; } else { List<V> result = null; for (V newObject : newObjects) { if (!Iterables.contains(values, newObject)) { if (result == null) { result = ThreadSafeMultimap.copy(values); } result.add(newObject); } } return result; } }
ObjectsAddedUpdater implements ThreadSafeMultimap.ListUpdater<V> { @Nullable @Override public List<V> update(@Nonnull List<V> values) { if (values == ThreadSafeMultimap.NO_VALUE) { return null; } else { List<V> result = null; for (V newObject : newObjects) { if (!Iterables.contains(values, newObject)) { if (result == null) { result = ThreadSafeMultimap.copy(values); } result.add(newObject); } } return result; } } }
ObjectsAddedUpdater implements ThreadSafeMultimap.ListUpdater<V> { @Nullable @Override public List<V> update(@Nonnull List<V> values) { if (values == ThreadSafeMultimap.NO_VALUE) { return null; } else { List<V> result = null; for (V newObject : newObjects) { if (!Iterables.contains(values, newObject)) { if (result == null) { result = ThreadSafeMultimap.copy(values); } result.add(newObject); } } return result; } } ObjectsAddedUpdater(@Nonnull Collection<V> newObjects); }
ObjectsAddedUpdater implements ThreadSafeMultimap.ListUpdater<V> { @Nullable @Override public List<V> update(@Nonnull List<V> values) { if (values == ThreadSafeMultimap.NO_VALUE) { return null; } else { List<V> result = null; for (V newObject : newObjects) { if (!Iterables.contains(values, newObject)) { if (result == null) { result = ThreadSafeMultimap.copy(values); } result.add(newObject); } } return result; } } ObjectsAddedUpdater(@Nonnull Collection<V> newObjects); @Nullable @Override List<V> update(@Nonnull List<V> values); }
ObjectsAddedUpdater implements ThreadSafeMultimap.ListUpdater<V> { @Nullable @Override public List<V> update(@Nonnull List<V> values) { if (values == ThreadSafeMultimap.NO_VALUE) { return null; } else { List<V> result = null; for (V newObject : newObjects) { if (!Iterables.contains(values, newObject)) { if (result == null) { result = ThreadSafeMultimap.copy(values); } result.add(newObject); } } return result; } } ObjectsAddedUpdater(@Nonnull Collection<V> newObjects); @Nullable @Override List<V> update(@Nonnull List<V> values);  }