git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1176524 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2011-09-27 18:55:15 +00:00
parent d717a495c7
commit bef9984b21
2 changed files with 85 additions and 4 deletions

View File

@ -16,6 +16,7 @@
*/ */
package org.apache.activemq.console.filter; package org.apache.activemq.console.filter;
import java.lang.reflect.Array;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
@ -331,10 +332,32 @@ public class MapTransformFilter extends ResultTransformFilter {
return props; return props;
} }
@SuppressWarnings("unchecked")
protected String getDisplayString(Object obj) { protected String getDisplayString(Object obj) {
if (null == obj)
return "null";
if (obj != null && obj.getClass().isArray()) { if (obj != null && obj.getClass().isArray()) {
Class type = obj.getClass().getComponentType();
if (!type.isPrimitive()) {
obj = Arrays.asList((Object[]) obj); 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(); return obj.toString();
} }
} }

View File

@ -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]);
}
}
}