public int getId(String key) {
        r.lock();
        try {
            Integer v = m.get(key);
            if (v != null) {
                return v;
            }
        } finally {
            r.unlock();
        }

        try {
            w.lock();
            Integer v = m.get(key);
            if (v != null) {
                return v;
            }
            v = m.size() + 1;
            m.put(key, v);
            write(v, key);
            numWrites++;
            return v;
        } finally {
            w.unlock();
        }
    }
Abstract buffer for map of values and unique ids.
<p>
Use this for fast in memory lookups of smallish sets of values.
tika-eval/tika-eval-app/src/main/java/org/apache/tika/eval/app/db/AbstractDBBuffer.java