[
https://issues.apache.org/jira/browse/JCR-3555?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13620706#comment-13620706
]
Lukas Eder commented on JCR-3555:
---------------------------------
+1 for naming the utility method "in()". That makes it very readable.
+1 also for moving it to JcrUtils.
I see your point for the naming conventions in JcrUtils. I must've missed that
correlation.
You're right about some Iterables being able to re-fetch the original Iterator
in the rare case it is requested twice. In case this doesn't work, the wrapper
could throw an IllegalStateException to indicate misusage. I'm still in favour
of clearly declaring the intent by returning a type called "OneShotIterable" or
something similar.
Note, I've found this to be a very interesting question worth clearing on Stack
Overflow. Let's see what a broader audience will think:
http://stackoverflow.com/q/15781739/521799
Besides, commons-collections already solved this issue. Consider
- IteratorUtils.asIterable(Iterator)
- IteratorUtils.asMultipleUseIterable(Iterator)
From:
https://github.com/apache/commons-collections/blob/trunk/src/main/java/org/apache/commons/collections/IteratorUtils.java
https://github.com/apache/commons-collections/blob/trunk/src/main/java/org/apache/commons/collections/iterators/IteratorIterable.java
> Add a static utility to transform JCR Iterators into Iterables
> --------------------------------------------------------------
>
> Key: JCR-3555
> URL: https://issues.apache.org/jira/browse/JCR-3555
> Project: Jackrabbit Content Repository
> Issue Type: Improvement
> Components: jackrabbit-jcr-commons
> Affects Versions: 2.6
> Reporter: Lukas Eder
> Priority: Minor
> Attachments: Iterators.java.patch
>
>
> I have stumbled upon the utility classes in the
> org.apache.jackrabbit.commons.iterator package. They're quite useful in
> principle, but not applied thoroughly. E.g. there are missing wrapper types
> for at least these JCR Iterators:
> - AccessControlPolicyIterator
> - EventIterator
> - EventListenerIterator
> - NodeTypeIterator
> - VersionIterator
> Instead of adding more classes, it might be useful to create static methods
> for the job. Using static methods from a single class (with static imports)
> is a bit more convenient than looking up and creating the wrapper types using
> "new WrapperType(...)"
> An example:
> org.apache.jackrabbit.commons.iterator.Iterators.iterable
> // And then:
> for (Node n : iterable(parent.getNodes())) {
> // Do stuff with n
> }
> Please find attached a .patch file containing an implementation suggestion.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira