blob: 186850b8847b36a96504c437a42d24708e329c44 (
plain)
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
|
package com.bumptech.glide.resize.bitmap_recycle;
import android.os.Build;
import java.util.ArrayDeque;
import java.util.LinkedList;
import java.util.Queue;
abstract class BaseKeyPool<T extends Poolable> {
private static final int MAX_SIZE = 20;
private final Queue<T> keyPool;
public BaseKeyPool() {
if (Build.VERSION.SDK_INT >= 9) {
keyPool = new ArrayDeque<T>(MAX_SIZE);
} else {
keyPool = new LinkedList<T>();
}
}
protected T get() {
T result = keyPool.poll();
if (result == null) {
result = create();
}
return result;
}
public void offer(T key) {
if (keyPool.size() < MAX_SIZE) {
keyPool.offer(key);
}
}
protected abstract T create();
}
|