當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。