You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2017/03/22 20:44:37 UTC
groovy git commit: DefaultGroovyMethods: add javadoc examples for
#find and #findResult
Repository: groovy
Updated Branches:
refs/heads/GROOVY_2_4_X a4aec412c -> 5a4db3c22
DefaultGroovyMethods: add javadoc examples for #find and #findResult
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/5a4db3c2
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/5a4db3c2
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/5a4db3c2
Branch: refs/heads/GROOVY_2_4_X
Commit: 5a4db3c221dd70615a86d49b4efe7cbd84f7a8c1
Parents: a4aec41
Author: pascalschumacher <pa...@gmx.net>
Authored: Wed Mar 22 21:44:28 2017 +0100
Committer: pascalschumacher <pa...@gmx.net>
Committed: Wed Mar 22 21:44:28 2017 +0100
----------------------------------------------------------------------
.../groovy/runtime/DefaultGroovyMethods.java | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/5a4db3c2/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 e99b207..f192585 100644
--- a/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -3829,7 +3829,13 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
}
/**
- * Finds the first value matching the closure condition
+ * Finds the first value matching the closure condition.
+ *
+ * <pre class="groovyTestCase">
+ * def numbers = [1, 2, 3]
+ * def result = numbers.find { it > 1}
+ * assert result == 2
+ * </pre>
*
* @param self an Object with an iterator returning its values
* @param closure a closure condition
@@ -3868,6 +3874,12 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
/**
* Treats the object as iterable, iterating through the values it represents and returns the first non-null result obtained from calling the closure, otherwise returns the defaultResult.
*
+ * <pre class="groovyTestCase">
+ * int[] numbers = [1, 2, 3]
+ * assert numbers.findResult(5) { if(it > 1) return it } == 2
+ * assert numbers.findResult(5) { if(it > 4) return it } == 5
+ * </pre>
+ *
* @param self an Object with an iterator returning its values
* @param defaultResult an Object that should be returned if all closure results are null
* @param closure a closure that returns a non-null value when processing should stop
@@ -3883,6 +3895,12 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
/**
* Treats the object as iterable, iterating through the values it represents and returns the first non-null result obtained from calling the closure, otherwise returns null.
*
+ * <pre class="groovyTestCase">
+ * int[] numbers = [1, 2, 3]
+ * assert numbers.findResult { if(it > 1) return it } == 2
+ * assert numbers.findResult { if(it > 4) return it } == null
+ * </pre>
+ *
* @param self an Object with an iterator returning its values
* @param closure a closure that returns a non-null value when processing should stop
* @return the first non-null result of the closure