groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pascalschumac...@apache.org
Subject [1/2] incubator-groovy git commit: add org.codehaus.groovy.runtime.DefaultGroovyMethods.isEmpty(Iterable)
Date Sun, 01 Nov 2015 11:50:46 GMT
Repository: incubator-groovy
Updated Branches:
  refs/heads/master 94bcd4a45 -> a28c72afe


add org.codehaus.groovy.runtime.DefaultGroovyMethods.isEmpty(Iterable)


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

Branch: refs/heads/master
Commit: 77677bcc50ad307b0e1705c605cc5d12b83ed471
Parents: 94bcd4a
Author: Jochen Kemnade <jochen.kemnade@eddyson.de>
Authored: Wed Aug 19 14:19:16 2015 +0200
Committer: pascalschumacher <pascalschumacher@gmx.net>
Committed: Sun Nov 1 10:54:00 2015 +0100

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


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/77677bcc/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 e1fe2c1..26f6e20 100644
--- a/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -6811,6 +6811,25 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport
{
     }
 
     /**
+     * Check whether an <code>Iterable</code> has elements
+     * <pre class="groovyTestCase">
+     * def items = [1]
+     * def iterable = { [ hasNext:{ !items.isEmpty() }, next:{ items.pop() } ] as Iterator
} as Iterable
+     * assert !iterable.isEmpty()
+     * iterable.next()
+     * assert iterable.isEmpty()
+     * </pre>
+     *
+     * @param self an Iterable
+     * @return true if the iterable has no elements, false otherwise
+     * @since 2.4.5
+     */
+    public static boolean isEmpty(Iterable self) {
+        return !self.iterator().hasNext();
+    }
+
+
+    /**
      * Support the range subscript operator for a List.
      * <pre class="groovyTestCase">def list = [1, "a", 4.5, true]
      * assert list[1..2] == ["a", 4.5]</pre>


Mime
View raw message