本文整理匯總了Java中org.apache.commons.csv.CSVRecord.toMap方法的典型用法代碼示例。如果您正苦於以下問題:Java CSVRecord.toMap方法的具體用法?Java CSVRecord.toMap怎麽用?Java CSVRecord.toMap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.csv.CSVRecord
的用法示例。
在下文中一共展示了CSVRecord.toMap方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseDelimitedAreaFile
import org.apache.commons.csv.CSVRecord; //導入方法依賴的package包/類
private Map<String,String> parseDelimitedAreaFile(Integer exercise, Integer exercise_order) {
Map<String,String> list;
CSVParser parser;
URL resource;
CSVFormat csvFormat;
Charset charset;
list = new HashMap<String,String>();
try {
resource =ResourceHelper.getResource(isFromGameResourceInput(),this.gamePath,this.setPath,exercise.toString(), exercise_order.toString(),"areaDelimitada.csv");
charset= FileEncodingDetectorHelper.guessEncodingAndGetCharset(resource);
csvFormat = CSVFormatHelper.getDefaultCSVFormat();
parser = CSVParser.parse(resource, charset, csvFormat);
for (CSVRecord record : parser )
list = record.toMap();
}
catch (IOException e) {
log.error("Fail",e);
}
return list;
}
示例2: parse
import org.apache.commons.csv.CSVRecord; //導入方法依賴的package包/類
public List<Map<String,String>> parse() throws BuenOjoCSVParserException {
List<Map<String,String>> list = new ArrayList<>();
CSVParser parser = null;
try {
parser = CSVFormat.RFC4180.withHeader()
.withDelimiter(',')
.withAllowMissingColumnNames(true)
.parse(new InputStreamReader(this.inputStreamSource.getInputStream()));
} catch (IOException e) {
throw new BuenOjoCSVParserException(e.getMessage());
}
for (CSVRecord record :parser) {
Map<String,String> map = record.toMap();
list.add(map);
}
return list;
}
示例3: getTypes
import org.apache.commons.csv.CSVRecord; //導入方法依賴的package包/類
private static Map<String, Type> getTypes(List<String> columns, Iterable<CSVRecord> records, Set<String> nullStrings) {
// linked hash map has predictable iteration order
// in particular, it retrieves keys in the order they are put in
// we want this to make sure columns aren't in a different order than the file
// they were read from (can be confusing, and messes up tests)
Map<String, Type> types = new LinkedHashMap<>();
for (CSVRecord record : records) {
Map<String, String> recordMap = record.toMap();
for (String key : columns) {
String val = recordMap.get(key);
if (val == null ||
(types.containsKey(key) && types.get(key) == null) ||
nullStrings.contains(val)) {
continue;
}
Type type;
try {
Integer.parseInt(val);
type = Type.INT_TYPE;
} catch (NumberFormatException e) {
try {
Double.parseDouble(val);
type = Type.DOUBLE_TYPE;
} catch (NumberFormatException ee) {
type = null;
}
}
if (!types.containsKey(key)) {
types.put(key, type);
} else {
if (!types.get(key).equals(type)) {
types.put(key, null);
}
}
}
}
return types;
}