本文整理汇总了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;
}