ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [10/13] ignite git commit: IGNITE-2263: Removed "retain" from GridToStringBuilder.
Date Sat, 02 Jan 2016 09:21:49 GMT
IGNITE-2263: Removed "retain" from GridToStringBuilder.


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

Branch: refs/heads/ignite-2263
Commit: c59643c4917a34caadbb6c445f32762103d86deb
Parents: 357ea8a
Author: thatcoach <ppozerov@list.ru>
Authored: Sat Jan 2 12:11:38 2016 +0300
Committer: thatcoach <ppozerov@list.ru>
Committed: Sat Jan 2 12:11:38 2016 +0300

----------------------------------------------------------------------
 .../ignite/internal/util/lang/GridFunc.java     | 102 ++++---------------
 .../util/tostring/GridToStringBuilder.java      |  31 ++++--
 2 files changed, 43 insertions(+), 90 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/c59643c4/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 2033d62..760037c 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
@@ -17,26 +17,6 @@
 
 package org.apache.ignite.internal.util.lang;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.ConcurrentModificationException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.NavigableSet;
-import java.util.NoSuchElementException;
-import java.util.RandomAccess;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicLong;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.compute.ComputeJobResult;
 import org.apache.ignite.internal.util.F0;
@@ -69,6 +49,27 @@ import org.jsr166.ConcurrentHashMap8;
 import org.jsr166.ConcurrentLinkedDeque8;
 import org.jsr166.ThreadLocalRandom8;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.ConcurrentModificationException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableSet;
+import java.util.NoSuchElementException;
+import java.util.RandomAccess;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
 /**
  * Contains factory and utility methods for {@code closures}, {@code predicates}, and {@code
tuples}.
  * It also contains functional style collection comprehensions.
@@ -927,67 +928,6 @@ public class GridFunc {
     }
 
     /**
-     * Retains all elements in input collection that are evaluated to {@code true}
-     * by all given predicates.
-     *
-     * @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,
@Nullable IgnitePredicate<? super T>[] p) {
-        A.notNull(c, "c");
-
-        return lose(c, cp, not(p));
-    }
-
-    /**
-     * Retains only up to first {@code num} elements in the input collection.
-     *
-     * @param c Input collection.
-     * @param cp If {@code true} method creates collection not modifying input, otherwise
does
-     *      <tt>in-place</tt> modifications.
-     * @param num Maximum number of elements to retain (the actual number can be
-     *      less if the input collection contains less elements).
-     * @param <T> Type of the collections.
-     * @return Collection contains up to {@code num} first elements from the input collection.
-     */
-    public static <T> Collection<T> retain(Collection<T> c, boolean cp,
int num) {
-        A.notNull(c, "c");
-        A.ensure(num >= 0, "num >= 0");
-
-        Collection<T> res;
-
-        if (!cp) {
-            res = c;
-
-            if (num < res.size()) {
-                int i = 0;
-
-                for (Iterator<T> iter = res.iterator(); iter.hasNext();) {
-                    iter.next();
-
-                    if (i++ >= num)
-                        iter.remove();
-                }
-            }
-        }
-        else {
-            res = new ArrayList<>(num);
-
-            Iterator<? extends T> iter = c.iterator();
-
-            for (int i = 0; i < num && iter.hasNext(); i++)
-                res.add(iter.next());
-        }
-
-        return res;
-    }
-
-    /**
      * Create list containing two elements.
      *
      * @param t1 First element.

http://git-wip-us.apache.org/repos/asf/ignite/blob/c59643c4/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
index b29d7cd..b31d53b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/tostring/GridToStringBuilder.java
@@ -17,12 +17,18 @@
 
 package org.apache.ignite.internal.util.tostring;
 
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.util.typedef.internal.SB;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.jetbrains.annotations.Nullable;
+
 import java.io.Externalizable;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Serializable;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.EventListener;
@@ -34,11 +40,6 @@ import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.SB;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.jetbrains.annotations.Nullable;
 
 /**
  * Provides auto-generation framework for {@code toString()} output.
@@ -453,18 +454,30 @@ public class GridToStringBuilder {
                 else {
                     Object val = field.get(obj);
 
-                    if (val instanceof Collection && ((Collection)val).size() >
MAX_COL_SIZE)
-                        val = F.retain((Collection)val, true, MAX_COL_SIZE);
+                    if (val instanceof Collection && ((Collection)val).size() >
MAX_COL_SIZE) {
+                        Collection val0 = new ArrayList();
+
+                        int ctr = 0;
+
+                        for (Object o : ((Collection) val)) {
+                            if (ctr++ < MAX_COL_SIZE)
+                                val0.add(o);
+                            else
+                                break;
+                        }
+
+                        val = val0;
+                    }
                     else if (val instanceof Map && ((Map)val).size() > MAX_COL_SIZE)
{
                         Map tmp = U.newHashMap(MAX_COL_SIZE);
-                        int cntr = 0;
+                        int ctr = 0;
 
                         for (Object o : ((Map)val).entrySet()) {
                             Map.Entry e = (Map.Entry)o;
 
                             tmp.put(e.getKey(), e.getValue());
 
-                            if (++cntr >= MAX_COL_SIZE)
+                            if (++ctr >= MAX_COL_SIZE)
                                 break;
                         }
 


Mime
View raw message