You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Julian Reschke (Jira)" <ji...@apache.org> on 2024/09/07 10:28:00 UTC
[jira] [Comment Edited] (OAK-11073) Create conversion utils in oak-commons to convert iterables/iterators to set/list
[ https://issues.apache.org/jira/browse/OAK-11073?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17880019#comment-17880019 ]
Julian Reschke edited comment on OAK-11073 at 9/7/24 10:27 AM:
---------------------------------------------------------------
Another common case where JDK usage leads to very verbose code: obtaining a stream from an Iterator/Iterable.
The latter case requires usage of
https://docs.oracle.com/en%2Fjava%2Fjavase%2F11%2Fdocs%2Fapi%2F%2F/java.base/java/util/stream/StreamSupport.html#stream(java.util.Spliterator,boolean)
..and the former case needs prior conversion of an Iterator to an Iterable, such as
{noformat}
Iterator x...
Iterable y = () -> x;
{noformat}
(and that's kind of a hack because it doesn't prevent calliny y.getIterator()) multiple times.
Proposal: add utilities:
{noformat}
public static Iterable toIterable(Iterator)
public static Stream toStream(Iterator)
public static Stream toStream(Iterable)
{noformat}
Should I go ahead with this?
Like that: [^stream-it.diff]
was (Author: reschke):
Another common case where JDK usage leads to very verbose code: obtaining a stream from an Iterator/Iterable.
The latter case requires usage of
https://docs.oracle.com/en%2Fjava%2Fjavase%2F11%2Fdocs%2Fapi%2F%2F/java.base/java/util/stream/StreamSupport.html#stream(java.util.Spliterator,boolean)
..and the former case needs prior conversion of an Iterator to an Iterable, such as
{noformat}
Iterator x...
Iterable y = () -> x;
{noformat}
(and that's kind of a hack because it doesn't prevent calliny y.getIterator()) multiple times.
Proposal: add utilities:
{noformat}
public static Iterable toIterable(Iterator)
public static Stream toStream(Iterator)
public static Stream toStream(Iterable)
{noformat}
Should I go ahead with this?
> Create conversion utils in oak-commons to convert iterables/iterators to set/list
> ---------------------------------------------------------------------------------
>
> Key: OAK-11073
> URL: https://issues.apache.org/jira/browse/OAK-11073
> Project: Jackrabbit Oak
> Issue Type: Technical task
> Components: commons
> Reporter: Rishabh Daim
> Assignee: Julian Reschke
> Priority: Major
> Fix For: 1.70.0
>
> Attachments: stream-it.diff
>
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)