SetMultimap<K, V> build() { return Multimaps.forMap(map); } }
@Override protected Iterator<Integer> newTargetIterator() { Map<String, Integer> map = Maps.newHashMap(); map.put("foo", 1); map.put("bar", 2); multimap = Multimaps.forMap(map); return multimap.get("foo").iterator(); }
private URI uri(final String path, final Map<String, String> query) { return uri(path, Multimaps.forMap(query)); }
public void addTags(Map<String, String> tags) { this.tags.putAll(Multimaps.forMap(tags)); }
@Override protected Map<String, Collection<Integer>> makePopulatedMap() { Map<String, Integer> map = Maps.newHashMap(); map.put("foo", 1); map.put("bar", 2); map.put("cow", 3); return Multimaps.forMap(map).asMap(); }
@Override protected Map<String, Collection<Integer>> makeEmptyMap() { Map<String, Integer> map = Maps.newHashMap(); return Multimaps.forMap(map).asMap(); }
@GwtIncompatible // SerializableTester public void testForMapSerialization() { Map<String, Integer> map = Maps.newHashMap(); map.put("foo", 1); map.put("bar", 2); Multimap<String, Integer> multimapView = Multimaps.forMap(map); SerializableTester.reserializeAndAssert(multimapView); }
public void testForMapRemoveAll() { Map<String, Integer> map = Maps.newHashMap(); map.put("foo", 1); map.put("bar", 2); map.put("cow", 3); Multimap<String, Integer> multimap = Multimaps.forMap(map); assertEquals(3, multimap.size()); assertEquals(Collections.emptySet(), multimap.removeAll("dog")); assertEquals(3, multimap.size()); assertTrue(multimap.containsKey("bar")); assertEquals(Collections.singleton(2), multimap.removeAll("bar")); assertEquals(2, multimap.size()); assertFalse(multimap.containsKey("bar")); }
public void testForMapAsMap() { Map<String, Integer> map = Maps.newHashMap(); map.put("foo", 1); map.put("bar", 2); Map<String, Collection<Integer>> asMap = Multimaps.forMap(map).asMap(); assertEquals(Collections.singleton(1), asMap.get("foo")); assertNull(asMap.get("cow")); assertTrue(asMap.containsKey("foo")); assertFalse(asMap.containsKey("cow")); Set<Entry<String, Collection<Integer>>> entries = asMap.entrySet(); assertFalse(entries.contains((Object) 4.5)); assertFalse(entries.remove((Object) 4.5)); assertFalse(entries.contains(Maps.immutableEntry("foo", Collections.singletonList(1)))); assertFalse(entries.remove(Maps.immutableEntry("foo", Collections.singletonList(1)))); assertFalse(entries.contains(Maps.immutableEntry("foo", Sets.newLinkedHashSet(asList(1, 2))))); assertFalse(entries.remove(Maps.immutableEntry("foo", Sets.newLinkedHashSet(asList(1, 2))))); assertFalse(entries.contains(Maps.immutableEntry("foo", Collections.singleton(2)))); assertFalse(entries.remove(Maps.immutableEntry("foo", Collections.singleton(2)))); assertTrue(map.containsKey("foo")); assertTrue(entries.contains(Maps.immutableEntry("foo", Collections.singleton(1)))); assertTrue(entries.remove(Maps.immutableEntry("foo", Collections.singleton(1)))); assertFalse(map.containsKey("foo")); }
multimap.put("foo", 1); multimap.put("bar", 2); Multimap<String, Integer> multimapView = Multimaps.forMap(map); new EqualsTester().addEqualityGroup(multimap, multimapView).addEqualityGroup(map).testEquals(); Multimap<String, Integer> multimap2 = HashMultimap.create();
public void putCellsDeleted(Map<SweepPriorityRow, Long> map) { Map<SweepPriorityRow, SweepPriorityNamedColumnValue<?>> toPut = Maps.newHashMapWithExpectedSize(map.size()); for (Entry<SweepPriorityRow, Long> e : map.entrySet()) { toPut.put(e.getKey(), CellsDeleted.of(e.getValue())); } put(Multimaps.forMap(toPut)); }
public void putValue(Map<DataStreamValueRow, byte[]> map) { Map<DataStreamValueRow, DataStreamValueNamedColumnValue<?>> toPut = Maps.newHashMapWithExpectedSize(map.size()); for (Entry<DataStreamValueRow, byte[]> e : map.entrySet()) { toPut.put(e.getKey(), Value.of(e.getValue())); } put(Multimaps.forMap(toPut)); }
public void putMetadata(Map<UserPhotosStreamMetadataRow, com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata> map) { Map<UserPhotosStreamMetadataRow, UserPhotosStreamMetadataNamedColumnValue<?>> toPut = Maps.newHashMapWithExpectedSize(map.size()); for (Entry<UserPhotosStreamMetadataRow, com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata> e : map.entrySet()) { toPut.put(e.getKey(), Metadata.of(e.getValue())); } put(Multimaps.forMap(toPut)); }
public void putData(Map<KvRowsRow, byte[]> map) { Map<KvRowsRow, KvRowsNamedColumnValue<?>> toPut = Maps.newHashMapWithExpectedSize(map.size()); for (Entry<KvRowsRow, byte[]> e : map.entrySet()) { toPut.put(e.getKey(), Data.of(e.getValue())); } put(Multimaps.forMap(toPut)); }
public void putBar(Map<TwoColumnsRow, Long> map) { Map<TwoColumnsRow, TwoColumnsNamedColumnValue<?>> toPut = Maps.newHashMapWithExpectedSize(map.size()); for (Entry<TwoColumnsRow, Long> e : map.entrySet()) { toPut.put(e.getKey(), Bar.of(e.getValue())); } put(Multimaps.forMap(toPut)); }
public void putMetadata(Map<StreamTestWithHashStreamMetadataRow, com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata> map) { Map<StreamTestWithHashStreamMetadataRow, StreamTestWithHashStreamMetadataNamedColumnValue<?>> toPut = Maps.newHashMapWithExpectedSize(map.size()); for (Entry<StreamTestWithHashStreamMetadataRow, com.palantir.atlasdb.protos.generated.StreamPersistence.StreamMetadata> e : map.entrySet()) { toPut.put(e.getKey(), Metadata.of(e.getValue())); } put(Multimaps.forMap(toPut)); }
@Override public void setupTableData() { getKvs().truncateTable(getTableRef()); Map<Cell, byte[]> batch = Tables.generateRandomBatch(random, BATCH_SIZE); getKvs().put(getTableRef(), batch, Tables.DUMMY_TIMESTAMP); data = Multimaps.forMap(Maps.transformValues(batch, $ -> Tables.DUMMY_TIMESTAMP)); }
@Test public void testKeyValueDelete() { putDirect("row1", "col1", "v1", 0); Pair<String, Long> pair = getDirect("row1", "col1", 2); assertEquals(0L, (long)pair.getRhSide()); assertEquals("v1", pair.getLhSide()); keyValueService.delete(TEST_TABLE, Multimaps.forMap(ImmutableMap.of(createCell("row1", "col1"), 0L))); pair = getDirect("row1", "col1", 2); assertNull(pair); }
@Test public void testKeyValueDelete2() { putDirect("row1", "col1", "v1", 1); putDirect("row1", "col1", "v2", 2); Pair<String, Long> pair = getDirect("row1", "col1", 3); assertEquals(2L, (long)pair.getRhSide()); assertEquals("v2", pair.getLhSide()); keyValueService.delete(TEST_TABLE, Multimaps.forMap(ImmutableMap.of(createCell("row1", "col1"), 2L))); pair = getDirect("row1", "col1", 3); assertEquals(1L, (long)pair.getRhSide()); assertEquals("v1", pair.getLhSide()); }
@Test public void testKeyValueDelete6() { putDirect("row1", "col1", "v1", 1); putDirect("row1", "col1", "v2", 2); Pair<String, Long> pair = getDirect("row1", "col1", 3); assertEquals(2L, (long)pair.getRhSide()); assertEquals("v2", pair.getLhSide()); keyValueService.delete(TEST_TABLE, Multimaps.forMap(ImmutableMap.of(createCell("row1", "col1"), 1L))); pair = getDirect("row1", "col1", 3); assertEquals(2L, (long)pair.getRhSide()); assertEquals("v2", pair.getLhSide()); }