|
@@ -21,6 +21,7 @@ import java.beans.PropertyDescriptor;
|
|
|
import java.lang.reflect.Array;
|
|
|
import java.lang.reflect.Field;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.function.BiFunction;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.function.Supplier;
|
|
@@ -513,6 +514,8 @@ public final class FastBeanCopier {
|
|
|
|
|
|
if (targetClass == List.class) {
|
|
|
return new ArrayList<>();
|
|
|
+ } else if (targetClass == ConcurrentHashMap.KeySetView.class) {
|
|
|
+ return ConcurrentHashMap.newKeySet();
|
|
|
} else if (targetClass == Set.class) {
|
|
|
return new HashSet<>();
|
|
|
} else if (targetClass == Queue.class) {
|
|
@@ -568,7 +571,7 @@ public final class FastBeanCopier {
|
|
|
return (T) new Date(((Date) source).getTime());
|
|
|
}
|
|
|
}
|
|
|
- if (Collection.class.isAssignableFrom(targetClass)) {
|
|
|
+ if (target.isCollectionType()) {
|
|
|
Collection collection = newCollection(targetClass);
|
|
|
Collection sourceCollection;
|
|
|
if (source instanceof Collection) {
|
|
@@ -619,7 +622,7 @@ public final class FastBeanCopier {
|
|
|
Enum t = ((Enum<?>) e);
|
|
|
if ((t.name().equalsIgnoreCase(strSource)
|
|
|
|| Objects.equals(String.valueOf(t.ordinal()), strSource))) {
|
|
|
- return (T)e;
|
|
|
+ return (T) e;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -642,7 +645,7 @@ public final class FastBeanCopier {
|
|
|
|
|
|
if (targetClass == Map.class) {
|
|
|
if (source instanceof Map) {
|
|
|
- return (T) new HashMap(((Map<?, ?>) source));
|
|
|
+ return (T) copyMap(((Map<?, ?>) source));
|
|
|
}
|
|
|
ClassDescription sourType = ClassDescriptions.getDescription(source.getClass());
|
|
|
return (T) copy(source, Maps.newHashMapWithExpectedSize(sourType.getFieldSize()));
|
|
@@ -656,6 +659,22 @@ public final class FastBeanCopier {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private Map<?, ?> copyMap(Map<?, ?> map) {
|
|
|
+ if (map instanceof TreeMap) {
|
|
|
+ return new TreeMap<>(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (map instanceof LinkedHashMap) {
|
|
|
+ return new LinkedHashMap<>(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (map instanceof ConcurrentHashMap) {
|
|
|
+ return new ConcurrentHashMap<>(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ return new HashMap<>(map);
|
|
|
+ }
|
|
|
+
|
|
|
private Object converterByApache(Class<?> targetClass, Object source) {
|
|
|
org.apache.commons.beanutils.Converter converter = convertUtils.lookup(targetClass);
|
|
|
if (null != converter) {
|