I'm trying to create a FIFO (first in first out) data structure in Java, which would have a limited capacity and remove the oldest elements when there is not enough space for new ones. For example:
FIFO<Integer> fifo = new FIFO<Integer>(100); // 100 elements maximum
for (int i = 0; i < 500; i++) {
fifo.write(i);
}
assert fifo.read() == 400; // elements 0..399 are lost
Am I re-inventing a wheel? Can you recommend some library (or maybe it's part of JDK) that does the same? Thread safety is not important.