Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-876

support closure with 2 params in default Method collect(Map, Collection, Closure)

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-JSR-1
    • 1.0-JSR-4
    • groovy-jdk
    • None
    • All

    Description

      /**

      • Iterates through this Map transforming each entry into a new value using the closure
      • as a transformer, returning a list of transformed values.
        *
      • @param self a Map
      • @param closure the closure used for mapping, which can be with one(Map.Entry) or two(key, value) parameters
      • @return a List of the mapped values
        */
        public static Collection collect(Map self, Collection collection, Closure closure) {
        boolean isTwoParams = (closure.getParameterTypes().length == 2);
        for (Iterator iter = self.entrySet().iterator(); iter.hasNext() {
        if (isTwoParams)
        Unknown macro: { Map.Entry entry = (Map.Entry) iter.next(); collection.add(closure.call(new Object[]{entry.getKey(), entry.getValue()})); }

        else

        { collection.add(closure.call(iter.next())); }

        }
        return collection;
        }

      Attachments

        1. Collect_Map.testcase.patch.txt
          0.7 kB
          wangbin
        2. collect_Map.Patch.txt
          1 kB
          wangbin

        Activity

          People

            meling Hein Meling
            wangbin wangbin
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: