當前位置: 首頁>>代碼示例>>Java>>正文


Java WeakHashMap.put方法代碼示例

本文整理匯總了Java中java.util.WeakHashMap.put方法的典型用法代碼示例。如果您正苦於以下問題:Java WeakHashMap.put方法的具體用法?Java WeakHashMap.put怎麽用?Java WeakHashMap.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.WeakHashMap的用法示例。


在下文中一共展示了WeakHashMap.put方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.util.WeakHashMap; //導入方法依賴的package包/類
public static void main(String[] strs) {
    int size = 100;
    Key[] a = new Key[100];
    WeakHashMap<Key, Value> weakHashMap = new WeakHashMap<>();

    for (int i = 0; i < size; i++) {
        Key key = new Key(i+"");
        Value value = new Value(i + "");
        if (i % 3 == 0) {
            a[i] = key;
        }
        weakHashMap.put(key, value);
    }

    System.gc();

    System.out.println(weakHashMap);
}
 
開發者ID:lgliuwei,項目名稱:ThinkingInJavaStudy,代碼行數:19,代碼來源:Test.java

示例2: invalidate

import java.util.WeakHashMap; //導入方法依賴的package包/類
public void invalidate() {
    if (mNativeMap.isEmpty()) return;

    final WeakHashMap<android.view.MenuItem, MenuItem> menuMapCopy = new WeakHashMap<android.view.MenuItem, MenuItem>(mNativeMap.size());

    for (int i = 0; i < mNativeMenu.size(); i++) {
        final android.view.MenuItem item = mNativeMenu.getItem(i);
        menuMapCopy.put(item, mNativeMap.get(item));
    }

    mNativeMap.clear();
    mNativeMap.putAll(menuMapCopy);
}
 
開發者ID:treasure-lau,項目名稱:CSipSimple,代碼行數:14,代碼來源:MenuWrapper.java

示例3: testAwaitDone_FinalizationPredicate

import java.util.WeakHashMap; //導入方法依賴的package包/類
public void testAwaitDone_FinalizationPredicate() {
  final WeakHashMap<Object, Object> map = new WeakHashMap<Object, Object>();
  map.put(new Object(), Boolean.TRUE);
  GcFinalization.awaitDone(new FinalizationPredicate() {
    public boolean isDone() {
      return map.isEmpty();
    }
  });
  assertTrue(map.isEmpty());
}
 
開發者ID:zugzug90,項目名稱:guava-mock,代碼行數:11,代碼來源:GcFinalizationTest.java

示例4: put

import java.util.WeakHashMap; //導入方法依賴的package包/類
@Override
public synchronized V put(K key, V value) {
  WeakHashMap<K, V> tmp = new WeakHashMap<K, V>(map);
  V result = tmp.put(key, value);
  map = Collections.unmodifiableMap(tmp);
  return result;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:8,代碼來源:CopyOnWriteWeakHashMap.java

示例5: putIfAbsent

import java.util.WeakHashMap; //導入方法依賴的package包/類
public synchronized V putIfAbsent(K key, V value) {
  V oldValue = map.get(key);
  if (oldValue != null) {
    return oldValue;
  }

  WeakHashMap<K, V> tmp = new WeakHashMap<K, V>(map);
  V result = tmp.put(key, value);
  map = Collections.unmodifiableMap(tmp);
  return result;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:12,代碼來源:CopyOnWriteWeakHashMap.java

示例6: setWindowDeactivationTime

import java.util.WeakHashMap; //導入方法依賴的package包/類
public synchronized void setWindowDeactivationTime(Window w, long time) {
    AppContext ctx = getAppContext(w);
    if (ctx == null) {
        return;
    }
    @SuppressWarnings("unchecked")
    WeakHashMap<Window, Long> map = (WeakHashMap<Window, Long>)ctx.get(DEACTIVATION_TIMES_MAP_KEY);
    if (map == null) {
        map = new WeakHashMap<Window, Long>();
        ctx.put(DEACTIVATION_TIMES_MAP_KEY, map);
    }
    map.put(w, time);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:SunToolkit.java

示例7: main

import java.util.WeakHashMap; //導入方法依賴的package包/類
public static void main(String[] args) {
    //使用軟引用構建敏感數據的緩存
    String str = new String("Hello");
    ReferenceQueue queue = new ReferenceQueue();
    SoftReference<String> softReferenceString = new SoftReference<>(str,queue);
    str = null;
    System.gc();
    System.out.println(softReferenceString.get());

    WeakReference<String> weakReferenceString = new WeakReference<>(new String("World"));
    System.out.println(weakReferenceString.get());

    WeakHashMap weakHashMap = new WeakHashMap();
    weakHashMap.put(1,2);
}
 
開發者ID:baohongfei,項目名稱:think-in-java,代碼行數:16,代碼來源:ReferenceTest.java

示例8: _doSaveInfo

import java.util.WeakHashMap; //導入方法依賴的package包/類
private static void _doSaveInfo(WeakHashMap<Canvas, ArrayList<CanvasSaveInfo>> stack, CanvasSaveInfo info) {
	if (stack != null) {
		ArrayList<CanvasSaveInfo> canvasSaveInfos = stack.get(info.canvas);
		if (canvasSaveInfos == null) {
			canvasSaveInfos = new ArrayList<CanvasSaveInfo>();
			stack.put(info.canvas, canvasSaveInfos);
		}
		canvasSaveInfos.add(info);
	}
}
 
開發者ID:starcor-company,項目名稱:starcor.xul,代碼行數:11,代碼來源:XulUtils.java


注:本文中的java.util.WeakHashMap.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。