/** * Returns compact class host. * * @param obj Object to compact. * @return String. */ @Nullable public static Object compactObject(Object obj) { if (obj == null) return null; if (obj instanceof Enum) return obj.toString(); if (obj instanceof String || obj instanceof Boolean || obj instanceof Number) return obj; if (obj instanceof Collection) { Collection col = (Collection) obj; Object[] res = new Object[col.size()]; int i = 0; for (Object elm : col) res[i++] = compactObject(elm); return res; } if (obj.getClass().isArray()) { Class<?> arrType = obj.getClass().getComponentType(); if (arrType.isPrimitive()) { if (obj instanceof boolean[]) return Arrays.toString((boolean[]) obj); if (obj instanceof byte[]) return Arrays.toString((byte[]) obj); if (obj instanceof short[]) return Arrays.toString((short[]) obj); if (obj instanceof int[]) return Arrays.toString((int[]) obj); if (obj instanceof long[]) return Arrays.toString((long[]) obj); if (obj instanceof float[]) return Arrays.toString((float[]) obj); if (obj instanceof double[]) return Arrays.toString((double[]) obj); } Object[] arr = (Object[]) obj; int iMax = arr.length - 1; StringBuilder sb = new StringBuilder("["); for (int i = 0; i <= iMax; i++) { sb.append(compactObject(arr[i])); if (i != iMax) sb.append(", "); } sb.append("]"); return sb.toString(); } return U.compact(obj.getClass().getName()); }
private static Object createArgumentPlaceholder(Class<?> clazz, Integer placeholderId) { if (clazz.isPrimitive() || Number.class.isAssignableFrom(clazz) || Character.class == clazz) return getPrimitivePlaceHolder(clazz, placeholderId); if (clazz == String.class) return String.valueOf(placeholderId); if (Date.class.isAssignableFrom(clazz)) return new Date(placeholderId); if (clazz.isArray()) return Array.newInstance(clazz.getComponentType(), 1); try { return createArgumentPlaceholderForUnknownClass(clazz, placeholderId); } catch (Exception e) { throw new ArgumentConversionException( "It is not possible to create a placeholder for class: " + clazz.getName(), e); } }