mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-18 08:50:57 +07:00
Part of IDEA-365344 Create a new Java error highlighter with minimal dependencies (PSI only) GitOrigin-RevId: 4449ffc2458eeb73fa296453f6963a6eeed28a76
29 lines
692 B
Java
29 lines
692 B
Java
/** @noinspection UnusedDeclaration*/
|
|
class LimitedPool<T> {
|
|
private int capacity;
|
|
private final ObjectFactory<T> factory;
|
|
private Object[] storage;
|
|
private int index = 0;
|
|
|
|
public LimitedPool(final int capacity, ObjectFactory<T> factory) {
|
|
this.capacity = capacity;
|
|
this.factory = factory;
|
|
storage = new Object[capacity];
|
|
}
|
|
|
|
interface ObjectFactory<T> {
|
|
T create();
|
|
void cleanup(T t);
|
|
}
|
|
|
|
public T alloc() {
|
|
if (index >= capacity) return factory.create();
|
|
|
|
if (storage[index] == null) {
|
|
storage[index] = factory.create();
|
|
}
|
|
|
|
return <error descr="Incompatible types. Found: 'java.lang.Object[]', required: 'T'">storage</error>;
|
|
}
|
|
|
|
} |