/** * Setter for the column mapping. * This mapping is for reading. Use of this method in conjunction with * writing is undefined. * * @param columnMapping Column names to be mapped. */ public void setColumnMapping(String... columnMapping) { if (columnMapping != null) { headerIndex.initializeHeaderIndex(columnMapping); } else { headerIndex.clear(); } columnsExplicitlySet = true; }
/** * This method generates a header that can be used for writing beans of the * type provided back to a file. * <p>The ordering of the headers is determined by the * {@link com.opencsv.bean.FieldMap} in use.</p> * <p>This method should be called first by all overriding classes to make * certain {@link #headerIndex} is properly initialized.</p> */ // The rest of the Javadoc is inherited @Override public String[] generateHeader(T bean) throws CsvRequiredFieldEmptyException { if(type == null) { throw new IllegalStateException(ResourceBundle .getBundle(ICSVParser.DEFAULT_BUNDLE_NAME, errorLocale) .getString("type.before.header")); } // Always take what's been given or previously determined first. if(headerIndex.isEmpty()) { String[] header = getFieldMap().generateHeader(bean); headerIndex.initializeHeaderIndex(header); return header; } // Otherwise, put headers in the right places. return headerIndex.getHeaderIndex(); }
headerIndex.initializeHeaderIndex(header);