Cache.java
1.8 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
57
58
59
60
61
62
63
64
65
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.pdfg.common;
import java.util.ArrayList;
public class Cache {
protected ArrayList cacheKeys = null;
protected ArrayList cacheValues = null;
protected int maxEntries = 1;
public Cache(int maxEntries) {
if (maxEntries >= 1) {
this.maxEntries = maxEntries;
}
this.cacheKeys = new ArrayList(maxEntries);
this.cacheValues = new ArrayList(maxEntries);
}
public synchronized void clear() {
this.cacheKeys.clear();
this.cacheValues.clear();
}
public synchronized Object get(Object key) {
int i;
Object value = null;
if (key != null && (i = this.cacheKeys.indexOf(key)) != -1) {
value = this.cacheValues.get(i);
this.cacheKeys.remove(i);
this.cacheValues.remove(i);
this.cacheKeys.add(key);
this.cacheValues.add(value);
}
return value;
}
public synchronized void remove(Object key) {
int i;
if (key != null && (i = this.cacheKeys.indexOf(key)) != -1) {
this.cacheKeys.remove(i);
this.cacheValues.remove(i);
}
}
public synchronized Object put(Object key, Object value) {
Object oldValue = null;
if (key != null) {
int i = this.cacheKeys.indexOf(key);
if (i != -1) {
oldValue = this.cacheValues.get(i);
this.cacheKeys.remove(i);
this.cacheValues.remove(i);
} else if (this.cacheKeys.size() >= this.maxEntries) {
this.cacheKeys.remove(0);
this.cacheValues.remove(0);
}
this.cacheKeys.add(key);
this.cacheValues.add(value);
}
return oldValue;
}
}