SimpleCache.java
1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.agl.impl;
import com.adobe.agl.impl.ICUCache;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class SimpleCache
implements ICUCache {
private Reference cacheRef = null;
private int type = 0;
private int capacity = 16;
public SimpleCache() {
}
public SimpleCache(int cacheType, int initialCapacity) {
if (cacheType == 1) {
this.type = cacheType;
}
if (initialCapacity > 0) {
this.capacity = initialCapacity;
}
}
public Object get(Object key) {
Map map;
Reference ref = this.cacheRef;
if (ref != null && (map = (Map)ref.get()) != null) {
return map.get(key);
}
return null;
}
public void put(Object key, Object value) {
Reference ref = this.cacheRef;
Map<Object, Object> map = null;
if (ref != null) {
map = (Map<Object, Object>)ref.get();
}
if (map == null) {
map = Collections.synchronizedMap(new HashMap(this.capacity));
ref = this.type == 1 ? new WeakReference(map) : new SoftReference(map);
this.cacheRef = ref;
}
map.put(key, value);
}
}