[ https://issues.apache.org/jira/browse/JCR-3561?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Lukas Eder updated JCR-3561: ---------------------------- Attachment: JcrUtils.java.patch > 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