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 2020/03/09 02:05:41 UTC

[groovy] 02/02: GROOVY-9450: add test case

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 8c81fbea5011e3622abc0244bdd9d215a3e26f93
Author: Paul King <pa...@asert.com.au>
AuthorDate: Mon Mar 9 11:55:04 2020 +1000

    GROOVY-9450: add test case
---
 .../groovy/runtime/DefaultGroovyMethods.java         | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index c37df1d..c06d628 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -17149,6 +17149,17 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
      * Iterates over the elements of an aggregate of items, starting from a
      * specified startIndex, and returns the index of the first item that matches the
      * condition specified in the closure.
+     * Example (aggregate is {@code ChronoUnit} enum values):
+     * <pre class="groovyTestCase">
+     * import java.time.temporal.ChronoUnit
+     * def nameStartsWithM = { it.name().startsWith('M') }
+     * def first  = ChronoUnit.findIndexOf(nameStartsWithM)
+     * def second = ChronoUnit.findIndexOf(first + 1, nameStartsWithM)
+     * def third  = ChronoUnit.findIndexOf(second + 1, nameStartsWithM)
+     * Set units  = [first, second, third]
+     * assert !units.contains(-1) // should have found 3 of MICROS, MILLIS, MINUTES, MONTHS, ...
+     * assert units.size() == 3 // just check size so as not to rely on order
+     * </pre>
      *
      * @param self       the iteration object over which to iterate
      * @param startIndex start matching from this index
@@ -17260,6 +17271,15 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
     /**
      * Iterates over the elements of an aggregate of items and returns
      * the index of the last item that matches the condition specified in the closure.
+     * Example (aggregate is {@code ChronoUnit} enum values):
+     * <pre class="groovyTestCase">
+     * import java.time.temporal.ChronoUnit
+     * def nameStartsWithM = { it.name().startsWith('M') }
+     * def first = ChronoUnit.findIndexOf(nameStartsWithM)
+     * def last  = ChronoUnit.findLastIndexOf(nameStartsWithM)
+     * // should have found 2 unique index values for MICROS, MILLIS, MINUTES, MONTHS, ...
+     * assert first != -1 && last != -1 && first != last
+     * </pre>
      *
      * @param self      the iteration object over which to iterate
      * @param condition the matching condition