You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by "Jukka Zitting (JIRA)" <ji...@apache.org> on 2013/04/08 11:41:17 UTC

[jira] [Commented] (JCR-3561) Add JcrUtils.collect(Iterable) and collect(Iterator) to conveniently collect Nodes / Properties into Lists

    [ https://issues.apache.org/jira/browse/JCR-3561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13625255#comment-13625255 ] 

Jukka Zitting commented on JCR-3561:
------------------------------------

How about using something like Lists.newArrayList(Iterable<T>) from Guava? I'd rather see the scope of JcrUtils to remain bound to JCR-specific utilities.
                
> Add JcrUtils.collect(Iterable) and collect(Iterator) to conveniently collect Nodes / Properties into Lists
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: JCR-3561
>                 URL: https://issues.apache.org/jira/browse/JCR-3561
>             Project: Jackrabbit Content Repository
>          Issue Type: Improvement
>          Components: jackrabbit-jcr-commons
>    Affects Versions: 2.7
>            Reporter: Lukas Eder
>            Priority: Minor
>         Attachments: JcrUtils.java.patch
>
>
> I repetitively find myself collecting nodes / properties into Lists as I want to perform multiple operations on a list of nodes (e.g. calling size() upon it). Instead of repeating this operation in client code, I'd like to add JcrUtils.collect(...) for this. These would be some sample implementations:
>     /**
>      * Collect all elements from an {@link Iterable} into a {@link List}.
>      *
>      * @param iterable The <code>Iterable</code> to collect values from.
>      * @return The collection result.
>      */
>     public static <T> List<T> collect(Iterable<T> iterable) {
>         List<T> result = new ArrayList<T>();
>         for (T value : iterable) {
>             result.add(value);
>         }
>         return result;
>     }
>     /**
>      * Collect all elements from an {@link Iterator} into a {@link List}.
>      *
>      * @param iterator The <code>Iterator</code> to collect values from.
>      * @return The collection result.
>      */
>     public static <T> List<T> collect(Iterator<T> iterator) {
>         return collect(in(iterator));
>     }
> I've also attached a patch containing the above. I'm sure that these methods will also be useful to Jackrabbit core libraries.
> Feel free to rename the method, e.g. to "list()" or "toList()" if you find that more suitable.

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