This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new f5453b1 Tweak `exists` and add a test
f5453b1 is described below
commit f5453b1eafedb4d37c50ff52fa711db65f9dcefe
Author: Daniel Sun <[email protected]>
AuthorDate: Sun Nov 22 01:28:21 2020 +0800
Tweak `exists` and add a test
---
.../apache/groovy/ginq/provider/collection/runtime/Queryable.java | 2 +-
.../provider/collection/runtime/QueryableCollectionTest.groovy | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/Queryable.java
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/Queryable.java
index 29f9b0e..083c0b8 100644
---
a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/Queryable.java
+++
b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/runtime/Queryable.java
@@ -219,7 +219,7 @@ public interface Queryable<T> {
* @return the result of checking, {@code true} if result is not empty,
otherwise {@code false}
*/
default boolean exists() {
- return stream().count() > 0;
+ return count() > 0;
}
/**
diff --git
a/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollectionTest.groovy
b/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollectionTest.groovy
index 965f3d4..4acbcd8 100644
---
a/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollectionTest.groovy
+++
b/subprojects/groovy-ginq/src/test/groovy/org/apache/groovy/ginq/provider/collection/runtime/QueryableCollectionTest.groovy
@@ -491,6 +491,13 @@ class QueryableCollectionTest {
assert nums == result
}
+ @Test
+ void testExists() {
+ def nums = [1, 2, 3]
+ def result = from(nums).exists()
+ assert result
+ }
+
@ToString
@EqualsAndHashCode
static class Person {