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:08 UTC
[2/4] ignite git commit: IGNITE-2263: Optimized size(...) methods.
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;