What this all shows to me is that Optional for end of iterator is not
what Optional is for.
next() has two return paths: an object reference or
NoSuchElementException. Converting NSEE into Optional goes against the
intent of Optional (see the EG email). The argument of reusing
machinery would be OK if the usage pattern was compatible.
You can call nextOptional() forever which is odd.
The nextOptional is looking like it does not stand up to scrutiny even
if we accept that ExtendedIterator does not yield nulls.
Which leaves nextOrElse*
On 06/12/17 15:21, Claude Warren wrote:
Is optional.get() == null an expected or acceptable solution? I supose it
might be in this case.
Checking the code it looks like you can't create an optional with null
in it. The JDK will throw NPE.
However i am beginning to believe that streaming
operations should not be applied to iterators and rather that methods to
convert the iterator to a stream should be sufficient. And i believe that
has been implemented.
Claude
On 6 Dec 2017 15:38, "Andy Seaborne (JIRA)" <j...@apache.org> wrote:
[ https://issues.apache.org/jira/browse/JENA-1427?page=
com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Andy Seaborne resolved JENA-1427.
---------------------------------
Resolution: Done
Assignee: Andy Seaborne
Fix Version/s: Jena 3.6.0
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
Assignee: Andy Seaborne
Priority: Trivial
Labels: easytask
Fix For: Jena 3.6.0
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)