activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1176524 - in /activemq/trunk/activemq-console/src: main/java/org/apache/activemq/console/filter/MapTransformFilter.java test/java/org/apache/activemq/console/filter/ test/java/org/apache/activemq/console/filter/TestMapTransformFilter.java
Date Tue, 27 Sep 2011 18:55:15 GMT
Author: tabish
Date: Tue Sep 27 18:55:15 2011
New Revision: 1176524

URL: http://svn.apache.org/viewvc?rev=1176524&view=rev
Log:
apply patch for: https://issues.apache.org/jira/browse/AMQ-3512

Added:
    activemq/trunk/activemq-console/src/test/java/org/apache/activemq/console/filter/
    activemq/trunk/activemq-console/src/test/java/org/apache/activemq/console/filter/TestMapTransformFilter.java
  (with props)
Modified:
    activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MapTransformFilter.java

Modified: activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MapTransformFilter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MapTransformFilter.java?rev=1176524&r1=1176523&r2=1176524&view=diff
==============================================================================
--- activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MapTransformFilter.java
(original)
+++ activemq/trunk/activemq-console/src/main/java/org/apache/activemq/console/filter/MapTransformFilter.java
Tue Sep 27 18:55:15 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.activemq.console.filter;
 
+import java.lang.reflect.Array;
 import java.lang.reflect.Method;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -331,10 +332,32 @@ public class MapTransformFilter extends 
         return props;
     }
 
-    protected String getDisplayString(Object obj) {
-        if (obj != null && obj.getClass().isArray()) {
-            obj = Arrays.asList((Object[]) obj);
-        }
+	@SuppressWarnings("unchecked")
+	protected String getDisplayString(Object obj) {
+		if (null == obj)
+			return "null";
+		
+		if (obj != null && obj.getClass().isArray()) {
+			Class type = obj.getClass().getComponentType();
+			if (!type.isPrimitive()) {
+				obj = Arrays.asList((Object[]) obj);
+			} else {
+				// for primitives, we can't use Arrays.toString(), so we have to roll something similar.
+				int len = Array.getLength(obj);
+				if (0 == len)
+					return "[]";
+				StringBuilder bldr = new StringBuilder();
+				bldr.append("[");
+				for (int i = 0; i <= len; i++) {
+					bldr.append(Array.get(obj, i));
+					if (i + 1 >= len)
+						return bldr.append("]").toString();
+					bldr.append(",");
+				}
+			}
+
+		}
+        
         return obj.toString();
     }
 }

Added: activemq/trunk/activemq-console/src/test/java/org/apache/activemq/console/filter/TestMapTransformFilter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-console/src/test/java/org/apache/activemq/console/filter/TestMapTransformFilter.java?rev=1176524&view=auto
==============================================================================
--- activemq/trunk/activemq-console/src/test/java/org/apache/activemq/console/filter/TestMapTransformFilter.java
(added)
+++ activemq/trunk/activemq-console/src/test/java/org/apache/activemq/console/filter/TestMapTransformFilter.java
Tue Sep 27 18:55:15 2011
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.console.filter;
+
+import junit.framework.TestCase;
+
+public class TestMapTransformFilter extends TestCase {
+
+    private static final Object[][] testData = new Object[][] {
+            { new byte[] { 1, 2, 3, 4 } },
+            { new int[] { 1, 2, 3, 4 } },
+            { new long[] { 1, 2, 3, 4 } },
+            { new double[] { 1, 2, 3, 4 } },
+            { new float[] { 1, 2, 3, 4 } },
+            { new char[] { '1', '2', '3', '4' } },
+
+            { new Integer[] { 1, 2, 3, 4 } },
+            { new Byte[] { 1, 2, 3, 4 } },
+            { new Long[] { 1L, 2L, 3L, 4L } },
+            { new Double[] { 1d, 2d, 3d, 4d } },
+            { new Float[] { 1f, 2f, 3f, 4f } },
+            { new Character[] { '1', '2', '3', '4' } },
+
+            { new String[] { "abc", "def" } },
+            { new int[] { 1, } },
+            { new int[] {,} },
+            { "abc"},
+            {(byte)1},
+            { (int)1 },
+            { (long)1 },
+            { (double)1d },
+            { (float)1f },
+            { (char)'1' },
+
+    };
+
+    public void testFetDisplayString() {
+        MapTransformFilter filter = new MapTransformFilter(null);
+        for (Object[] objectArray : testData) {
+            filter.getDisplayString(objectArray[0]);
+        }
+    }
+
+}

Propchange: activemq/trunk/activemq-console/src/test/java/org/apache/activemq/console/filter/TestMapTransformFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message