gradebookng/tool/src/java/org/sakaiproject/gradebookng/business/util/ImportGradesHelper.java
private static Map<Integer, ImportedColumn> mapHeaderRow(final String[] line) throws GbImportExportInvalidColumnException, GbImportExportDuplicateColumnException {

		// retain order
		final Map<Integer, ImportedColumn> mapping = new LinkedHashMap<Integer, ImportedColumn>();

		for (int i = 0; i < line.length; i++) {

			ImportedColumn column = null;

			log.debug("i: " + i);
			log.debug("line[i]: " + line[i]);

			if(i == USER_ID_POS) {
				column = new ImportedColumn();
				column.setType(ImportedColumn.Type.USER_ID);
			} else if(i == USER_NAME_POS) {
				column = new ImportedColumn();
				column.setType(ImportedColumn.Type.USER_NAME);
			} else {
				column = parseHeaderToColumn(trim(line[i]));
			}

			// check for duplicates
			if(mapping.values().contains(column)) {
				throw new GbImportExportDuplicateColumnException("Duplicate column header: " + column.getColumnTitle());
			}

			mapping.put(i, column);
		}

		return mapping;
	}
/**
	 * Takes a row of String[] data to determine the position of the columns so that we can correctly parse any arbitrary delimited file.
	 * This is required because when we iterate over the rest of the lines, we need to know what the column header is, so we can take the appropriate action.
	 *
	 * Note that some columns are determined positionally
	 *
	 * @param line the already split line
	 * @return LinkedHashMap to retain order
	 * @throws GbImportExportInvalidColumnException if a column doesn't map to any known format
	 * @throws GbImportExportDuplicateColumnException if there are duplicate column headers
	 */
Takes a row of String[] data to determine the position of the columns so that we can correctly parse any arbitrary delimited file.
This is required because when we iterate over the rest of the lines, we need to know what the column header is, so we can take the appropriate action.

Note that some columns are determined positionally

@param line the already split line
@return LinkedHashMap to retain order
@throws GbImportExportInvalidColumnException if a column doesn't map to any known format
@throws GbImportExportDuplicateColumnException if there are duplicate column headers
Takes a row of String [] data to determine the position of the columns so that we can correctly parse any arbitrary delimited file . This is required because when we iterate over the rest of the lines we need to know what the column header is so we can take the appropriate action . Note that some columns are determined positionally @param line the already split line @return LinkedHashMap to retain order @throws GbImportExportInvalidColumnException if a column doesn ' t map to any known format @throws GbImportExportDuplicateColumnException if there are duplicate column headers
private static Map<Integer, ImportedColumn> mapHeaderRow(final String[] line) throws GbImportExportInvalidColumnException, GbImportExportDuplicateColumnException {
		final Map<Integer, ImportedColumn> mapping = new LinkedHashMap<Integer, ImportedColumn>();
		for (int i = 0; i < line.length; i++) {
			ImportedColumn column = null;
			log.debug("i: " + i);
			log.debug("line[i]: " + line[i]);
			if(i == USER_ID_POS) {
				column = new ImportedColumn();
				column.setType(ImportedColumn.Type.USER_ID);
			} else if(i == USER_NAME_POS) {
				column = new ImportedColumn();
				column.setType(ImportedColumn.Type.USER_NAME);
			} else {
				column = parseHeaderToColumn(trim(line[i]));
			}
			if(mapping.values().contains(column)) {
				throw new GbImportExportDuplicateColumnException("Duplicate column header: " + column.getColumnTitle());
			}
			mapping.put(i, column);
		}
		return mapping;
	}
private static Map < Integer , ImportedColumn > mapHeaderRow ( final String [ ] line ) throws GbImportExportInvalidColumnException , GbImportExportDuplicateColumnException { final Map < Integer , ImportedColumn > mapping = new LinkedHashMap < Integer , ImportedColumn > ( ) ; for ( int i = 0 ; i < line . length ; i ++ ) { ImportedColumn column = null ; log . debug ( "i: " + i ) ; log . debug ( "line[i]: " + line [ i ] ) ; if ( i == USER_ID_POS ) { column = new ImportedColumn ( ) ; column . setType ( ImportedColumn . Type . USER_ID ) ; } else if ( i == USER_NAME_POS ) { column = new ImportedColumn ( ) ; column . setType ( ImportedColumn . Type . USER_NAME ) ; } else { column = parseHeaderToColumn ( trim ( line [ i ] ) ) ; } if ( mapping . values ( ) . contains ( column ) ) { throw new GbImportExportDuplicateColumnException ( "Duplicate column header: " + column . getColumnTitle ( ) ) ; } mapping . put ( i , column ) ; } return mapping ; }
Takes a row of String[] data to determine the position of the columns so that we can correctly parse any arbitrary delimited file.
Takes a row of String [] data to determine the position of the columns so that we can correctly parse any arbitrary delimited file .
// retain order // check for duplicates