I am implementing a sliding window over a stream of events in Java. Therefore, I need a data structure that allows me to do the following:
add to the end of the data structure when new events occur;
delete from the beginning of the data structure when processing old events;
get standard random access ( size(), get(i)) to data structure elements; in general, typical List "read" operations;
effective for all of the above operations;
is not limited.
No other access is required. And no thread safety is required.
I am currently doing this with an ArrayList to get things going. But I want something more efficient; method remove(0)(2. above) is ineffective at ArrayList.
Numbers 1. and 2. are standard Queue - style operations. However, implementations Queuein the JDK (e.g. ArrayDeque ) do not allow get(i)in 3.
So, I am wondering if there are libraries that have such an implementation and are suitable for commercial use.
If not, I think I will attach to writing my own ...
Calum source
share