Building sorted Spliterators for library authors

Paul Sandoz paul.sandoz at oracle.com
Tue Nov 19 16:44:40 UTC 2013


On Nov 19, 2013, at 4:50 PM, Louis Wasserman <lowasser at google.com> wrote:

> Is there a convenient way of building a Spliterator SORTED by a given
> Comparator, from, say, an array?

Unfortunately not. There are no factory methods in j.u.Splitrerators that accept Comparator as a parameter, and as you note below we do not expose the Spliterator impls.

You could wrap/proxy a Spliterator instance, but i suspect you will find that ugly, so you probably need to roll your own implementation and duplicate as appropriate from the JDK impls.


>  From what I can tell, SortedSet's default
> implementation uses a private IteratorSpliterator API.
> 

Yes, and that is a poorly splitting Spliterator since the default implementation can only obtain elements from the Iterator.

If your Spliterator covers an array you will probably want to implement better splitting.

Hth,
Paul.




More information about the core-libs-dev mailing list