java - FIFO buffer with a limited capacity that overrides oldest elements -


this question has answer here:

i'm trying create fifo (first in first out) data structure in java, have limited capacity , remove oldest elements when there not enough space new ones. example:

fifo<integer> fifo = new fifo<integer>(100); // 100 elements maximum (int = 0; < 500; i++) {   fifo.write(i); } assert fifo.read() == 400; // elements 0..399 lost 

am re-inventing wheel? can recommend library (or maybe it's part of jdk) same? thread safety not important.

apache's common.collections has circularfifobuffer should meet requirements.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -