@Test public void testRenderer() { assertEquals("", "null", ToStringHelper.render(null)); assertEquals("", "a", ToStringHelper.render("a")); assertEquals("", "[]", ToStringHelper.render(new String[0])); assertEquals("", "[a]", ToStringHelper.render(new String[] { "a" })); assertEquals("", "[a, b]", ToStringHelper.render(new String[] { "a", "b" })); assertEquals("", "[a, b, c]", ToStringHelper.render(new String[] { "a", "b", "c" })); assertEquals("", "[[a], [b, c]]", ToStringHelper.render(new String[][] { { "a" }, { "b", "c" } })); assertEquals("", "[0, [a], [b, c]]", ToStringHelper.render(new Object[] { "0", new String[] { "a" }, new Object[] { "b", "c" } })); assertEquals("", "[1]", ToStringHelper.render(new int[] { 1 })); assertEquals("", "[1, 2, 3]", ToStringHelper.render(new int[] { 1, 2, 3 })); assertEquals("", "[1, 2, 3]", ToStringHelper.render(new long[] { 1, 2, 3 })); assertEquals("", "[1, 2, 3]", ToStringHelper.render(new short[] { 1, 2, 3 })); assertEquals("", "[[1, 2], [], [3, 4]]", ToStringHelper.render(new byte[][] { { 1, 2 }, {}, { 3, 4 } })); assertEquals("", "[1.0, 2.0, 3.0]", ToStringHelper.render(new float[] { 1, 2, 3 })); assertEquals("", "[1.0, 2.0, 3.0]", ToStringHelper.render(new double[] { 1, 2, 3 })); assertEquals("", "[[1.0, 2.0, 3.0]]", ToStringHelper.render(new double[][] { { 1, 2, 3 } })); assertEquals("", "[true, false, true]", ToStringHelper.render(new boolean[] { true, false, true })); }
public static String render(Object o) { if (o == null) { return String.valueOf(o); } Class<?> objectClass = o.getClass(); if (unrenderableClasses.containsKey(objectClass) == false) { try { if (objectClass.isArray()) { return renderArray(o, objectClass).toString(); } else { return o.toString(); } } catch (Exception e) { Long now = new Long(System.currentTimeMillis()); System.err.println("Disabling exception throwing class " + objectClass.getName() + ", " + e.getMessage()); unrenderableClasses.put(objectClass, now); } } String name = o.getClass().getName(); return name + "@" + Integer.toHexString(o.hashCode()); }
ToStringHelper { public static String render(Object o) { if (o == null) { return String.valueOf(o); } Class<?> objectClass = o.getClass(); if (unrenderableClasses.containsKey(objectClass) == false) { try { if (objectClass.isArray()) { return renderArray(o, objectClass).toString(); } else { return o.toString(); } } catch (Exception e) { Long now = new Long(System.currentTimeMillis()); System.err.println("Disabling exception throwing class " + objectClass.getName() + ", " + e.getMessage()); unrenderableClasses.put(objectClass, now); } } String name = o.getClass().getName(); return name + "@" + Integer.toHexString(o.hashCode()); } }
ToStringHelper { public static String render(Object o) { if (o == null) { return String.valueOf(o); } Class<?> objectClass = o.getClass(); if (unrenderableClasses.containsKey(objectClass) == false) { try { if (objectClass.isArray()) { return renderArray(o, objectClass).toString(); } else { return o.toString(); } } catch (Exception e) { Long now = new Long(System.currentTimeMillis()); System.err.println("Disabling exception throwing class " + objectClass.getName() + ", " + e.getMessage()); unrenderableClasses.put(objectClass, now); } } String name = o.getClass().getName(); return name + "@" + Integer.toHexString(o.hashCode()); }  }
ToStringHelper { public static String render(Object o) { if (o == null) { return String.valueOf(o); } Class<?> objectClass = o.getClass(); if (unrenderableClasses.containsKey(objectClass) == false) { try { if (objectClass.isArray()) { return renderArray(o, objectClass).toString(); } else { return o.toString(); } } catch (Exception e) { Long now = new Long(System.currentTimeMillis()); System.err.println("Disabling exception throwing class " + objectClass.getName() + ", " + e.getMessage()); unrenderableClasses.put(objectClass, now); } } String name = o.getClass().getName(); return name + "@" + Integer.toHexString(o.hashCode()); }  static String render(Object o); }
ToStringHelper { public static String render(Object o) { if (o == null) { return String.valueOf(o); } Class<?> objectClass = o.getClass(); if (unrenderableClasses.containsKey(objectClass) == false) { try { if (objectClass.isArray()) { return renderArray(o, objectClass).toString(); } else { return o.toString(); } } catch (Exception e) { Long now = new Long(System.currentTimeMillis()); System.err.println("Disabling exception throwing class " + objectClass.getName() + ", " + e.getMessage()); unrenderableClasses.put(objectClass, now); } } String name = o.getClass().getName(); return name + "@" + Integer.toHexString(o.hashCode()); }  static String render(Object o);  }