本文整理汇总了Java中java.util.concurrent.ConcurrentMap.putAll方法的典型用法代码示例。如果您正苦于以下问题:Java ConcurrentMap.putAll方法的具体用法?Java ConcurrentMap.putAll怎么用?Java ConcurrentMap.putAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.ConcurrentMap
的用法示例。
在下文中一共展示了ConcurrentMap.putAll方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doInTransaction
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
void doInTransaction(Runnable dbWork) {
ConcurrentMap<String, String> newStorage = new ConcurrentHashMap<String, String>();
newStorage.putAll(storage);
workingStorage.set(newStorage);
SQLiteDatabase mDb = openDB();
workingDB.set(mDb);
List<String> changedKeys = new ArrayList<String>();
workingChangedKeys.set(changedKeys);
mDb.beginTransaction();
try {
dbWork.run();
mDb.setTransactionSuccessful();
storage = newStorage;
} finally {
workingDB.remove();
workingStorage.remove();
workingChangedKeys.remove();
mDb.endTransaction();
mDb.close();
}
}
示例2: create
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
@Override
public <K extends Comparable<K>, V> Map<K, V> create(Map<K, V> map) {
// We use a "custom" equivalence to force MapMaker to make a MapMakerInternalMap.
ConcurrentMap<K, V> newMap = new MapMaker().keyEquivalence(Equivalence.equals()).makeMap();
checkState(newMap instanceof MapMakerInternalMap);
newMap.putAll(map);
return newMap;
}
示例3: create
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
@Override
<K, V> Map<K, V> create(Map<K, V> map) {
// We use a "custom" equivalence to force MapMaker to make a MapMakerInternalMap.
ConcurrentMap<K, V> newMap = new MapMaker().keyEquivalence(Equivalence.equals()).makeMap();
checkState(newMap instanceof MapMakerInternalMap);
newMap.putAll(map);
return newMap;
}
示例4: testAsMap
import java.util.concurrent.ConcurrentMap; //导入方法依赖的package包/类
public void testAsMap() {
CacheBuilder<Object, Object> builder = createCacheBuilder();
LocalLoadingCache<Object, Object> cache = makeCache(builder, identityLoader());
assertEquals(EMPTY_STATS, cache.stats());
Object one = new Object();
Object two = new Object();
Object three = new Object();
ConcurrentMap<Object, Object> map = cache.asMap();
assertNull(map.put(one, two));
assertSame(two, map.get(one));
map.putAll(ImmutableMap.of(two, three));
assertSame(three, map.get(two));
assertSame(two, map.putIfAbsent(one, three));
assertSame(two, map.get(one));
assertNull(map.putIfAbsent(three, one));
assertSame(one, map.get(three));
assertSame(two, map.replace(one, three));
assertSame(three, map.get(one));
assertFalse(map.replace(one, two, three));
assertSame(three, map.get(one));
assertTrue(map.replace(one, three, two));
assertSame(two, map.get(one));
assertEquals(3, map.size());
map.clear();
assertTrue(map.isEmpty());
assertEquals(0, map.size());
cache.getUnchecked(one);
assertEquals(1, map.size());
assertSame(one, map.get(one));
assertTrue(map.containsKey(one));
assertTrue(map.containsValue(one));
assertSame(one, map.remove(one));
assertEquals(0, map.size());
cache.getUnchecked(one);
assertEquals(1, map.size());
assertFalse(map.remove(one, two));
assertTrue(map.remove(one, one));
assertEquals(0, map.size());
cache.getUnchecked(one);
Map<Object, Object> newMap = ImmutableMap.of(one, one);
assertEquals(newMap, map);
assertEquals(newMap.entrySet(), map.entrySet());
assertEquals(newMap.keySet(), map.keySet());
Set<Object> expectedValues = ImmutableSet.of(one);
Set<Object> actualValues = ImmutableSet.copyOf(map.values());
assertEquals(expectedValues, actualValues);
}