AbstractFontCache.java
2.89 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.observation.EventIterator
*/
package com.day.image.internal.font;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.jcr.observation.EventIterator;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public abstract class AbstractFontCache<T> {
private final ReferenceQueue<T> reaped = new ReferenceQueue();
private final Map<String, ValueRef<T>> contents = new HashMap<String, ValueRef<T>>();
public void destroy() {
this.clear();
}
public abstract void onEvent(EventIterator var1);
public T get(Object key) {
ValueRef<T> vr = this.contents.get(key);
return vr != null ? (T)vr.get() : null;
}
public T put(String key, T value) {
this.reap();
ValueRef<T> vr = new ValueRef<T>(value, key, this.reaped);
return this.dereference(this.contents.put(key, vr));
}
public void putAll(Map<String, T> baseMap) {
this.reap();
for (Map.Entry<String, T> entry : baseMap.entrySet()) {
this.put(entry.getKey(), entry.getValue());
}
}
public Object remove(Object key) {
this.reap();
return this.dereference(this.contents.remove(key));
}
public void clear() {
this.reap();
this.contents.clear();
}
public boolean equals(Object o) {
return this == o;
}
public int hashCode() {
return this.getClass().getName().hashCode();
}
public String toString() {
return this.getClass().getName() + super.toString();
}
public void reap() {
ValueRef ref;
while ((ref = (ValueRef)this.reaped.poll()) != null) {
this.contents.remove(ref.key);
ref.key = null;
}
}
private T dereference(ValueRef<T> ref) {
if (ref != null) {
T result = ref.get();
ref.clear();
return result;
}
return null;
}
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
private static class ValueRef<T>
extends WeakReference<T> {
private Object key;
ValueRef(T val, Object key, ReferenceQueue<T> q) {
super(val, q);
this.key = key;
}
public int hashCode() {
Object r = this.get();
return r != null ? r.hashCode() : Object.super.hashCode();
}
public boolean equals(Object obj) {
Object r = this.get();
if (r == obj) {
return true;
}
if (r == null) {
return false;
}
return r.equals(obj);
}
}
}