当前位置: 首页>>代码示例>>Java>>正文


Java ConcurrentMap.putAll方法代码示例

本文整理汇总了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();
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:25,代码来源:Storage.java

示例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;
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:9,代码来源:BenchmarkHelpers.java

示例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;
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:9,代码来源:BenchmarkHelpers.java

示例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);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:54,代码来源:LocalLoadingCacheTest.java


注:本文中的java.util.concurrent.ConcurrentMap.putAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。