You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2017/04/07 13:31:06 UTC

[23/50] [abbrv] groovy git commit: DefaultGroovyMethods: add more javadoc examples for the each, eachWithIndex and every methods

DefaultGroovyMethods: add more javadoc examples for the each, eachWithIndex and every methods


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/97d8c9eb
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/97d8c9eb
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/97d8c9eb

Branch: refs/heads/parrot
Commit: 97d8c9ebd1608f2f93b8914971913ffe801809ba
Parents: d05cdcc
Author: pascalschumacher <pa...@gmx.net>
Authored: Sat Mar 18 11:38:45 2017 +0100
Committer: pascalschumacher <pa...@gmx.net>
Committed: Sat Mar 18 11:38:45 2017 +0100

----------------------------------------------------------------------
 .../groovy/runtime/DefaultGroovyMethods.java    | 27 ++++++++++++++++++++
 1 file changed, 27 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/97d8c9eb/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 219226f..68a9efd 100644
--- a/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -1976,6 +1976,12 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
 
     /**
      * Iterates through an array passing each array entry to the given closure.
+     * <pre class="groovyTestCase">
+     * String[] letters = ['a', 'b', 'c']
+     * String result = ''
+     * letters.each{ result += it }
+     * assert result == 'abc'
+     * </pre>
      *
      * @param self    the array over which we iterate
      * @param closure the closure applied on each array entry
@@ -1994,6 +2000,11 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * passing each item to the given closure.  Custom types may utilize this
      * method by simply providing an "iterator()" method.  The items returned
      * from the resulting iterator will be passed to the closure.
+     * <pre class="groovyTestCase">
+     * String result = ''
+     * ['a', 'b', 'c'].each{ result += it }
+     * assert result == 'abc'
+     * </pre>
      *
      * @param self    the object over which we iterate
      * @param closure the closure applied on each element found
@@ -2009,6 +2020,12 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * Iterates through an array,
      * passing each array element and the element's index (a counter starting at
      * zero) to the given closure.
+     * <pre class="groovyTestCase">
+     * String[] letters = ['a', 'b', 'c']
+     * String result = ''
+     * letters.eachWithIndex{ letter, index -> result += "$index:$letter" }
+     * assert result == '0:a1:b2:c'
+     * </pre>
      *
      * @param self    an array
      * @param closure a Closure to operate on each array entry
@@ -2030,6 +2047,11 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * Iterates through an aggregate type or data structure,
      * passing each item and the item's index (a counter starting at
      * zero) to the given closure.
+     * <pre class="groovyTestCase">
+     * String result = ''
+     * ['a', 'b', 'c'].eachWithIndex{ letter, index -> result += "$index:$letter" }
+     * assert result == '0:a1:b2:c'
+     * </pre>
      *
      * @param self    an Object
      * @param closure a Closure to operate on each item
@@ -2413,6 +2435,11 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * Iterates over every element of a collection, and checks whether all
      * elements are <code>true</code> according to the Groovy Truth.
      * Equivalent to <code>self.every({element -> element})</code>
+     * <pre class="groovyTestCase">
+     * assert [true, true].every()
+     * assert [1, 1].every()
+     * assert ![1, 0].every()
+     * </pre>
      *
      * @param self the object over which we iterate
      * @return true if every item in the collection matches the closure