ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sevdoki...@apache.org
Subject [1/2] incubator-ignite git commit: # IGNITE-289 Create IgniteIterators and IgniteIterable utility classes.
Date Thu, 07 May 2015 16:28:06 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-289 [created] 12fa88943


# IGNITE-289 Create IgniteIterators and IgniteIterable utility classes.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/8b61e1c9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/8b61e1c9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/8b61e1c9

Branch: refs/heads/ignite-289
Commit: 8b61e1c963f2dad4ccc08064f46911bf04fb05bd
Parents: 4cf2133
Author: sevdokimov <sevdokimov@gridgain.com>
Authored: Thu May 7 19:20:53 2015 +0300
Committer: sevdokimov <sevdokimov@gridgain.com>
Committed: Thu May 7 19:20:53 2015 +0300

----------------------------------------------------------------------
 .../ignite/internal/util/IgniteIterables.java   | 107 +++++++++++++++++++
 .../ignite/internal/util/IgniteIterators.java   |  82 ++++++++++++++
 2 files changed, 189 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8b61e1c9/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteIterables.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteIterables.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteIterables.java
new file mode 100644
index 0000000..0c1dc66
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteIterables.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.util;
+
+import org.apache.ignite.internal.util.lang.*;
+import org.apache.ignite.lang.*;
+import org.jetbrains.annotations.*;
+
+import java.util.*;
+
+/**
+ *
+ */
+@SuppressWarnings("PublicInnerClass")
+public class IgniteIterables {
+    /**
+     * Private constructor.
+     */
+    private IgniteIterables() {
+        // No-op.
+    }
+
+    /**
+     * @param iterable Input iterable.
+     * @param filter Filter.
+     */
+    public static <T> Iterable<T> filter(@NotNull Iterable<T> iterable,
@NotNull IgnitePredicate<T> filter) {
+        return new FilteredIterable<>(iterable, filter);
+    }
+    /**
+     * @param iterable Input iterable.
+     * @param trans Transformation closure.
+     */
+    public static <T1, T2> Iterable<T2> transform(@NotNull Iterable<T1>
iterable,
+        @NotNull IgniteClosure<? super T1, T2> trans) {
+        return new TransformedIterable<>(iterable, trans);
+    }
+
+    /**
+     *
+     */
+    public static class TransformedIterable<T1, T2> implements Iterable<T2> {
+        /** */
+        private final Iterable<T1> src;
+
+        /** */
+        private final IgniteClosure<? super T1, T2> trans;
+
+        /**
+         * @param src Source.
+         * @param trans Trans.
+         */
+        public TransformedIterable(Iterable<T1> src, IgniteClosure<? super T1, T2>
trans) {
+            this.src = src;
+            this.trans = trans;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Iterator<T2> iterator() {
+            return IgniteIterators.transform(src.iterator(), trans);
+        }
+    }
+
+    /**
+     *
+     */
+    public static class FilteredIterable<T> implements Iterable<T> {
+        /** */
+        private final Iterable<T> src;
+
+        /** */
+        private final IgnitePredicate<T> filter;
+
+        /**
+         * @param src Iterable.
+         * @param filter Filter.
+         */
+        public FilteredIterable(Iterable<T> src, IgnitePredicate<T> filter) {
+            this.src = src;
+            this.filter = filter;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Iterator<T> iterator() {
+            return new GridFilteredIterator<T>(src.iterator()) {
+                @Override protected boolean accept(T t) {
+                    return filter.apply(t);
+                }
+            };
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8b61e1c9/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteIterators.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteIterators.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteIterators.java
new file mode 100644
index 0000000..33a9e43
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteIterators.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.util;
+
+import org.apache.ignite.lang.*;
+import org.jetbrains.annotations.*;
+
+import java.util.*;
+
+/**
+ *
+ */
+@SuppressWarnings("PublicInnerClass")
+public class IgniteIterators {
+    /**
+     * Private constructor.
+     */
+    private IgniteIterators() {
+        // No-op.
+    }
+
+    /**
+     * @param itr Itr.
+     * @param trans Trans.
+     */
+    public static <T1, T2> Iterator<T2> transform(@NotNull Iterator<T1>
itr,
+        @NotNull IgniteClosure<? super T1, T2> trans) {
+        return new TransformIterator<>(itr, trans);
+    }
+
+    /**
+     *
+     */
+    public static class TransformIterator<T1, T2> implements Iterator<T2> {
+        /** */
+        private final Iterator<T1> src;
+
+        /** */
+        private final IgniteClosure<? super T1, T2> trans;
+
+        /**
+         * @param src Source.
+         * @param trans Trans.
+         */
+        public TransformIterator(Iterator<T1> src, IgniteClosure<? super T1, T2>
trans) {
+            this.src = src;
+            this.trans = trans;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean hasNext() {
+            return src.hasNext();
+        }
+
+        /** {@inheritDoc} */
+        @Override public T2 next() {
+            T1 res = src.next();
+
+            return trans.apply(res);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void remove() {
+            src.remove();
+        }
+    }
+}


Mime
View raw message