You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by "Andy Seaborne (JIRA)" <ji...@apache.org> on 2017/12/06 14:38:00 UTC

[jira] [Resolved] (JENA-1427) Add nextOrElse() method in ExtendedIterator

     [ 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)

Re: [jira] [Resolved] (JENA-1427) Add nextOrElse() method in ExtendedIterator

Posted by ajs6f <aj...@apache.org>.
> You can call nextOptional() forever which is odd.

This is just as true of nextOrElse*, so they're not better in that regard.

I agree that the semantics don't really work here, and I think Claude is right to point at Streams as the place Optional really fits (e.g. Stream::findFirst).

ExtendedIterator (< Iterator) just isn't a Stream.

ajs6f

> On Dec 6, 2017, at 12:21 PM, Andy Seaborne <an...@apache.org> wrote:
> 
> 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)" <ji...@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)
>>> 


Re: [jira] [Resolved] (JENA-1427) Add nextOrElse() method in ExtendedIterator

Posted by Andy Seaborne <an...@apache.org>.
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)" <ji...@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)
>>
> 

Re: [jira] [Resolved] (JENA-1427) Add nextOrElse() method in ExtendedIterator

Posted by ajs6f <aj...@apache.org>.
> methods to convert the iterator to a stream should be sufficient.  And i believe that has been implemented

I would say that actually having streams from the API would be sufficient, but we are a long way from that. (We should restart that thread about a potential new API with immutability and streams and possibly more.)

ajs6f

> On Dec 6, 2017, at 10:21 AM, Claude Warren <cl...@xenei.com> wrote:
> 
> Is optional.get() == null an expected or acceptable solution?  I supose it
> might be in this case.  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)" <ji...@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)
>> 


Re: [jira] [Resolved] (JENA-1427) Add nextOrElse() method in ExtendedIterator

Posted by Claude Warren <cl...@xenei.com>.
Is optional.get() == null an expected or acceptable solution?  I supose it
might be in this case.  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)" <ji...@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)
>