code: protected static <T> T callClosureForMapEntryAndCounter(Closure<T> closure, Map.Entry entry, int counter) {
          if (closure.getMaximumNumberOfParameters() == 3) {
              return closure.call(new Object[]{entry.getKey(), entry.getValue(), counter});
          }
          if (closure.getMaximumNumberOfParameters() == 2) {
              return closure.call(new Object[]{entry, counter});
          }
          return closure.call(entry);
      }
docs: internal helper method