DATACMNS-1435 - Fixed Vavr Map component and value type detection.
This commit is contained in:
@@ -28,16 +28,7 @@ import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.lang.reflect.WildcardType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -61,14 +52,10 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
|
||||
static {
|
||||
|
||||
ClassLoader classLoader = TypeDiscoverer.class.getClassLoader();
|
||||
|
||||
Set<Class<?>> mapTypes = new HashSet<>();
|
||||
mapTypes.add(Map.class);
|
||||
|
||||
try {
|
||||
mapTypes.add(ClassUtils.forName("javaslang.collection.Map", classLoader));
|
||||
} catch (ClassNotFoundException o_O) {}
|
||||
tryToAddClassTo("javaslang.collection.Map", mapTypes);
|
||||
tryToAddClassTo("io.vavr.collection.Map", mapTypes);
|
||||
|
||||
MAP_TYPES = mapTypes.toArray(new Class[0]);
|
||||
}
|
||||
@@ -569,6 +556,19 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to load the class with the given name and adds it to the given {@link Set} of classes if present.
|
||||
*
|
||||
* @param className must not be {@literal null} or empty.
|
||||
* @param classes must not be {@literal null}.
|
||||
*/
|
||||
private static final void tryToAddClassTo(String className, Set<Class<?>> classes) {
|
||||
|
||||
try {
|
||||
classes.add(ClassUtils.forName(className, TypeDiscoverer.class.getClassLoader()));
|
||||
} catch (ClassNotFoundException o_O) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* A synthetic {@link ParameterizedType}.
|
||||
*
|
||||
|
||||
@@ -392,7 +392,17 @@ public class ClassTypeInformationUnitTests {
|
||||
@Test // DATACMNS-940
|
||||
public void detectsJavaslangMapComponentAndValueType() {
|
||||
|
||||
ClassTypeInformation<SampleMap> information = ClassTypeInformation.from(SampleMap.class);
|
||||
ClassTypeInformation<JavaslangSampleMap> information = ClassTypeInformation.from(JavaslangSampleMap.class);
|
||||
|
||||
assertThat(information.getComponentType().getType()).isAssignableFrom(String.class);
|
||||
|
||||
assertThat(information.getMapValueType().getType()).isAssignableFrom(Integer.class);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1434
|
||||
public void detectsVavrMapComponentAndValueType() {
|
||||
|
||||
ClassTypeInformation<VavrSampleMap> information = ClassTypeInformation.from(VavrSampleMap.class);
|
||||
|
||||
assertThat(information.getComponentType().getType()).isAssignableFrom(String.class);
|
||||
|
||||
@@ -611,7 +621,9 @@ public class ClassTypeInformationUnitTests {
|
||||
|
||||
static interface SampleTraversable extends Traversable<Integer> {}
|
||||
|
||||
static interface SampleMap extends javaslang.collection.Map<String, Integer> {}
|
||||
static interface JavaslangSampleMap extends javaslang.collection.Map<String, Integer> {}
|
||||
|
||||
static interface VavrSampleMap extends io.vavr.collection.Map<String, Integer> {}
|
||||
|
||||
// DATACMNS-1138
|
||||
|
||||
|
||||
Reference in New Issue
Block a user