persistable sclass SynchronizedCircularBuffer { A[] buffer; long base; // elements dropped due to overcapacity int size; // elements actually contained *(int capacity) { buffer = (A[]) new O[capacity]; } synchronized void add(A a) { if (size == buffer.length) { --size; ++base; } buffer[(int) ((base+size) % buffer.length)] = a; ++size; } synchronized A get(long pos) { if (pos < base || pos >= base+size) null; ret buffer[(int) (pos % buffer.length)]; } synchronized int size() { ret size; } synchronized int capacity() { ret buffer.length; } synchronized bool isFull() { ret size() == capacity(); } synchronized long getBase() { ret base; } }