Re: Recommended way to get an empty XdmSequenceIterator?
Michael Kay <mike-JkSD5nQpfvpWk0Htik3J/[email protected]> Sat, 17 Oct 2020 09:40:02 +0100
| Newsgroups | gmane.text.xml.saxon.help |
|---|---|
| Message-ID | <[email protected]> |
Thanks for raising it. I think the simplest solution is to change XdmValue.iterator() to declare its return type as XdmSequenceIterator. Michael Kay Saxonica > On 17 Oct 2020, at 00:46, Chapman Flack <chap-JULfBfA8satPFr4CO1/[email protected]> wrote: > > Hi, > > I have a simple case where ordinarily I will get an > XdmSequenceIterator<XdmItem> as the result of XQueryEvaluator.iterator(), > and pass that to a consumer method that does expect an > XdmSequenceIterator<XdmItem> (so as to be able to close it, if > the full result isn't needed). > > But in another case that's detectable, I should skip the evaluator and > just pass the consumer method an empty XdmSequenceIterator<XdmItem> instead. > > My first instinct was to use XdmEmptySequence.getInstance().iterator(), > but that returns a java.util.Iterator, not an XdmSequenceIterator. > > I seem to have been getting away with casting that java.util.Iterator > to an XdmSequenceIterator<XdmItem>, but it seems a bit smelly to assume > that is what will be returned, and cast to an assumed generic type. > > I could import EmptyIterator from net.sf.saxon.tree.iter and construct > an XdmSequenceIterator from an instance of that. But then I end up > suppressing both an unchecked-cast and a raw-type warning, because the > XdmSequenceIterator constructor returns a raw type. > > So I think for now I will stick with the assumption and cast. > > Maybe XdmSequenceIterator should just have an emptyIterator() method of > its own? > > Or perhaps a generic > > static <T extends XdmItem> > XdmSequenceIterator<T> of(java.util.Iterator<T> iter) > > that just returns an appropriately-typed XdmSequenceIterator whose close() > does nothing, from an arbitrary java.util.Iterator? It could internally > just be a cast, if the argument is already an XdmSequenceIterator. > > Regards, > -Chap > > > _______________________________________________ > saxon-help mailing list archived at http://saxon.markmail.org/ > [email protected] > https://lists.sourceforge.net/lists/listinfo/saxon-help _______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ [email protected] https://lists.sourceforge.net/lists/listinfo/saxon-help