@Test public void testGetValueStringWithCustomCollection() { List<Integer> data = new AbstractList<Integer>() { int[] values = new int[15]; int size = 0; @Override public boolean add(Integer e) { values[size] = e; size++; return true; } @Override public Integer get(int index) { if ( index >= size ) throw new IndexOutOfBoundsException(); return values[index]; } @Override public int size() { return size; } @Override public String toString() { return "Custom" + super.toString(); } }; data.add(5); assertEquals("[5]", ShellUtil.getValueString(data)); }
public static String getValueString(Object obj) { if (obj == null) { return "null"; } else if (obj instanceof boolean[]) { return Arrays.toString((boolean[]) obj); } else if (obj instanceof byte[]) { return Arrays.toString((byte[]) obj); } else if (obj instanceof char[]) { return Arrays.toString((char[]) obj); } else if (obj instanceof double[]) { return Arrays.toString((double[]) obj); } else if (obj instanceof float[]) { return Arrays.toString((float[]) obj); } else if (obj instanceof int[]) { return Arrays.toString((int[]) obj); } else if (obj instanceof long[]) { return Arrays.toString((long[]) obj); } else if (obj instanceof short[]) { return Arrays.toString((short[]) obj); } else if (obj instanceof Collection<?>) { Object[] array = ((Collection<?>) obj).toArray(); return getValueString(array); } else if (obj.getClass().isArray()) { Object[] array = (Object[]) obj; StringBuilder sb = new StringBuilder(); sb.append("["); for (int i = 0; i < array.length; i++) { if (i != 0) { sb.append(", "); } sb.append(getValueString(array[i])); } sb.append("]"); return sb.toString(); } else { return obj.toString(); } }
ShellUtil { public static String getValueString(Object obj) { if (obj == null) { return "null"; } else if (obj instanceof boolean[]) { return Arrays.toString((boolean[]) obj); } else if (obj instanceof byte[]) { return Arrays.toString((byte[]) obj); } else if (obj instanceof char[]) { return Arrays.toString((char[]) obj); } else if (obj instanceof double[]) { return Arrays.toString((double[]) obj); } else if (obj instanceof float[]) { return Arrays.toString((float[]) obj); } else if (obj instanceof int[]) { return Arrays.toString((int[]) obj); } else if (obj instanceof long[]) { return Arrays.toString((long[]) obj); } else if (obj instanceof short[]) { return Arrays.toString((short[]) obj); } else if (obj instanceof Collection<?>) { Object[] array = ((Collection<?>) obj).toArray(); return getValueString(array); } else if (obj.getClass().isArray()) { Object[] array = (Object[]) obj; StringBuilder sb = new StringBuilder(); sb.append("["); for (int i = 0; i < array.length; i++) { if (i != 0) { sb.append(", "); } sb.append(getValueString(array[i])); } sb.append("]"); return sb.toString(); } else { return obj.toString(); } } }
ShellUtil { public static String getValueString(Object obj) { if (obj == null) { return "null"; } else if (obj instanceof boolean[]) { return Arrays.toString((boolean[]) obj); } else if (obj instanceof byte[]) { return Arrays.toString((byte[]) obj); } else if (obj instanceof char[]) { return Arrays.toString((char[]) obj); } else if (obj instanceof double[]) { return Arrays.toString((double[]) obj); } else if (obj instanceof float[]) { return Arrays.toString((float[]) obj); } else if (obj instanceof int[]) { return Arrays.toString((int[]) obj); } else if (obj instanceof long[]) { return Arrays.toString((long[]) obj); } else if (obj instanceof short[]) { return Arrays.toString((short[]) obj); } else if (obj instanceof Collection<?>) { Object[] array = ((Collection<?>) obj).toArray(); return getValueString(array); } else if (obj.getClass().isArray()) { Object[] array = (Object[]) obj; StringBuilder sb = new StringBuilder(); sb.append("["); for (int i = 0; i < array.length; i++) { if (i != 0) { sb.append(", "); } sb.append(getValueString(array[i])); } sb.append("]"); return sb.toString(); } else { return obj.toString(); } }  }
ShellUtil { public static String getValueString(Object obj) { if (obj == null) { return "null"; } else if (obj instanceof boolean[]) { return Arrays.toString((boolean[]) obj); } else if (obj instanceof byte[]) { return Arrays.toString((byte[]) obj); } else if (obj instanceof char[]) { return Arrays.toString((char[]) obj); } else if (obj instanceof double[]) { return Arrays.toString((double[]) obj); } else if (obj instanceof float[]) { return Arrays.toString((float[]) obj); } else if (obj instanceof int[]) { return Arrays.toString((int[]) obj); } else if (obj instanceof long[]) { return Arrays.toString((long[]) obj); } else if (obj instanceof short[]) { return Arrays.toString((short[]) obj); } else if (obj instanceof Collection<?>) { Object[] array = ((Collection<?>) obj).toArray(); return getValueString(array); } else if (obj.getClass().isArray()) { Object[] array = (Object[]) obj; StringBuilder sb = new StringBuilder(); sb.append("["); for (int i = 0; i < array.length; i++) { if (i != 0) { sb.append(", "); } sb.append(getValueString(array[i])); } sb.append("]"); return sb.toString(); } else { return obj.toString(); } }  static String getBundleName(Bundle bundle); static String getUnderlineString(String s); static String getValueString(Object obj); static boolean isASystemBundle(BundleContext bundleContext, Bundle bundle); static boolean getBoolean(Session session, String name); static void logException(Session session, Throwable t); static String getCurrentUserName(); static Map<String, String> getKsColorMap(Session session); static Map<String, String> getColorMap(Session session, String name, String def); }
ShellUtil { public static String getValueString(Object obj) { if (obj == null) { return "null"; } else if (obj instanceof boolean[]) { return Arrays.toString((boolean[]) obj); } else if (obj instanceof byte[]) { return Arrays.toString((byte[]) obj); } else if (obj instanceof char[]) { return Arrays.toString((char[]) obj); } else if (obj instanceof double[]) { return Arrays.toString((double[]) obj); } else if (obj instanceof float[]) { return Arrays.toString((float[]) obj); } else if (obj instanceof int[]) { return Arrays.toString((int[]) obj); } else if (obj instanceof long[]) { return Arrays.toString((long[]) obj); } else if (obj instanceof short[]) { return Arrays.toString((short[]) obj); } else if (obj instanceof Collection<?>) { Object[] array = ((Collection<?>) obj).toArray(); return getValueString(array); } else if (obj.getClass().isArray()) { Object[] array = (Object[]) obj; StringBuilder sb = new StringBuilder(); sb.append("["); for (int i = 0; i < array.length; i++) { if (i != 0) { sb.append(", "); } sb.append(getValueString(array[i])); } sb.append("]"); return sb.toString(); } else { return obj.toString(); } }  static String getBundleName(Bundle bundle); static String getUnderlineString(String s); static String getValueString(Object obj); static boolean isASystemBundle(BundleContext bundleContext, Bundle bundle); static boolean getBoolean(Session session, String name); static void logException(Session session, Throwable t); static String getCurrentUserName(); static Map<String, String> getKsColorMap(Session session); static Map<String, String> getColorMap(Session session, String name, String def); static final String DEFAULT_KS_COLORS; }