@ Override public List < T > parse ( ) throws IllegalAccessException , InstantiationException , InvocationTargetException , NoSuchMethodException { List < T > list = new ArrayList <> ( ) ; Map < Method , TableCellMapping > cellMappingByMethod = ImporterUtils . getMappedMethods ( clazz , group ) ; final Constructor < T > constructor = clazz . getDeclaredConstructor ( ) ; constructor . setAccessible ( true ) ; for ( int i = 0 ; i < csvLines . size ( ) ; i ++ ) { final String line = csvLines . get ( i ) ; if ( ( i + 1 ) <= headersRows ) { continue ; } List < String > fields = split ( line ) ; T instance = constructor . newInstance ( ) ; for ( Entry < Method , TableCellMapping > methodTcm : cellMappingByMethod . entrySet ( ) ) { Method method = methodTcm . getKey ( ) ; method . setAccessible ( true ) ; TableCellMapping tcm = methodTcm . getValue ( ) ; String value = getValueOrEmpty ( fields , tcm . columnIndex ( ) ) ; Converter < ? , ? > converter = tcm . converter ( ) . newInstance ( ) ; Object obj = converter . apply ( value ) ; method . invoke ( instance , obj ) ; } list . add ( instance ) ; } return list ; }
Parser file to list of T objects