Uploaded image for project: 'Jackrabbit Content Repository'
  1. Jackrabbit Content Repository
  2. JCR-3561

Add JcrUtils.collect(Iterable) and collect(Iterator) to conveniently collect Nodes / Properties into Lists

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Not A Problem
    • 2.7
    • None
    • jackrabbit-jcr-commons
    • None

    Description

      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.

      Attachments

        1. JcrUtils.java.patch
          1 kB
          Lukas Eder

        Activity

          People

            Unassigned Unassigned
            lukas.eder Lukas Eder
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: