class MessageQueue<T> { private T[] buffer = null; private int size = 0; public synchronized T pop() {
final T obj = size == 0? null : buffer[0];
if (size > 0 && obj != null)
buffer = Util.redim(–size, buffer, (Class<T>) obj.getClass());
return obj;
} public synchronized void push(final T obj) {
if (size + 1 > (buffer == null? 0: buffer.length))
buffer = Util.redim(size + 1, buffer, (Class<T>) obj.getClass());
buffer[size++] = obj;
}}