You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/03/11 18:28:29 UTC
[03/19] incubator-tinkerpop git commit: Add matches features to
IteratorUtils.
Add matches features to IteratorUtils.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/95666275
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/95666275
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/95666275
Branch: refs/heads/newapi
Commit: 95666275c4e93343055a0d2f5e967e3048612756
Parents: de553fc
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Mar 10 08:16:31 2015 -0400
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Mar 10 08:16:31 2015 -0400
----------------------------------------------------------------------
.../gremlin/util/iterator/IteratorUtils.java | 30 ++++++++++++++++++++
1 file changed, 30 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/95666275/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java
index 56cc93e..7d37a5d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/iterator/IteratorUtils.java
@@ -90,6 +90,36 @@ public final class IteratorUtils {
return fill(iterator, new ArrayList<>());
}
+ public static <T> boolean allMatch(final Iterator<T> iterator, final Predicate<T> predicate) {
+ while (iterator.hasNext()) {
+ if (!predicate.test(iterator.next())) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public static <T> boolean anyMatch(final Iterator<T> iterator, final Predicate<T> predicate) {
+ while (iterator.hasNext()) {
+ if (predicate.test(iterator.next())) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public static <T> boolean noneMatch(final Iterator<T> iterator, final Predicate<T> predicate) {
+ while (iterator.hasNext()) {
+ if (predicate.test(iterator.next())) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
public static <K, S> Map<K, S> collectMap(final Iterator<S> iterator, final Function<S, K> key) {
return collectMap(iterator, key, Function.identity());
}