@Test public void shouldExtractNullForNullTargetType() { final Object result = resultExtractor.extractObjectFromList(null, null); assertThat(result).isNull(); }
public Object extractObjectFromList(List<Object> list, Class<?> targetType) { Object value = null; if (targetType != null && targetType.isAssignableFrom(list.getClass())) { value = list; } else if (targetType != null && objectFactory.isCollection(targetType)) { value = objectFactory.create(targetType); MetaObject metaObject = configuration.newMetaObject(value); metaObject.addAll(list); } else if (targetType != null && targetType.isArray()) { Class<?> arrayComponentType = targetType.getComponentType(); Object array = Array.newInstance(arrayComponentType, list.size()); if (arrayComponentType.isPrimitive()) { for (int i = 0; i < list.size(); i++) { Array.set(array, i, list.get(i)); } value = array; } else { value = list.toArray((Object[])array); } } else { if (list != null && list.size() > 1) { throw new ExecutorException("Statement returned more than one row, where no more than one was expected."); } else if (list != null && list.size() == 1) { value = list.get(0); } } return value; }
ResultExtractor { public Object extractObjectFromList(List<Object> list, Class<?> targetType) { Object value = null; if (targetType != null && targetType.isAssignableFrom(list.getClass())) { value = list; } else if (targetType != null && objectFactory.isCollection(targetType)) { value = objectFactory.create(targetType); MetaObject metaObject = configuration.newMetaObject(value); metaObject.addAll(list); } else if (targetType != null && targetType.isArray()) { Class<?> arrayComponentType = targetType.getComponentType(); Object array = Array.newInstance(arrayComponentType, list.size()); if (arrayComponentType.isPrimitive()) { for (int i = 0; i < list.size(); i++) { Array.set(array, i, list.get(i)); } value = array; } else { value = list.toArray((Object[])array); } } else { if (list != null && list.size() > 1) { throw new ExecutorException("Statement returned more than one row, where no more than one was expected."); } else if (list != null && list.size() == 1) { value = list.get(0); } } return value; } }
ResultExtractor { public Object extractObjectFromList(List<Object> list, Class<?> targetType) { Object value = null; if (targetType != null && targetType.isAssignableFrom(list.getClass())) { value = list; } else if (targetType != null && objectFactory.isCollection(targetType)) { value = objectFactory.create(targetType); MetaObject metaObject = configuration.newMetaObject(value); metaObject.addAll(list); } else if (targetType != null && targetType.isArray()) { Class<?> arrayComponentType = targetType.getComponentType(); Object array = Array.newInstance(arrayComponentType, list.size()); if (arrayComponentType.isPrimitive()) { for (int i = 0; i < list.size(); i++) { Array.set(array, i, list.get(i)); } value = array; } else { value = list.toArray((Object[])array); } } else { if (list != null && list.size() > 1) { throw new ExecutorException("Statement returned more than one row, where no more than one was expected."); } else if (list != null && list.size() == 1) { value = list.get(0); } } return value; } ResultExtractor(Configuration configuration, ObjectFactory objectFactory); }
ResultExtractor { public Object extractObjectFromList(List<Object> list, Class<?> targetType) { Object value = null; if (targetType != null && targetType.isAssignableFrom(list.getClass())) { value = list; } else if (targetType != null && objectFactory.isCollection(targetType)) { value = objectFactory.create(targetType); MetaObject metaObject = configuration.newMetaObject(value); metaObject.addAll(list); } else if (targetType != null && targetType.isArray()) { Class<?> arrayComponentType = targetType.getComponentType(); Object array = Array.newInstance(arrayComponentType, list.size()); if (arrayComponentType.isPrimitive()) { for (int i = 0; i < list.size(); i++) { Array.set(array, i, list.get(i)); } value = array; } else { value = list.toArray((Object[])array); } } else { if (list != null && list.size() > 1) { throw new ExecutorException("Statement returned more than one row, where no more than one was expected."); } else if (list != null && list.size() == 1) { value = list.get(0); } } return value; } ResultExtractor(Configuration configuration, ObjectFactory objectFactory); Object extractObjectFromList(List<Object> list, Class<?> targetType); }
ResultExtractor { public Object extractObjectFromList(List<Object> list, Class<?> targetType) { Object value = null; if (targetType != null && targetType.isAssignableFrom(list.getClass())) { value = list; } else if (targetType != null && objectFactory.isCollection(targetType)) { value = objectFactory.create(targetType); MetaObject metaObject = configuration.newMetaObject(value); metaObject.addAll(list); } else if (targetType != null && targetType.isArray()) { Class<?> arrayComponentType = targetType.getComponentType(); Object array = Array.newInstance(arrayComponentType, list.size()); if (arrayComponentType.isPrimitive()) { for (int i = 0; i < list.size(); i++) { Array.set(array, i, list.get(i)); } value = array; } else { value = list.toArray((Object[])array); } } else { if (list != null && list.size() > 1) { throw new ExecutorException("Statement returned more than one row, where no more than one was expected."); } else if (list != null && list.size() == 1) { value = list.get(0); } } return value; } ResultExtractor(Configuration configuration, ObjectFactory objectFactory); Object extractObjectFromList(List<Object> list, Class<?> targetType);  }