[
https://issues.apache.org/jira/browse/JENA-1427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16257346#comment-16257346
]
Adam Jacobs commented on JENA-1427:
-----------------------------------
{{Optional}} does add an extra object and an extra call in the functional chain.
{noformat}
RDFNode object = model.listObjectsOfProperty(subject,
predicate).nextOptional().orElseThrow(() -> new IllegalStateException("No
objects found for subject and predicate..."));
{noformat}
But it would still solve my use case. Perhaps this is a better method for
ExtendedIterator?
{noformat}
public default Optional<T> nextOptional() {
return hasNext() ? Optional.of(next()) : Optional.empty();
}
{noformat}
I wouldn't mind having both methods! :)
> 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)