当前位置: 首页>>代码示例>>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;未经允许,请勿转载。