Reputation: 22052
I am currently looking at consolidating to a single collections library in a project I'm involved in, and though I have little experience with it, I really like the look of Eclipse Collections.
One concrete use case we have is that we use a Map
implementation with soft value references in several places as a simple cache. We currently use Apache Commons Collections' ReferenceMap
for this purpose, for example:
private final Map<Integer, Long[]> cache = new ReferenceMap<>();
Of course this can be replaced by a standard Java HashMap
where the value is an SoftReference
implementation, but I was hoping Eclipse Collections had a similar "convenience" collection type or factory/builder for this purpose. Is there such a thing? Or perhaps more broadly formulated: how would I set up a Map with soft value references using Eclipse Collections and a minimum amount of boilerplate?
Upvotes: 2
Views: 219
Reputation: 6706
Eclipse Collections does not currently have a WeakValueHashMap
or SoftValueHashMap
. I also can't think off hand of a way of setting one up with minimal boiler plate without implementing them. If you want to use the Eclipse Collections MutableMap
API instead of Map
, you can adapt the ReferenceMap
above.
private final MutableMap<Integer, Long[]> cache = Maps.adapt(new ReferenceMap<>());
This won't help you get rid of the Apache Commons dependency, but gets you a step closer to a consistent API usage.
If you are interested in contributing to Eclipse Collections, there is certainly room for WeakValueHashMap
and SoftValueHashMap
implementations.
Upvotes: 2