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:10 UTC
[27/50] [abbrv] groovy git commit: DefaultGroovyMethods: add javadoc
examples for #find and #findResult
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/4432ca28
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/4432ca28
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/4432ca28
Branch: refs/heads/parrot
Commit: 4432ca286d4f1c537acd9407f2f143cf362e714d
Parents: c155e9d
Author: pascalschumacher <pa...@gmx.net>
Authored: Wed Mar 22 21:44:28 2017 +0100
Committer: pascalschumacher <pa...@gmx.net>
Committed: Wed Mar 22 21:46:54 2017 +0100
----------------------------------------------------------------------
.../groovy/runtime/DefaultGroovyMethods.java | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/4432ca28/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 68a9efd..a8b6868 100644
--- a/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -3984,7 +3984,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
@@ -4023,6 +4029,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
@@ -4038,6 +4050,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