ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject ignite git commit: ignite-7195 correctly handle primitive array (addition for commit 5d66516d18b84878331918b79afe452d70bd7a42).
Date Fri, 12 Jan 2018 07:37:29 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 04806d93e -> eeebfca0b


ignite-7195 correctly handle primitive array (addition for commit 5d66516d18b84878331918b79afe452d70bd7a42).


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

Branch: refs/heads/master
Commit: eeebfca0bddbf31b10a86a6725e2c27933fdb0ae
Parents: 04806d9
Author: Alexander Belyak <alexandr.belyak@xored.com>
Authored: Fri Jan 12 10:37:20 2018 +0300
Committer: sboikov <sboikov@gridgain.com>
Committed: Fri Jan 12 10:37:20 2018 +0300

----------------------------------------------------------------------
 .../util/tostring/GridToStringBuilder.java      | 103 ++++++++++++++-----
 .../tostring/GridToStringBuilderSelfTest.java   |  56 ++++++++++
 2 files changed, 132 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/eeebfca0/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 a5f2c95..56eef1d 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
@@ -1047,41 +1047,90 @@ public class GridToStringBuilder {
      * @return String representation of an array.
      */
     @SuppressWarnings({"ConstantConditions", "unchecked"})
-    public static <T> String arrayToString(Class arrType, @Nullable Object arr) {
+    public static <T> String arrayToString(Class arrType, Object arr) {
         if (arr == null)
             return "null";
 
-        T[] array = (T[])arr;
-
-        if (array.length > COLLECTION_LIMIT)
-            arr = Arrays.copyOf(array, COLLECTION_LIMIT);
-
         String res;
+        int more = 0;
 
-        if (arrType.equals(byte[].class))
-            res = Arrays.toString((byte[])arr);
-        else if (arrType.equals(boolean[].class))
-            res = Arrays.toString((boolean[])arr);
-        else if (arrType.equals(short[].class))
-            res = Arrays.toString((short[])arr);
-        else if (arrType.equals(int[].class))
-            res = Arrays.toString((int[])arr);
-        else if (arrType.equals(long[].class))
-            res = Arrays.toString((long[])arr);
-        else if (arrType.equals(float[].class))
-            res = Arrays.toString((float[])arr);
-        else if (arrType.equals(double[].class))
-            res = Arrays.toString((double[])arr);
-        else if (arrType.equals(char[].class))
-            res = Arrays.toString((char[])arr);
-        else
-            res = Arrays.toString((Object[])arr);
-
-        if (array.length > COLLECTION_LIMIT) {
+        if (arrType.equals(byte[].class)) {
+            byte[] byteArr = (byte[])arr;
+            if (byteArr.length > COLLECTION_LIMIT) {
+                more = byteArr.length - COLLECTION_LIMIT;
+                byteArr = Arrays.copyOf(byteArr, COLLECTION_LIMIT);
+            }
+            res = Arrays.toString(byteArr);
+        }
+        else if (arrType.equals(boolean[].class)) {
+            boolean[] boolArr = (boolean[])arr;
+            if (boolArr.length > COLLECTION_LIMIT) {
+                more = boolArr.length - COLLECTION_LIMIT;
+                boolArr = Arrays.copyOf(boolArr, COLLECTION_LIMIT);
+            }
+            res = Arrays.toString(boolArr);
+        }
+        else if (arrType.equals(short[].class)) {
+            short[] shortArr = (short[])arr;
+            if (shortArr.length > COLLECTION_LIMIT) {
+                more = shortArr.length - COLLECTION_LIMIT;
+                shortArr = Arrays.copyOf(shortArr, COLLECTION_LIMIT);
+            }
+            res = Arrays.toString(shortArr);
+        }
+        else if (arrType.equals(int[].class)) {
+            int[] intArr = (int[])arr;
+            if (intArr.length > COLLECTION_LIMIT) {
+                more = intArr.length - COLLECTION_LIMIT;
+                intArr = Arrays.copyOf(intArr, COLLECTION_LIMIT);
+            }
+            res = Arrays.toString(intArr);
+        }
+        else if (arrType.equals(long[].class)) {
+            long[] longArr = (long[])arr;
+            if (longArr.length > COLLECTION_LIMIT) {
+                more = longArr.length - COLLECTION_LIMIT;
+                longArr = Arrays.copyOf(longArr, COLLECTION_LIMIT);
+            }
+            res = Arrays.toString(longArr);
+        }
+        else if (arrType.equals(float[].class)) {
+            float[] floatArr = (float[])arr;
+            if (floatArr.length > COLLECTION_LIMIT) {
+                more = floatArr.length - COLLECTION_LIMIT;
+                floatArr = Arrays.copyOf(floatArr, COLLECTION_LIMIT);
+            }
+            res = Arrays.toString(floatArr);
+        }
+        else if (arrType.equals(double[].class)) {
+            double[] doubleArr = (double[])arr;
+            if (doubleArr.length > COLLECTION_LIMIT) {
+                more = doubleArr.length - COLLECTION_LIMIT;
+                doubleArr = Arrays.copyOf(doubleArr, COLLECTION_LIMIT);
+            }
+            res = Arrays.toString(doubleArr);
+        }
+        else if (arrType.equals(char[].class)) {
+            char[] charArr = (char[])arr;
+            if (charArr.length > COLLECTION_LIMIT) {
+                more = charArr.length - COLLECTION_LIMIT;
+                charArr = Arrays.copyOf(charArr, COLLECTION_LIMIT);
+            }
+            res = Arrays.toString(charArr);
+        }
+        else {
+            Object[] objArr = (Object[])arr;
+            if (objArr.length > COLLECTION_LIMIT) {
+                more = objArr.length - COLLECTION_LIMIT;
+                objArr = Arrays.copyOf(objArr, COLLECTION_LIMIT);
+            }
+            res = Arrays.toString(objArr);
+        }
+        if (more > 0) {
             StringBuilder resSB = new StringBuilder(res);
 
             resSB.deleteCharAt(resSB.length() - 1);
-            resSB.append("... and ").append(array.length - COLLECTION_LIMIT).append(" more]");
+            resSB.append("... and ").append(more).append(" more]");
 
             res = resSB.toString();
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/eeebfca0/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
index 04186a5..4ac05fb 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/util/tostring/GridToStringBuilderSelfTest.java
@@ -161,6 +161,62 @@ public class GridToStringBuilderSelfTest extends GridCommonAbstractTest
{
         for (Object val : vals)
             testArr(val, limit);
 
+        byte[] byteArr = new byte[1];
+        byteArr[0] = 1;
+        assertEquals(Arrays.toString(byteArr), GridToStringBuilder.arrayToString(byteArr.getClass(),
byteArr));
+        byteArr = Arrays.copyOf(byteArr, 101);
+        assertTrue("Can't find \"... and 1 more\" in overflowed array string!",
+            GridToStringBuilder.arrayToString(byteArr.getClass(), byteArr).contains("...
and 1 more"));
+
+        boolean[] boolArr = new boolean[1];
+        boolArr[0] = true;
+        assertEquals(Arrays.toString(boolArr), GridToStringBuilder.arrayToString(boolArr.getClass(),
boolArr));
+        boolArr = Arrays.copyOf(boolArr, 101);
+        assertTrue("Can't find \"... and 1 more\" in overflowed array string!",
+            GridToStringBuilder.arrayToString(boolArr.getClass(), boolArr).contains("...
and 1 more"));
+
+        short[] shortArr = new short[1];
+        shortArr[0] = 100;
+        assertEquals(Arrays.toString(shortArr), GridToStringBuilder.arrayToString(shortArr.getClass(),
shortArr));
+        shortArr = Arrays.copyOf(shortArr, 101);
+        assertTrue("Can't find \"... and 1 more\" in overflowed array string!",
+            GridToStringBuilder.arrayToString(shortArr.getClass(), shortArr).contains("...
and 1 more"));
+
+        int[] intArr = new int[1];
+        intArr[0] = 10000;
+        assertEquals(Arrays.toString(intArr), GridToStringBuilder.arrayToString(intArr.getClass(),
intArr));
+        intArr = Arrays.copyOf(intArr, 101);
+        assertTrue("Can't find \"... and 1 more\" in overflowed array string!",
+            GridToStringBuilder.arrayToString(intArr.getClass(), intArr).contains("... and
1 more"));
+
+        long[] longArr = new long[1];
+        longArr[0] = 10000000;
+        assertEquals(Arrays.toString(longArr), GridToStringBuilder.arrayToString(longArr.getClass(),
longArr));
+        longArr = Arrays.copyOf(longArr, 101);
+        assertTrue("Can't find \"... and 1 more\" in overflowed array string!",
+            GridToStringBuilder.arrayToString(longArr.getClass(), longArr).contains("...
and 1 more"));
+
+        float[] floatArr = new float[1];
+        floatArr[0] = 1.f;
+        assertEquals(Arrays.toString(floatArr), GridToStringBuilder.arrayToString(floatArr.getClass(),
floatArr));
+        floatArr = Arrays.copyOf(floatArr, 101);
+        assertTrue("Can't find \"... and 1 more\" in overflowed array string!",
+            GridToStringBuilder.arrayToString(floatArr.getClass(), floatArr).contains("...
and 1 more"));
+
+        double[] doubleArr = new double[1];
+        doubleArr[0] = 1.;
+        assertEquals(Arrays.toString(doubleArr), GridToStringBuilder.arrayToString(doubleArr.getClass(),
doubleArr));
+        doubleArr = Arrays.copyOf(doubleArr, 101);
+        assertTrue("Can't find \"... and 1 more\" in overflowed array string!",
+            GridToStringBuilder.arrayToString(doubleArr.getClass(), doubleArr).contains("...
and 1 more"));
+
+        char[] charArr = new char[1];
+        charArr[0] = 'a';
+        assertEquals(Arrays.toString(charArr), GridToStringBuilder.arrayToString(charArr.getClass(),
charArr));
+        charArr = Arrays.copyOf(charArr, 101);
+        assertTrue("Can't find \"... and 1 more\" in overflowed array string!",
+            GridToStringBuilder.arrayToString(charArr.getClass(), charArr).contains("...
and 1 more"));
+
         Map<String, String> strMap = new TreeMap<>();
         List<String> strList = new ArrayList<>(limit+1);
 


Mime
View raw message