com.google.common.collect.Multimap.putAll()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(142)

本文整理了Java中com.google.common.collect.Multimap.putAll()方法的一些代码示例,展示了Multimap.putAll()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Multimap.putAll()方法的具体详情如下:
包路径:com.google.common.collect.Multimap
类名称:Multimap
方法名:putAll

Multimap.putAll介绍

[英]Stores all key-value pairs of multimap in this multimap, in the order returned by multimap.entries().
[中]按照multimap返回的顺序,在此multimap中存储multimap的所有键值对。条目()。

代码示例

代码示例来源:origin: google/guava

@Override
public boolean putAll(Multimap<? extends K, ? extends V> multimap) {
 synchronized (mutex) {
  return delegate().putAll(multimap);
 }
}

代码示例来源:origin: google/guava

/**
 * Returns a {@code Multimap} with the specified implementation, initialized with the entries of
 * {@code multimap}.
 */
public <K extends K0, V extends V0> Multimap<K, V> build(
  Multimap<? extends K, ? extends V> multimap) {
 Multimap<K, V> result = build();
 result.putAll(multimap);
 return result;
}

代码示例来源:origin: google/guava

@Override
protected Iterator<String> newTargetIterator() {
 multimap = LinkedHashMultimap.create();
 multimap.putAll("foo", asList(2, 3));
 multimap.putAll("bar", asList(4, 5));
 multimap.putAll("foo", asList(6));
 multimap.putAll("baz", asList(7, 8));
 multimap.putAll("dog", asList(9));
 multimap.putAll("bar", asList(10, 11));
 multimap.putAll("cat", asList(12, 13, 14));
 return multimap.keySet().iterator();
}

代码示例来源:origin: google/guava

@Override
protected Iterator<Entry<String, Collection<Integer>>> newTargetIterator() {
 multimap = LinkedHashMultimap.create();
 multimap.putAll("foo", asList(2, 3));
 multimap.putAll("bar", asList(4, 5));
 multimap.putAll("foo", asList(6));
 multimap.putAll("baz", asList(7, 8));
 multimap.putAll("dog", asList(9));
 multimap.putAll("bar", asList(10, 11));
 multimap.putAll("cat", asList(12, 13, 14));
 return multimap.asMap().entrySet().iterator();
}

代码示例来源:origin: google/guava

@Override
protected Iterator<Entry<String, Collection<Integer>>> newTargetIterator() {
 multimap = create();
 multimap.putAll("foo", asList(2, 3));
 multimap.putAll("bar", asList(4, 5));
 multimap.putAll("foo", asList(6));
 multimap.putAll("baz", asList(7, 8));
 multimap.putAll("dog", asList(9));
 multimap.putAll("bar", asList(10, 11));
 multimap.putAll("cat", asList(12, 13, 14));
 return multimap.asMap().entrySet().iterator();
}

代码示例来源:origin: google/guava

@CanIgnoreReturnValue
@Override
public boolean putAll(K key, Iterable<? extends V> values) {
 return delegate().putAll(key, values);
}

代码示例来源:origin: google/guava

@CanIgnoreReturnValue
@Override
public boolean putAll(Multimap<? extends K, ? extends V> multimap) {
 return delegate().putAll(multimap);
}

代码示例来源:origin: google/guava

@Override
protected Iterator<String> newTargetIterator() {
 multimap = LinkedHashMultimap.create();
 multimap.putAll("foo", asList(2, 3));
 multimap.putAll("bar", asList(4, 5));
 multimap.putAll("foo", asList(6));
 return multimap.keys().iterator();
}

代码示例来源:origin: google/guava

public void testToString() {
 Multimap<String, Integer> multimap = create();
 multimap.put("foo", 3);
 multimap.put("bar", 1);
 multimap.putAll("foo", Arrays.asList(-1, 2, 4));
 multimap.putAll("bar", Arrays.asList(2, 3));
 multimap.put("foo", 1);
 assertEquals("{bar=[3, 2, 1], foo=[4, 3, 2, 1, -1]}", multimap.toString());
}

代码示例来源:origin: google/guava

@MapFeature.Require(absent = ALLOWS_NULL_KEYS)
public void testPutAllNullForbidden() {
 try {
  multimap().putAll(null, Collections.singletonList(v3()));
  fail("Expected NullPointerException");
 } catch (NullPointerException expected) {
  // success
 }
}

代码示例来源:origin: google/guava

@MapFeature.Require(value = SUPPORTS_PUT, absent = ALLOWS_NULL_VALUES)
public void testPutAllNullValueSingle_unsupported() {
 multimap().putAll(k1(), Lists.newArrayList((V) null));
 expectUnchanged();
}

代码示例来源:origin: google/guava

@MapFeature.Require(SUPPORTS_PUT)
public void testPutAllEmptyCollectionOnAbsentKey() {
 assertFalse(multimap().putAll(k3(), Collections.<V>emptyList()));
 expectUnchanged();
}

代码示例来源:origin: google/guava

@CollectionSize.Require(absent = ZERO)
@MapFeature.Require(SUPPORTS_PUT)
public void testPutAllEmptyIterableOnPresentKey() {
 multimap().putAll(k0(), Collections.<V>emptyList());
 expectUnchanged();
}

代码示例来源:origin: google/guava

public void testLinkedPutAllMultimap() {
 Multimap<String, Integer> src = create();
 src.put("bar", 1);
 src.put("foo", 2);
 src.put("bar", 3);
 Multimap<String, Integer> dst = create();
 dst.putAll(src);
 assertEquals("{bar=[1, 3], foo=[2]}", dst.toString());
 assertEquals("[bar=1, foo=2, bar=3]", src.entries().toString());
}

代码示例来源:origin: google/guava

@MapFeature.Require(SUPPORTS_PUT)
public void testPutAllEmptyIterableOnAbsentKey() {
 Iterable<V> iterable =
   new Iterable<V>() {
    @Override
    public Iterator<V> iterator() {
     return ImmutableSet.<V>of().iterator();
    }
   };
 assertFalse(multimap().putAll(k3(), iterable));
 expectUnchanged();
}

代码示例来源:origin: google/guava

@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_VALUES})
public void testPutAllNullValueOnAbsentKey_supported() {
 assertTrue(multimap().putAll(k3(), Lists.newArrayList(v3(), null)));
 assertGet(k3(), v3(), null);
}

代码示例来源:origin: google/guava

@MapFeature.Require({SUPPORTS_PUT, ALLOWS_NULL_KEYS})
public void testPutAllOnPresentNullKey() {
 assertTrue(multimap().putAll(null, Lists.newArrayList(v3(), v4())));
 assertGet(null, v3(), v4());
}

代码示例来源:origin: google/guava

@MapFeature.Require(SUPPORTS_PUT)
 public void testPutAllPropagatesToGet() {
  Multimap<K, V> source =
    getSubjectGenerator().create(Helpers.mapEntry(k0(), v3()), Helpers.mapEntry(k3(), v3()));
  Collection<V> getCollection = multimap().get(k0());
  int getCollectionSize = getCollection.size();
  assertTrue(multimap().putAll(source));
  assertEquals(getCollectionSize + 1, getCollection.size());
  assertContains(getCollection, v3());
 }
}

代码示例来源:origin: google/guava

@MapFeature.Require(SUPPORTS_PUT)
public void testPutAllNonEmptyCollectionOnAbsentKey() {
 assertTrue(multimap().putAll(k3(), Lists.newArrayList(v3(), v4())));
 assertGet(k3(), v3(), v4());
}

代码示例来源:origin: google/guava

@MapFeature.Require(SUPPORTS_PUT)
public void testPutAll() {
 Multimap<K, V> source =
   getSubjectGenerator().create(Helpers.mapEntry(k0(), v3()), Helpers.mapEntry(k3(), v3()));
 assertTrue(multimap().putAll(source));
 assertTrue(multimap().containsEntry(k0(), v3()));
 assertTrue(multimap().containsEntry(k3(), v3()));
}

相关文章