Add support for NagivableSet like SortedSetIterable
Hello,
First of all, thanks for this incredible collection framework.
One small gripe I have with SortedSetIterable is the feature gap with TreeSet :
- methods such as floor, ceiling... have no equivalents
- current implementations of
MutableSortedSetthrowUnsupportedOperationExceptioninReversibleIterable.toReversed, which would be equivalent toNavigableSet.descendingSet
If it's possible, it would be great to make SortedSetIterable somewhat similar feature-wise to NavigableSet, and MutableSortedSet implement NavigableSet directly.
I agree. @tampix are you interested in working on this idea?
Hi @motlin , I would like to pick and work on this issue. Please assign to me.
@shubhanjayt we generally don't assign issues but feel free to work on this and submit a PR when ready!
@motlin
I was pretty busy so I almost forgot I had this ticket pending.
I just started a PoC to implement that feature : https://github.com/tampix/eclipse-collections/commit/bf6206971b23ed0a7ed9feab547cbe0066ee003d#diff-df8ee2f2ad9cc4c2fca5852e9b3b1aeeb8d3525056e640ae5968c12aaf4ced40
One questionable choice I made was to replicate the NavigableSet interface 1:1.
Pros :
- I see no benefit to add new APIs while this one already exists.
- Developers are used to it so no learning curve.
Cons :
- This forces the methods implemented in AbstractImmutableSortedSet (and it's subclasses) to return the actual type instead of the ImmutableSortedSet interface to work with the intersection of NavigableSet and ImmutableSortedSet (e.g.
NavigableSet<T> headSet(T, boolean)vsImmutableSortedSet<T> headSet(T, boolean)would clash because ImmutableSortedSet doesn't extend NavigableSet), butAbstractImmutableSortedSet<T> headSet(T, boolean)would not. - This forces the SortedSetAdapter to check at runtime for support of NavigableSet operation, depending on the underlying. Imo, this can be tolerated as the most common use case is java.util.TreeSet, and it can be documented. This could be improved by falling back to a less efficient solutions for those methods on non-NavigableSet delegates.
ps: I'll open a PR once I've got unit tests ready. If you see this message beforehand and think the approach isn't the right one, don't hesitate to reach out to me.
pps: If the approach seems ok, I could also see to replicate that for SortedMapIeterable/NavigableMap :)