guava icon indicating copy to clipboard operation
guava copied to clipboard

iterate EvictingQueue backwards

Open guai opened this issue 5 years ago • 5 comments

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

guai avatar Nov 15 '18 12:11 guai

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?

kluever avatar Nov 15 '18 23:11 kluever

Hello, @kluever I think I can take care of this issue. Would you let me?

amsukdu avatar May 20 '19 09:05 amsukdu

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.

kluever avatar May 20 '19 16:05 kluever

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. :-(

xberger avatar Nov 02 '21 15:11 xberger

✋ 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.

dacunni1 avatar Dec 31 '21 21:12 dacunni1