|
@@ -1,8 +1,13 @@
|
|
|
package com.uas.report.util;
|
|
package com.uas.report.util;
|
|
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
|
|
-import java.util.Collection;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.*;
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
|
|
+import java.lang.reflect.Type;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.Map.Entry;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 对象工具类
|
|
* 对象工具类
|
|
@@ -12,75 +17,376 @@ import java.util.Map;
|
|
|
*/
|
|
*/
|
|
|
public class ObjectUtils {
|
|
public class ObjectUtils {
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 判断是否为 null、空数组、空串或者空集合
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param obj
|
|
|
|
|
+ * 对象
|
|
|
|
|
+ * @return 是否为 null、空数组、空串或者空集合
|
|
|
|
|
+ */
|
|
|
|
|
+ public static boolean isEmpty(Object obj) {
|
|
|
|
|
+ if (obj == null) {
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (obj.getClass().isArray()) {
|
|
|
|
|
+ if (obj instanceof long[]) {
|
|
|
|
|
+ return ArrayUtils.isEmpty((long[]) obj);
|
|
|
|
|
+ } else if (obj instanceof int[]) {
|
|
|
|
|
+ return ArrayUtils.isEmpty((int[]) obj);
|
|
|
|
|
+ } else if (obj instanceof short[]) {
|
|
|
|
|
+ return ArrayUtils.isEmpty((short[]) obj);
|
|
|
|
|
+ } else if (obj instanceof byte[]) {
|
|
|
|
|
+ return ArrayUtils.isEmpty((byte[]) obj);
|
|
|
|
|
+ } else if (obj instanceof char[]) {
|
|
|
|
|
+ return ArrayUtils.isEmpty((char[]) obj);
|
|
|
|
|
+ } else if (obj instanceof boolean[]) {
|
|
|
|
|
+ return ArrayUtils.isEmpty((boolean[]) obj);
|
|
|
|
|
+ } else if (obj instanceof float[]) {
|
|
|
|
|
+ return ArrayUtils.isEmpty((float[]) obj);
|
|
|
|
|
+ } else if (obj instanceof double[]) {
|
|
|
|
|
+ return ArrayUtils.isEmpty((double[]) obj);
|
|
|
|
|
+ }
|
|
|
|
|
+ return ArrayUtils.isEmpty((Object[]) obj);
|
|
|
|
|
+ }
|
|
|
|
|
+ return (obj instanceof String && StringUtils.isEmpty(obj))
|
|
|
|
|
+ || (obj instanceof Collection && CollectionUtils.isEmpty((Collection<?>) obj))
|
|
|
|
|
+ || (obj instanceof Map && CollectionUtils.isEmpty((Map<?, ?>) obj));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 将对象转为 String
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param obj
|
|
|
|
|
+ * 对象
|
|
|
|
|
+ * @return 转换的 String
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String toString(Object obj) {
|
|
|
|
|
+ if (obj == null) {
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+ if (obj instanceof String) {
|
|
|
|
|
+ return (String) obj;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (obj.getClass().isArray()) {
|
|
|
|
|
+ if (obj instanceof long[]) {
|
|
|
|
|
+ return Arrays.toString((long[]) obj);
|
|
|
|
|
+ } else if (obj instanceof int[]) {
|
|
|
|
|
+ return Arrays.toString((int[]) obj);
|
|
|
|
|
+ } else if (obj instanceof short[]) {
|
|
|
|
|
+ return Arrays.toString((short[]) 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 boolean[]) {
|
|
|
|
|
+ return Arrays.toString((boolean[]) obj);
|
|
|
|
|
+ } else if (obj instanceof float[]) {
|
|
|
|
|
+ return Arrays.toString((float[]) obj);
|
|
|
|
|
+ } else if (obj instanceof double[]) {
|
|
|
|
|
+ return Arrays.toString((double[]) obj);
|
|
|
|
|
+ }
|
|
|
|
|
+ return Arrays.toString((Object[]) obj);
|
|
|
|
|
+ }
|
|
|
|
|
+ return obj.toString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 深克隆对象
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param t
|
|
|
|
|
+ * 要克隆的对象
|
|
|
|
|
+ * @return 克隆得到的对象
|
|
|
|
|
+ */
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ public static <T extends Serializable> T clone(T t)
|
|
|
|
|
+ throws IOException, ClassNotFoundException, NotSerializableException {
|
|
|
|
|
+ if (t == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
|
|
+ new ObjectOutputStream(out).writeObject(t);
|
|
|
|
|
+ ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(out.toByteArray()));
|
|
|
|
|
+ return (T) in.readObject();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 深克隆集合对象
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param collection
|
|
|
|
|
+ * 要克隆的对象
|
|
|
|
|
+ * @return 克隆得到的对象
|
|
|
|
|
+ */
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ public static <T> Collection<T> clone(Collection<T> collection) throws InstantiationException,
|
|
|
|
|
+ IllegalAccessException, NotSerializableException, ClassNotFoundException, IOException {
|
|
|
|
|
+ if (collection == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ Collection<T> result = collection.getClass().newInstance();
|
|
|
|
|
+ for (T t : collection) {
|
|
|
|
|
+ if (t instanceof Serializable) {
|
|
|
|
|
+ result.add((T) clone((Serializable) t));
|
|
|
|
|
+ } else if (t instanceof Collection) {
|
|
|
|
|
+ result.add((T) clone((Collection<?>) t));
|
|
|
|
|
+ } else if (t instanceof Map) {
|
|
|
|
|
+ result.add((T) clone((Map<String, ?>) t));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new IllegalArgumentException("未实现 Serializable 接口");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 深克隆 Map 对象
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param map
|
|
|
|
|
+ * 要克隆的对象
|
|
|
|
|
+ * @return 克隆得到的对象
|
|
|
|
|
+ */
|
|
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
|
|
+ public static <T> Map<String, T> clone(Map<String, T> map) throws InstantiationException, IllegalAccessException,
|
|
|
|
|
+ NotSerializableException, ClassNotFoundException, IOException {
|
|
|
|
|
+ if (map == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, T> result = map.getClass().newInstance();
|
|
|
|
|
+ Set<Entry<String, T>> entrySet = map.entrySet();
|
|
|
|
|
+ for (Entry<String, T> entry : entrySet) {
|
|
|
|
|
+ T value = entry.getValue();
|
|
|
|
|
+ if (value instanceof Serializable) {
|
|
|
|
|
+ result.put(entry.getKey(), (T) clone((Serializable) value));
|
|
|
|
|
+ } else if (value instanceof Collection) {
|
|
|
|
|
+ result.put(entry.getKey(), (T) clone((Collection<?>) value));
|
|
|
|
|
+ } else if (value instanceof Map) {
|
|
|
|
|
+ result.put(entry.getKey(), (T) clone((Map<String, ?>) value));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new IllegalArgumentException("未实现 Serializable 接口");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * JSONArray 转为指定类型的 List
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param array
|
|
|
|
|
+ * JSONArray
|
|
|
|
|
+ * @param clazz
|
|
|
|
|
+ * 指定的类型
|
|
|
|
|
+ * @param <T>
|
|
|
|
|
+ * 指定的类型
|
|
|
|
|
+ * @return 指定类型的 List
|
|
|
|
|
+ */
|
|
|
|
|
+ public static <T> List<T> toList(JSONArray array, Class<T> clazz) {
|
|
|
|
|
+ if (array == null) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<T> list = new ArrayList<>();
|
|
|
|
|
+ for (int i = 0; i < array.size(); i++) {
|
|
|
|
|
+ list.add(array.getObject(i, clazz));
|
|
|
|
|
+ }
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 利用反射获取指定对象的指定字段的值
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param field
|
|
|
|
|
+ * 指定字段
|
|
|
|
|
+ * @param k
|
|
|
|
|
+ * 指定对象
|
|
|
|
|
+ * @return 指定字段的值
|
|
|
|
|
+ */
|
|
|
|
|
+ public static <K> Object getValue(Field field, K k) throws IllegalStateException {
|
|
|
|
|
+ Object value;
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (!field.isAccessible()) {
|
|
|
|
|
+ field.setAccessible(true);
|
|
|
|
|
+ value = field.get(k);
|
|
|
|
|
+ field.setAccessible(false);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ value = field.get(k);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
|
|
|
|
|
+ throw new IllegalStateException("通过反射取值失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ return value;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 利用反射递归获取指定对象的指定字段的值
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param field
|
|
|
|
|
+ * 指定字段
|
|
|
|
|
+ * @param k
|
|
|
|
|
+ * 指定对象
|
|
|
|
|
+ * @return 指定字段的值
|
|
|
|
|
+ */
|
|
|
|
|
+ public static <K> Object recursivelyGetValue(String field, K k) {
|
|
|
|
|
+ return getValue(recursivelyGetField(field, k.getClass()), k);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 递归获取指定类的指定字段(包括父类的私有字段)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param field
|
|
|
|
|
+ * 指定字段
|
|
|
|
|
+ * @param clazz
|
|
|
|
|
+ * 指定类
|
|
|
|
|
+ * @return 指定字段
|
|
|
|
|
+ * @throws IllegalArgumentException
|
|
|
|
|
+ */
|
|
|
|
|
+ public static Field recursivelyGetField(String field, Class<?> clazz) throws IllegalArgumentException {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return clazz.getDeclaredField(field);
|
|
|
|
|
+ } catch (NoSuchFieldException e) {
|
|
|
|
|
+ Class<?> superclass = clazz.getSuperclass();
|
|
|
|
|
+ if (superclass != null) {
|
|
|
|
|
+ return recursivelyGetField(field, superclass);
|
|
|
|
|
+ }
|
|
|
|
|
+ throw new IllegalArgumentException(clazz + "中不存在字段:" + field);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取指定类的指定字段
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param field
|
|
|
|
|
+ * 指定字段
|
|
|
|
|
+ * @param clazz
|
|
|
|
|
+ * 指定类
|
|
|
|
|
+ * @return 指定字段
|
|
|
|
|
+ * @throws IllegalArgumentException
|
|
|
|
|
+ */
|
|
|
|
|
+ public static Field getField(String field, Class<?> clazz) throws IllegalArgumentException {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return clazz.getDeclaredField(field);
|
|
|
|
|
+ } catch (NoSuchFieldException e) {
|
|
|
|
|
+ throw new IllegalArgumentException(clazz + "中不存在字段:" + field);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 递归获取父类(包括私有字段)的所有字段
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param clazz
|
|
|
|
|
+ * 指定类
|
|
|
|
|
+ * @return 所有字段
|
|
|
|
|
+ */
|
|
|
|
|
+ public static List<Field> recursivelyGetParentField(Class<?> clazz) {
|
|
|
|
|
+ List<Field> fields = new ArrayList<>();
|
|
|
|
|
+ Class<?> superclass = clazz.getSuperclass();
|
|
|
|
|
+ if (superclass != null) {
|
|
|
|
|
+ fields.addAll(recursivelyGetField(superclass));
|
|
|
|
|
+ }
|
|
|
|
|
+ return fields;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 递归获取所有字段(包括父类的私有字段)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param clazz
|
|
|
|
|
+ * 指定类
|
|
|
|
|
+ * @return 所有字段
|
|
|
|
|
+ */
|
|
|
|
|
+ private static List<Field> recursivelyGetField(Class<?> clazz) {
|
|
|
|
|
+ List<Field> fields = new ArrayList<>();
|
|
|
|
|
+ Field[] declaredFields = clazz.getDeclaredFields();
|
|
|
|
|
+ if (!ArrayUtils.isEmpty(declaredFields)) {
|
|
|
|
|
+ fields.addAll(Arrays.asList(declaredFields));
|
|
|
|
|
+ }
|
|
|
|
|
+ Class<?> superclass = clazz.getSuperclass();
|
|
|
|
|
+ if (superclass != null) {
|
|
|
|
|
+ fields.addAll(recursivelyGetField(superclass));
|
|
|
|
|
+ }
|
|
|
|
|
+ return fields;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * 判断是否为 null、空数组、空串或者空集合
|
|
|
|
|
|
|
+ * 通过反射为指定的字段赋值
|
|
|
*
|
|
*
|
|
|
- * @param obj 对象
|
|
|
|
|
- * @return 是否为 null、空数组、空串或者空集合
|
|
|
|
|
|
|
+ * @param object 对象
|
|
|
|
|
+ * @param field 字段
|
|
|
|
|
+ * @param value 值
|
|
|
|
|
+ * @throws IllegalAccessException
|
|
|
*/
|
|
*/
|
|
|
- public static boolean isEmpty(Object obj) {
|
|
|
|
|
- if (obj == null) {
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ public static void setValue(Object object, Field field, Object value) throws IllegalAccessException {
|
|
|
|
|
+ if (object == null || field == null) {
|
|
|
|
|
+ throw new IllegalArgumentException("object 或 field 为空");
|
|
|
}
|
|
}
|
|
|
- if (obj.getClass().isArray()) {
|
|
|
|
|
- if (obj instanceof long[]) {
|
|
|
|
|
- return ArrayUtils.isEmpty((long[]) obj);
|
|
|
|
|
- } else if (obj instanceof int[]) {
|
|
|
|
|
- return ArrayUtils.isEmpty((int[]) obj);
|
|
|
|
|
- } else if (obj instanceof short[]) {
|
|
|
|
|
- return ArrayUtils.isEmpty((short[]) obj);
|
|
|
|
|
- } else if (obj instanceof byte[]) {
|
|
|
|
|
- return ArrayUtils.isEmpty((byte[]) obj);
|
|
|
|
|
- } else if (obj instanceof char[]) {
|
|
|
|
|
- return ArrayUtils.isEmpty((char[]) obj);
|
|
|
|
|
- } else if (obj instanceof boolean[]) {
|
|
|
|
|
- return ArrayUtils.isEmpty((boolean[]) obj);
|
|
|
|
|
- } else if (obj instanceof float[]) {
|
|
|
|
|
- return ArrayUtils.isEmpty((float[]) obj);
|
|
|
|
|
- } else if (obj instanceof double[]) {
|
|
|
|
|
- return ArrayUtils.isEmpty((double[]) obj);
|
|
|
|
|
|
|
+ if (value != null) {
|
|
|
|
|
+ Type type = field.getGenericType();
|
|
|
|
|
+ String typeString = type.toString();
|
|
|
|
|
+ if (typeString.equals("class java.lang.String")) {
|
|
|
|
|
+ } else if (typeString.equals("class java.lang.Long") || typeString.equals("long")) {
|
|
|
|
|
+ value = Long.valueOf(value.toString());
|
|
|
|
|
+ } else if (typeString.equals("class java.lang.Integer") || typeString.equals("int")) {
|
|
|
|
|
+ value = Integer.valueOf(value.toString());
|
|
|
|
|
+ } else if (typeString.equals("class java.lang.Short") || typeString.equals("short")) {
|
|
|
|
|
+ value = Short.valueOf(value.toString());
|
|
|
|
|
+ } else if (typeString.equals("class java.lang.Double") || typeString.equals("double")) {
|
|
|
|
|
+ value = Double.valueOf(value.toString());
|
|
|
|
|
+ } else if (typeString.equals("class java.lang.Float") || typeString.equals("float")) {
|
|
|
|
|
+ value = Float.valueOf(value.toString());
|
|
|
|
|
+ } else if (typeString.equals("class java.lang.Byte") || typeString.equals("byte")) {
|
|
|
|
|
+ value = Byte.valueOf(value.toString());
|
|
|
|
|
+ } else if (typeString.equals("class java.lang.Boolean") || typeString.equals("boolean")) {
|
|
|
|
|
+ value = Boolean.valueOf(value.toString());
|
|
|
|
|
+ } else if (typeString.equals("class com.alibaba.fastjson.JSONObject")) {
|
|
|
|
|
+ value = JSONObject.parseObject(value.toString());
|
|
|
|
|
+ } else if (typeString.startsWith("java.util.List")) {
|
|
|
|
|
+ Class<?> clazz = Object.class;
|
|
|
|
|
+ if (typeString.matches("^java.util.List<[\\s\\S]+?>$")) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ clazz = Class.forName(typeString.substring(typeString.indexOf("<") + 1, typeString.length() - 1));
|
|
|
|
|
+ } catch (ClassNotFoundException e) {
|
|
|
|
|
+ throw new IllegalStateException("无法转换为 " + typeString, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ String[] strs = value.toString().split(",[ ]*");
|
|
|
|
|
+ value = castList(strs, clazz);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new IllegalArgumentException("不支持的类型:type=" + type + ", value=" + value);
|
|
|
}
|
|
}
|
|
|
- return ArrayUtils.isEmpty((Object[]) obj);
|
|
|
|
|
}
|
|
}
|
|
|
- return (obj instanceof String && StringUtils.isEmpty(obj))
|
|
|
|
|
- || (obj instanceof Collection && CollectionUtils.isEmpty((Collection<?>) obj))
|
|
|
|
|
- || (obj instanceof Map && CollectionUtils.isEmpty((Map<?, ?>) obj));
|
|
|
|
|
|
|
+ if (!field.isAccessible()) {
|
|
|
|
|
+ field.setAccessible(true);
|
|
|
|
|
+ field.set(object, value);
|
|
|
|
|
+ field.setAccessible(false);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ field.set(object, value);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 将对象转为 String
|
|
|
|
|
|
|
+ * 转换 String 数组为指定对象列表
|
|
|
*
|
|
*
|
|
|
- * @param obj 对象
|
|
|
|
|
- * @return 转换的 String
|
|
|
|
|
|
|
+ * @param strs String 数组
|
|
|
|
|
+ * @param clazz 目标类型
|
|
|
|
|
+ * @param <T> 目标类型
|
|
|
|
|
+ * @return 对象列表
|
|
|
*/
|
|
*/
|
|
|
- public static String toString(Object obj) {
|
|
|
|
|
- if (obj == null) {
|
|
|
|
|
- return "";
|
|
|
|
|
- }
|
|
|
|
|
- if (obj instanceof String) {
|
|
|
|
|
- return (String) obj;
|
|
|
|
|
|
|
+ private static <T> List<T> castList(String[] strs, Class<T> clazz) {
|
|
|
|
|
+ if (ArrayUtils.isEmpty(strs)) {
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
- if (obj.getClass().isArray()) {
|
|
|
|
|
- if (obj instanceof long[]) {
|
|
|
|
|
- return Arrays.toString((long[]) obj);
|
|
|
|
|
- } else if (obj instanceof int[]) {
|
|
|
|
|
- return Arrays.toString((int[]) obj);
|
|
|
|
|
- } else if (obj instanceof short[]) {
|
|
|
|
|
- return Arrays.toString((short[]) 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 boolean[]) {
|
|
|
|
|
- return Arrays.toString((boolean[]) obj);
|
|
|
|
|
- } else if (obj instanceof float[]) {
|
|
|
|
|
- return Arrays.toString((float[]) obj);
|
|
|
|
|
- } else if (obj instanceof double[]) {
|
|
|
|
|
- return Arrays.toString((double[]) obj);
|
|
|
|
|
- }
|
|
|
|
|
- return Arrays.toString((Object[]) obj);
|
|
|
|
|
|
|
+ List<T> list = new ArrayList<>();
|
|
|
|
|
+ for (String str : strs) {
|
|
|
|
|
+ list.add(cast(str, clazz));
|
|
|
}
|
|
}
|
|
|
- return obj.toString();
|
|
|
|
|
|
|
+ return list;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 转换对象为指定类型
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param object 对象
|
|
|
|
|
+ * @param clazz 目标类型
|
|
|
|
|
+ * @param <T> 目标类型
|
|
|
|
|
+ * @return 目标
|
|
|
|
|
+ */
|
|
|
|
|
+ private static <T> T cast(Object object, Class<T> clazz) {
|
|
|
|
|
+ return object == null ? null : (T) object;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|