You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/12/30 12:23:07 UTC
[1/4] ignite git commit: IGNITE-2263: Optimized not(...) and
retain(...) - no more varargs.
Repository: ignite
Updated Branches:
refs/heads/ignite-2263 6788b76fe -> 6f7de6ac2
IGNITE-2263: Optimized not(...) and retain(...) - no more varargs.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/8f43c59d
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/8f43c59d
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/8f43c59d
Branch: refs/heads/ignite-2263
Commit: 8f43c59d35a8036c2528613dffad6cb2ddca887e
Parents: 6788b76
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Dec 30 13:58:50 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Dec 30 13:58:50 2015 +0300
----------------------------------------------------------------------
.../ignite/internal/util/lang/GridFunc.java | 45 ++++++++++++++++++--
.../memory/MemoryEventStorageSpi.java | 1 +
2 files changed, 43 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/8f43c59d/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
index 736e933..31e1156 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
@@ -1008,6 +1008,25 @@ public class GridFunc {
/**
* Retains all elements in input collection that are evaluated to {@code true}
+ * by the given predicate.
+ *
+ * @param c Input collection.
+ * @param cp If {@code true} method creates collection not modifying input, otherwise does
+ * <tt>in-place</tt> modifications.
+ * @param p Predicates to filter by. If no predicates provides - all elements
+ * will be retained.
+ * @param <T> Type of collections.
+ * @return Collection of retain elements.
+ */
+ public static <T> Collection<T> retain(Collection<T> c, boolean cp, IgnitePredicate<? super T> p) {
+ A.notNull(c, "c");
+ A.notNull(p, "p");
+
+ return lose(c, cp, not(p));
+ }
+
+ /**
+ * Retains all elements in input collection that are evaluated to {@code true}
* by all given predicates.
*
* @param c Input collection.
@@ -1018,7 +1037,7 @@ public class GridFunc {
* @param <T> Type of collections.
* @return Collection of retain elements.
*/
- public static <T> Collection<T> retain(Collection<T> c, boolean cp, @Nullable IgnitePredicate<? super T>... p) {
+ public static <T> Collection<T> retain(Collection<T> c, boolean cp, @Nullable IgnitePredicate<? super T>[] p) {
A.notNull(c, "c");
return lose(c, cp, not(p));
@@ -2143,6 +2162,27 @@ public class GridFunc {
}
/**
+ * Negates given predicate.
+ * <p>
+ * Gets predicate that evaluates to {@code true} if any of given predicates
+ * evaluates to {@code false}. If all predicates evaluate to {@code true} the
+ * result predicate will evaluate to {@code false}.
+ *
+ * @param p Predicate to negate.
+ * @param <T> Type of the free variable, i.e. the element the predicate is called on.
+ * @return Negated predicate.
+ */
+ public static <T> IgnitePredicate<T> not(final IgnitePredicate<? super T> p) {
+ A.notNull(p, "p");
+
+ return isAlwaysFalse(p) ? F.<T>alwaysTrue() : isAlwaysTrue(p) ? F.<T>alwaysFalse() : new P1<T>() {
+ @Override public boolean apply(T t) {
+ return !p.apply(t);
+ }
+ };
+ }
+
+ /**
* Negates given predicates.
* <p>
* Gets predicate that evaluates to {@code true} if any of given predicates
@@ -2153,8 +2193,7 @@ public class GridFunc {
* @param <T> Type of the free variable, i.e. the element the predicate is called on.
* @return Negated predicate.
*/
- @SafeVarargs
- public static <T> IgnitePredicate<T> not(@Nullable final IgnitePredicate<? super T>... p) {
+ public static <T> IgnitePredicate<T> not(@Nullable final IgnitePredicate<? super T>[] p) {
return isAlwaysFalse(p) ? F.<T>alwaysTrue() : isAlwaysTrue(p) ? F.<T>alwaysFalse() : new P1<T>() {
@Override public boolean apply(T t) {
return !isAll(t, p);
http://git-wip-us.apache.org/repos/asf/ignite/blob/8f43c59d/modules/core/src/main/java/org/apache/ignite/spi/eventstorage/memory/MemoryEventStorageSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/eventstorage/memory/MemoryEventStorageSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/eventstorage/memory/MemoryEventStorageSpi.java
index c7c635e..56a627a 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/eventstorage/memory/MemoryEventStorageSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/eventstorage/memory/MemoryEventStorageSpi.java
@@ -216,6 +216,7 @@ public class MemoryEventStorageSpi extends IgniteSpiAdapter implements EventStor
}
/** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
@Override public <T extends Event> Collection<T> localEvents(IgnitePredicate<T> p) {
A.notNull(p, "p");
[2/4] ignite git commit: IGNITE-2263: Optimized size(...) methods.
Posted by vo...@apache.org.
IGNITE-2263: Optimized size(...) methods.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/7dadfb6a
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/7dadfb6a
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/7dadfb6a
Branch: refs/heads/ignite-2263
Commit: 7dadfb6a6dd882ca0baee40b7574e6e9d48e565a
Parents: 8f43c59
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Dec 30 14:07:54 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Dec 30 14:07:54 2015 +0300
----------------------------------------------------------------------
.../ignite/internal/util/lang/GridFunc.java | 37 +++++++++++++++++---
1 file changed, 33 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/7dadfb6a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
index 31e1156..484ea0b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
@@ -720,8 +720,7 @@ public class GridFunc {
* @param obj One or more elements.
* @return Concatenated array.
*/
- @SuppressWarnings("unchecked")
- public static <T> T[] concat(@Nullable T[] arr, T... obj) {
+ public static <T> T[] concat(@Nullable T[] arr, T[] obj) {
T[] newArr;
if (arr == null || arr.length == 0)
@@ -1125,6 +1124,7 @@ public class GridFunc {
* @param <T> Type of the iterator.
* @return Newly created empty iterator.
*/
+ @SuppressWarnings("unchecked")
public static <T> GridIterator<T> emptyIterator() {
return EMPTY_ITER;
}
@@ -1284,6 +1284,16 @@ public class GridFunc {
}
/**
+ * Gets size of the given collection.
+ *
+ * @param c Collection.
+ * @return Size.
+ */
+ public static <T> int size(@Nullable Collection<? extends T> c) {
+ return c == null || c.isEmpty() ? 0 : c.size();
+ }
+
+ /**
* Gets size of the given collection with provided optional predicates.
*
* @param c Collection to size.
@@ -1292,11 +1302,30 @@ public class GridFunc {
* @return Number of elements in the collection for which all given predicates
* evaluates to {@code true}. If no predicates is provided - all elements are counted.
*/
- public static <T> int size(@Nullable Collection<? extends T> c, @Nullable IgnitePredicate<? super T>... p) {
+ public static <T> int size(@Nullable Collection<? extends T> c, @Nullable IgnitePredicate<? super T>[] p) {
return c == null || c.isEmpty() ? 0 : isEmpty(p) || isAlwaysTrue(p) ? c.size() : size(c.iterator(), p);
}
/**
+ * Gets size of the given iterator. Iterator will be traversed to get the count.
+ *
+ * @param it Iterator to size.
+ * @param <T> Type of the iterator.
+ * @return Number of elements in the iterator.
+ */
+ public static <T> int size(@Nullable Iterator<? extends T> it) {
+ if (it == null)
+ return 0;
+
+ int n = 0;
+
+ while (it.hasNext())
+ n++;
+
+ return n;
+ }
+
+ /**
* Gets size of the given iterator with provided optional predicates. Iterator
* will be traversed to get the count.
*
@@ -1306,7 +1335,7 @@ public class GridFunc {
* @return Number of elements in the iterator for which all given predicates
* evaluates to {@code true}. If no predicates is provided - all elements are counted.
*/
- public static <T> int size(@Nullable Iterator<? extends T> it, @Nullable IgnitePredicate<? super T>... p) {
+ public static <T> int size(@Nullable Iterator<? extends T> it, @Nullable IgnitePredicate<? super T>[] p) {
if (it == null)
return 0;
[3/4] ignite git commit: IGNITE-2263: Optimized fold() method.
Posted by vo...@apache.org.
IGNITE-2263: Optimized fold() method.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/9f02041e
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/9f02041e
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/9f02041e
Branch: refs/heads/ignite-2263
Commit: 9f02041eda6ed179872498e0385d90e8f681c4dd
Parents: 7dadfb6
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Dec 30 14:19:23 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Dec 30 14:19:23 2015 +0300
----------------------------------------------------------------------
.../org/apache/ignite/internal/util/lang/GridFunc.java | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/9f02041e/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
index 484ea0b..bc7252f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
@@ -3031,22 +3031,17 @@ public class GridFunc {
*
* @param c Input collection.
* @param b Optional first folding pair element.
- * @param fs Optional set of folding closures.
+ * @param fs Optional folding closure.
* @param <D> Type of the input collection elements and type of the free variable for the closure.
* @param <B> Type of the folding value and return type of the closure.
* @return Value representing folded collection.
*/
@Nullable public static <D, B> B fold(Iterable<? extends D> c, @Nullable B b,
- @Nullable IgniteBiClosure<? super D, ? super B, B>... fs) {
+ IgniteBiClosure<? super D, ? super B, B> fs) {
A.notNull(c, "c");
- if (!isEmpty(fs))
- for (D e : c) {
- assert fs != null;
-
- for (IgniteBiClosure<? super D, ? super B, B> f : fs)
- b = f.apply(e, b);
- }
+ for (D e : c)
+ b = fs.apply(e, b);
return b;
}
[4/4] ignite git commit: IGNITE-2263: Optimized forAll() and forAny()
methods.
Posted by vo...@apache.org.
IGNITE-2263: Optimized forAll() and forAny() methods.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6f7de6ac
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6f7de6ac
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6f7de6ac
Branch: refs/heads/ignite-2263
Commit: 6f7de6ac2c815b18ef561bba1366a93065f4a997
Parents: 9f02041
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Dec 30 14:24:03 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Dec 30 14:24:03 2015 +0300
----------------------------------------------------------------------
.../ignite/internal/util/lang/GridFunc.java | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/6f7de6ac/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
index bc7252f..4036686 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java
@@ -62,7 +62,6 @@ import org.apache.ignite.lang.IgniteBiTuple;
import org.apache.ignite.lang.IgniteCallable;
import org.apache.ignite.lang.IgniteClosure;
import org.apache.ignite.lang.IgniteInClosure;
-import org.apache.ignite.lang.IgniteOutClosure;
import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.lang.IgniteReducer;
import org.jetbrains.annotations.NotNull;
@@ -2714,6 +2713,7 @@ public class GridFunc {
* @param p Predicate.
* @return {@code True} if test is passed.
*/
+ // TODO: To be removed!
public static <T> boolean isAll(@Nullable T t, @Nullable IgnitePredicate<? super T> p) {
return p == null || p.apply(t);
}
@@ -2932,14 +2932,14 @@ public class GridFunc {
* @return Returns {@code true} if all given predicates evaluate to {@code true} for
* all elements. Returns {@code false} otherwise.
*/
- public static <V> boolean forAll(Iterable<? extends V> c, @Nullable IgnitePredicate<? super V>... p) {
+ public static <V> boolean forAll(Iterable<? extends V> c, IgnitePredicate<? super V> p) {
A.notNull(c, "c");
if (isAlwaysFalse(p))
return false;
else if (isAlwaysTrue(p))
return true;
- else if (!isEmpty(p)) {
+ else {
for (V v : c) {
if (!isAll(v, p))
return false;
@@ -2961,17 +2961,18 @@ public class GridFunc {
* entries. Returns {@code false} otherwise.
*/
public static <K1, K extends K1, V1, V extends V1> boolean forAll(Map<K, V> m,
- @Nullable IgnitePredicate<? super Map.Entry<K, V>>... p) {
+ IgnitePredicate<? super Map.Entry<K, V>> p) {
A.notNull(m, "m");
if (isAlwaysFalse(p))
return false;
else if (isAlwaysTrue(p))
return true;
- else if (!isEmpty(p))
+ else {
for (Map.Entry<K, V> e : m.entrySet())
if (!isAll(e, p))
return false;
+ }
return true;
}
@@ -2988,14 +2989,10 @@ public class GridFunc {
* @return Returns {@code true} if all given predicates evaluate to {@code true} for
* at least one element. Returns {@code false} otherwise.
*/
- public static <V> boolean forAny(Iterable<? extends V> c, @Nullable IgnitePredicate<? super V>... p) {
+ public static <V> boolean forAny(Iterable<? extends V> c, IgnitePredicate<? super V> p) {
A.notNull(c, "c");
- if (!c.iterator().hasNext())
- return false;
- else if (isEmpty(p))
- return true;
- else if (isAlwaysFalse(p))
+ if (isAlwaysFalse(p))
return false;
else if (isAlwaysTrue(p))
return true;