1package com.bumptech.glide.load.engine.bitmap_recycle;
2
3import com.bumptech.glide.util.Util;
4
5import java.util.Queue;
6
7abstract class BaseKeyPool<T extends Poolable> {
8    private static final int MAX_SIZE = 20;
9    private final Queue<T> keyPool = Util.createQueue(MAX_SIZE);
10
11    protected T get() {
12        T result = keyPool.poll();
13        if (result == null) {
14            result = create();
15        }
16        return result;
17    }
18
19    public void offer(T key) {
20        if (keyPool.size() < MAX_SIZE) {
21            keyPool.offer(key);
22        }
23    }
24
25    protected abstract T create();
26}
27