本文整理汇总了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);
}
示例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);
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}