@Test void getEmptyImplementationForMapInterface() { Map<?, ?> map = ReflectionUtils.getEmptyImplementationForMapInterface(SortedMap.class); assertThat(map).isInstanceOf(TreeMap.class).isEmpty(); }
public static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface) { Map<?, ?> map = new HashMap<>(); if (ConcurrentNavigableMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentSkipListMap<>(); } else if (ConcurrentMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentHashMap<>(); } else if (NavigableMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } else if (SortedMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } return map; }
ReflectionUtils { public static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface) { Map<?, ?> map = new HashMap<>(); if (ConcurrentNavigableMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentSkipListMap<>(); } else if (ConcurrentMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentHashMap<>(); } else if (NavigableMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } else if (SortedMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } return map; } }
ReflectionUtils { public static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface) { Map<?, ?> map = new HashMap<>(); if (ConcurrentNavigableMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentSkipListMap<>(); } else if (ConcurrentMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentHashMap<>(); } else if (NavigableMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } else if (SortedMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } return map; } private  ReflectionUtils(); }
ReflectionUtils { public static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface) { Map<?, ?> map = new HashMap<>(); if (ConcurrentNavigableMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentSkipListMap<>(); } else if (ConcurrentMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentHashMap<>(); } else if (NavigableMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } else if (SortedMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } return map; } private  ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments); }
ReflectionUtils { public static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface) { Map<?, ?> map = new HashMap<>(); if (ConcurrentNavigableMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentSkipListMap<>(); } else if (ConcurrentMap.class.isAssignableFrom(mapInterface)) { map = new ConcurrentHashMap<>(); } else if (NavigableMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } else if (SortedMap.class.isAssignableFrom(mapInterface)) { map = new TreeMap<>(); } return map; } private  ReflectionUtils(); @SuppressWarnings("unchecked") static Randomizer<T> asRandomizer(final Supplier<T> supplier); static List<Field> getDeclaredFields(T type); static List<Field> getInheritedFields(Class<?> type); static void setProperty(final Object object, final Field field, final Object value); static void setFieldValue(final Object object, final Field field, final Object value); static Object getFieldValue(final Object object, final Field field); static Class<?> getWrapperType(Class<?> primitiveType); static boolean isPrimitiveFieldWithDefaultValue(final Object object, final Field field); static boolean isStatic(final Field field); static boolean isInterface(final Class<?> type); static boolean isAbstract(final Class<T> type); static boolean isPublic(final Class<T> type); static boolean isArrayType(final Class<?> type); static boolean isEnumType(final Class<?> type); static boolean isCollectionType(final Class<?> type); static boolean isCollectionType(final Type type); static boolean isPopulatable(final Type type); static boolean isIntrospectable(final Class<?> type); static boolean isMapType(final Class<?> type); static boolean isJdkBuiltIn(final Class<?> type); static boolean isParameterizedType(final Type type); static boolean isWildcardType(final Type type); static boolean isTypeVariable(final Type type); static List<Class<?>> getPublicConcreteSubTypesOf(final Class<T> type); static List<Class<?>> filterSameParameterizedTypes(final List<Class<?>> types, final Type type); static T getAnnotation(Field field, Class<T> annotationType); static boolean isAnnotationPresent(Field field, Class<? extends Annotation> annotationType); static Collection<?> getEmptyImplementationForCollectionInterface(final Class<?> collectionInterface); static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize); static Map<?, ?> getEmptyImplementationForMapInterface(final Class<?> mapInterface); static Optional<Method> getReadMethod(Field field); @SuppressWarnings("unchecked") static Randomizer<T> newInstance(final Class<T> type, final RandomizerArgument[] randomizerArguments);  }