Sequenced Collections

Ernie Rael errael at raelity.com
Tue Sep 20 19:08:39 UTC 2022


(There may be a better place to send this, let me know where)

Suggesting an option to limit the size of the collection, e.g 
"setMaxSize(int)", default of zero means no limit.

I put together "interface MRU<E> extends Collection<E>" some months ago, 
it has two implementations based on LinkedList and LinkedHashSet. The 
code can be seen at 
https://sourceforge.net/p/jvi/raelity-lib/ci/default/tree/lib/src/main/java/com/raelity/lib/

A SequencedCollection, as outlined in the JEP draft 2020/09/01, would be 
almost perfect to implement MRU; I've run into most of the 
problems/issues discussed in the JEP draft.

The MRU is a cache, as I use it; it typically has a max size for the 
collection. Handling this natively in the collection would be ideal; if 
an add operation would overflow, remove the item at the other end. Note 
that addAll() is used when initializing from backing store.

FYI, I use a "Supplier<Integer>" to the constructor to provide maxSize, 
but a property makes much more sense. I'll make that change in MRU for 
sanity, and get rid of the trim() method. setMaxSize can do the trim.

-ernie



More information about the core-libs-dev mailing list