[ https://issues.apache.org/jira/browse/JENA-1427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16273015#comment-16273015 ]
ASF GitHub Bot commented on JENA-1427: -------------------------------------- Github user ajs6f commented on the issue: https://github.com/apache/jena/pull/323 I'm saying we don't do `orElseThrow` or any other `orElseX`, we leave that to `nextOptional().orElseThrow()`, etc. Then at iterator end, `nextOptional()` returns `empty` forever. If there are `null`s, it returns `empty`. If you want to know whether that is because there are many `null`s or because the iterator is done, you call `hasNext()`. Another way to put it: we shouldn't try to eliminate needing `hasNext()` with this-- if we want to do that, we should do something like `Spliterator::tryAdvance`, which is a whole different story. You can se how that would work a little with `Iterator::forEachRemaining`. You don't need `hasNext()` with that. > Add nextOrElse() method in ExtendedIterator > ------------------------------------------- > > Key: JENA-1427 > URL: https://issues.apache.org/jira/browse/JENA-1427 > Project: Apache Jena > Issue Type: Improvement > Components: Core > Affects Versions: Jena 3.5.0 > Reporter: Adam Jacobs > Priority: Trivial > Labels: easytask > > Allow a functional approach for returning a default value or throwing a > custom exception from a Jena iterator. > The following method may be added to the ExtendedIterator interface. > {noformat} > /** > Answer the next object, if it exists, otherwise invoke the > _supplier_. > */ > public default T nextOrElse( Supplier<T> supplier ) { > return hasNext() ? next() : supplier.get(); > } > {noformat} -- This message was sent by Atlassian JIRA (v6.4.14#64029)