MappingUtils { public static Object prepareIndexedCollection(Class<?> collectionType, Object existingCollection, Object collectionEntry, int index) { Object result = null; if (collectionType.isArray()) { result = prepareIndexedArray(collectionType, existingCollection, collectionEntry, index); } else if (Collection.class.isAssignableFrom(collectionType)) { result = prepareIndexedCollectionType(collectionType, existingCollection, collectionEntry, index); } else { throwMappingException("Only types java.lang.Object[] and java.util.Collection are supported for indexed properties."); } return result; } private  MappingUtils(); static String getClassNameWithoutPackage(Class<?> clazz); static boolean isSupportedCollection(Class<?> aClass); static boolean isSupportedMap(Class<?> aClass); static void throwMappingException(Throwable e); static void throwMappingException(String msg); static void throwMappingException(String msg, Throwable cause); static boolean isBlankOrNull(String value); static Throwable getRootCause(Throwable ex); static String getMappedParentFieldKey(Object destObj, FieldMap destFieldMap); static Class<?> findCustomConverter(Cache converterByDestTypeCache, CustomConverterContainer customConverterContainer,
                                               Class<?> srcClass, Class<?> destClass); static Class<?> determineCustomConverter(FieldMap fieldMap, Cache converterByDestTypeCache,
                                                    CustomConverterContainer customConverterContainer, Class<?> srcClass, Class<?> destClass); static void reverseFields(FieldMap source, FieldMap reversed); static void reverseFields(ClassMap source, ClassMap destination, BeanContainer beanContainer); static Object getIndexedValue(Object collection, int index); static void applyGlobalCopyByReference(Configuration globalConfig, FieldMap fieldMap, ClassMap classMap); static Class<?> loadClass(String name, BeanContainer beanContainer); static Class<?> getRealClass(Class<?> clazz, BeanContainer beanContainer); static T deProxy(T object, BeanContainer beanContainer); static boolean isProxy(Class<?> clazz, BeanContainer beanContainer); static Object prepareIndexedCollection(Class<?> collectionType, Object existingCollection, Object collectionEntry,
                                                  int index); static boolean isDeepMapping(String mapping); static boolean isEnumType(Class<?> srcFieldClass); static boolean isEnumType(Class<?> srcFieldClass, Class<?> destFieldType); static List<Class<?>> getSuperClassesAndInterfaces(Class<?> srcClass, BeanContainer beanContainer); @SuppressWarnings("unchecked") static List<Class<?>> getInterfaceHierarchy(Class<?> srcClass, BeanContainer beanContainer);  }
@Test public void testPrepareIndexedCollection_Array() { String[] result = (String[])MappingUtils.prepareIndexedCollection(String[].class, null, "some entry", 0); assertTrue(Arrays.equals(new String[] {"some entry"}, result)); result = (String[])MappingUtils.prepareIndexedCollection(String[].class, null, "some entry", 3); assertTrue(Arrays.equals(new String[] {null, null, null, "some entry"}, result)); result = (String[])MappingUtils.prepareIndexedCollection(String[].class, new String[] {"a", "b", "c"}, "some entry", 5); assertTrue(Arrays.equals(new String[] {"a", "b", "c", null, null, "some entry"}, result)); }
@Test public void testPrepareIndexedCollection_List() { List<?> result = (List<?>)MappingUtils.prepareIndexedCollection(List.class, null, "some entry", 0); assertEquals(Arrays.asList("some entry"), result); result = (List<?>)MappingUtils.prepareIndexedCollection(List.class, null, "some entry", 3); assertEquals(Arrays.asList(null, null, null, "some entry"), result); result = (List<?>)MappingUtils.prepareIndexedCollection(List.class, Arrays.asList("a", "b", "c"), "some entry", 5); assertEquals(Arrays.asList("a", "b", "c", null, null, "some entry"), result); }
@Test public void testPrepareIndexedCollection_Vector() { Vector<?> result = (Vector<?>)MappingUtils.prepareIndexedCollection(Vector.class, null, "some entry", 0); assertEquals(new Vector<>(Arrays.asList("some entry")), result); result = (Vector<?>)MappingUtils.prepareIndexedCollection(Vector.class, null, "some entry", 3); assertEquals(new Vector<>(Arrays.asList(null, null, null, "some entry")), result); result = (Vector<?>)MappingUtils.prepareIndexedCollection(Vector.class, new Vector<>(Arrays.asList("a", "b", "c")), "some entry", 5); assertEquals(new Vector<>(Arrays.asList("a", "b", "c", null, null, "some entry")), result); }
@Test public void testPrepareIndexedCollection_ArrayResize() { String[] result = (String[])MappingUtils.prepareIndexedCollection(String[].class, new String[] {"a", "b"}, "some entry", 3); assertTrue(Arrays.equals(new String[] {"a", "b", null, "some entry"}, result)); }
@Test(expected = MappingException.class) public void testPrepareIndexedCollection_UnsupportedType() { MappingUtils.prepareIndexedCollection(String.class, null, "some entry", 0); }