diff --git a/src/main/java/ru/yandex/clickhouse/util/ClickHouseArrayUtil.java b/src/main/java/ru/yandex/clickhouse/util/ClickHouseArrayUtil.java index 1e24c58..a5fda41 100644 --- a/src/main/java/ru/yandex/clickhouse/util/ClickHouseArrayUtil.java +++ b/src/main/java/ru/yandex/clickhouse/util/ClickHouseArrayUtil.java @@ -2,6 +2,7 @@ import ru.yandex.clickhouse.ClickHouseUtil; +import java.util.Arrays; import java.util.Collection; /** @@ -34,73 +35,24 @@ public static String arrayToString(Object object, Boolean explicitEscape) { private static String primitiveArrayToString(Object array) { if (array instanceof int[]) { - return toString((int[]) array); + return Arrays.toString((int[]) array); } else if (array instanceof long[]) { - return toString((long[]) array); + return Arrays.toString((long[]) array); } else if (array instanceof float[]) { - return toString((float[]) array); + return Arrays.toString((float[]) array); } else if (array instanceof double[]) { - return toString((double[]) array); + return Arrays.toString((double[]) array); } else if (array instanceof char[]) { return toString((char[]) array); } else if (array instanceof byte[]) { - return toString((byte[]) array); + return Arrays.toString((byte[]) array); } else if (array instanceof short[]) { - return toString((short[]) array); + return Arrays.toString((short[]) array); } else { throw new IllegalArgumentException("Wrong primitive type: " + array.getClass().getComponentType()); } } - public static String toString(int[] values) { - ArrayBuilder builder = new ArrayBuilder(false, true); - for (int value : values) { - builder.append(value); - } - return builder.build(); - } - - public static String toString(long[] values) { - ArrayBuilder builder = new ArrayBuilder(false, true); - for (long value : values) { - builder.append(value); - } - return builder.build(); - } - - public static String toString(float[] values) { - ArrayBuilder builder = new ArrayBuilder(false, true); - for (float value : values) { - builder.append(value); - } - return builder.build(); - } - - public static String toString(double[] values) { - ArrayBuilder builder = new ArrayBuilder(false, true); - for (double value : values) { - builder.append(value); - } - return builder.build(); - } - - public static String toString(byte[] values) { - ArrayBuilder builder = new ArrayBuilder(false, true); - for (byte value : values) { - builder.append(value); - } - return builder.build(); - } - - public static String toString(short[] values) { - ArrayBuilder builder = new ArrayBuilder(false, true); - for (short value : values) { - builder.append(value); - } - return builder.build(); - } - - public static String toString(char[] values) { ArrayBuilder builder = new ArrayBuilder(true, true); for (char value : values) { diff --git a/src/test/java/ru/yandex/clickhouse/util/ClickHouseArrayUtilTest.java b/src/test/java/ru/yandex/clickhouse/util/ClickHouseArrayUtilTest.java index 334bbfa..6feedbb 100644 --- a/src/test/java/ru/yandex/clickhouse/util/ClickHouseArrayUtilTest.java +++ b/src/test/java/ru/yandex/clickhouse/util/ClickHouseArrayUtilTest.java @@ -38,12 +38,12 @@ public void testArrayToString() { Assert.assertEquals( ClickHouseArrayUtil.arrayToString(new int[]{21, 42}), - "[21,42]" + "[21, 42]" ); Assert.assertEquals( ClickHouseArrayUtil.arrayToString(new double[]{0.1, 1.2}), - "[0.1,1.2]" + "[0.1, 1.2]" ); Assert.assertEquals( @@ -68,12 +68,12 @@ public void testArrayToString() { Assert.assertEquals( ClickHouseArrayUtil.arrayToString(new double[][]{{0.1, 1.2}, {0.2, 2.2}}), - "[[0.1,1.2],[0.2,2.2]]" + "[[0.1, 1.2],[0.2, 2.2]]" ); Assert.assertEquals( ClickHouseArrayUtil.arrayToString(new int[][]{{1, 2}, {3, 4}}), - "[[1,2],[3,4]]" + "[[1, 2],[3, 4]]" ); Assert.assertEquals( @@ -81,6 +81,11 @@ public void testArrayToString() { "[['a','b'],['c','d']]" ); + Assert.assertEquals(ClickHouseArrayUtil.arrayToString(new short[] { 1,2,3 }), "[1, 2, 3]"); + Assert.assertEquals(ClickHouseArrayUtil.arrayToString(new float[] { 1.2f, 2.3f, 3.4f }), "[1.2, 2.3, 3.4]"); + Assert.assertEquals(ClickHouseArrayUtil.arrayToString(new byte[] {1, 2}), "[1, 2]"); + + } @Test