guava
guava copied to clipboard
iterate EvictingQueue backwards
EvictingQueue is mostly a wrapper over ArrayDeque which have a descendingIterator.
EvictingQueue's only constructor is private, so I can't extend the class.
And delegate() is also protected.
Either the constructor should be made protected or delegate public, I think, so I could do what I want
I wonder why I made EvictingQueue extend ForwardingQueue instead of ForwardingDeque...hmm. Maybe we didn't want the conceptual weight of all of the Deque API cluttering up the API?
Hello, @kluever I think I can take care of this issue. Would you let me?
I think we'd want to hear some use cases first for why you'd want to iterate an EvictingQueue backwards before we make any changes.
Use case? Well. Maybe I shot myself in the foot with this. I use an EvictingQueue as an easy way for logging, keeping events restricted to the last x events and forgetting older. Now when I print this "log" by iterating it starts with the oldest entry. But mostly I'm interested in the newest events, especially when outputting just a few of those.
Now its a pain to just print the last three events or to just look up at the newest event. :-(
✋ use case here! I wanted to use an EvictingQueue to keep around the most recent N items. When I need to process (not remove) items from the queue, I'm only interested in the most recent items which may or may not be all N items. e.g. I may keep around 20 things but might only be interested in the most recent 10 right now. There's no easy way to do this with EvictingQueue, so I'm forced to use another Deque implementation and manually evict things when necessary.