List of usage examples for org.apache.commons.csv CSVRecord get
public String get(final String name)
From source file:javalibs.CSVDataNormalizer.java
private Pair getMaxMinFromCol(String columnName) { double max = Double.MIN_VALUE; double min = Double.MAX_VALUE; for (CSVRecord record : this.allRecords) { double val = NumUtils.getDoubleFromStr(record.get(columnName)); // NOTE: Floating point errors aren't really that important here, don't waste time on // a proper floating point comparison if (val > max) max = val; if (val < min) min = val; }// w w w . j a v a 2 s. com return new Pair(max, min); }
From source file:com.hack23.cia.service.external.vdem.impl.VdemServiceImpl.java
/** * Gets the country question data.// w ww .j a v a 2s.co m * * @return the country question data */ @Override public List<CountryQuestionData> getCountryQuestionData() { final List<CountryQuestionData> list = new ArrayList<>(); final List<Question> questions = getQuestions(); try { final Reader in = new InputStreamReader(new URL(VDEM_DATA_DOWNLOAD_URL).openStream()); final CSVParser parser = new CSVParser(in, CSVFormat.EXCEL.withHeader().withDelimiter(',')); for (final CSVRecord record : parser) { final String countryName = record.get("country_name"); final String countryId = record.get("country_id"); final String countryTextId = record.get("country_text_id"); final String year = record.get("year"); final String gapStart = record.get("gapstart"); final String gapEnd = record.get("gapend"); final String codingEnd = record.get("codingend"); final String cowCode = record.get("COWcode"); final int currentSize = list.size(); LOGGER.info("Loading vdem data for country:{} year {} ", countryName, year); for (final Question question : questions) { addQuestionDataToList(list, record, countryName, countryId, countryTextId, year, gapStart, gapEnd, codingEnd, cowCode, question); } final int afterSize = list.size(); LOGGER.info("Found vdem data for country:{} year:{} data points:{}", countryName, year, afterSize - currentSize); } parser.close(); } catch (final IOException e) { LOGGER.warn("Problem loading vdem data", e); } return list; }
From source file:com.cotrino.langnet.GenerateVisualization.java
private void generateLanguages(String summaryFile, String languagesFile) throws IOException { HashMap<String, Integer> list = new HashMap<String, Integer>(); Reader reader = new FileReader(summaryFile); CSVParser parser = new CSVParser(reader, csvFormat); for (CSVRecord record : parser) { String languageA = record.get("LanguageA"); String languageB = record.get("LanguageB"); int words = Integer.parseInt(record.get("ExecutedComparisons")); list.put(languageA, Math.max(words, list.getOrDefault(languageA, 0))); list.put(languageB, Math.max(words, list.getOrDefault(languageB, 0))); }//from w w w . j ava2 s. c om parser.close(); reader.close(); String content = "Language;Words;Family;\n"; for (String language : list.keySet()) { content += language + ";" + list.get(language) + ";Romance;\n"; } IOUtil.write(languagesFile, content); }
From source file:com.nordpos.device.csv.FileCSVInputOutput.java
@Override public ProductIO recieveProduct() throws DeviceInputOutputException { CSVRecord record; ProductIO product = new ProductIO(); while (recIterator.hasNext()) { record = (CSVRecord) recIterator.next(); product.setCode(record.get(PRODUCT_CODE)); String qty = record.get(PRODUCT_QUANTITY); product.setQuantity(Double.parseDouble(qty)); return product; }/*from ww w . j a v a2 s .c o m*/ return null; }
From source file:de.fhws.ifactory.api.utils.UserCSVToRequestTransformer.java
@Override protected UserViewModel transformCSVRecordToModel(CSVRecord record) { // ###(csv_headers) You can edit below this line ### final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(this.datePattern); formatter.withLocale(Locale.GERMANY); final UserViewModel model = new UserViewModel(); model.setFirstName(record.get("firstName")); model.setLastName(record.get("lastName")); model.setRole(Integer.parseInt(record.get("role"))); model.setIsGuest(Integer.parseInt(record.get("isGuest"))); model.setId(Integer.parseInt(record.get("id"))); model.setEmail(record.get("email")); return model; // ###(csv_headers) You can edit above this line ### }
From source file:ColdestWeather.ColdestWeather.java
public CSVRecord checkLowestHumidity(CSVRecord currentRow, CSVRecord lowestSoFar) { if (lowestSoFar == null) { lowestSoFar = currentRow;/*from ww w. j a v a 2s. c om*/ } else { if (!currentRow.get("Humidity").contains("N/A")) { int currentHumidity = Integer.parseInt(currentRow.get("Humidity")); int lowestHumidity = Integer.parseInt(lowestSoFar.get("Humidity")); if (currentHumidity < lowestHumidity) { lowestSoFar = currentRow; } } } return lowestSoFar; }
From source file:biz.ganttproject.impex.csv.RecordGroup.java
protected boolean hasMandatoryFields(CSVRecord record) { for (String s : myMandatoryFields) { if (!record.isSet(s)) { return false; }//w w w .j a v a2 s . c o m if (Strings.isNullOrEmpty(record.get(s))) { return false; } } return true; }
From source file:de.fhws.ifactory.api.utils.SessionCSVToRequestTransformer.java
@Override protected SessionViewModel transformCSVRecordToModel(CSVRecord record) { // ###(csv_headers) You can edit below this line ### final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(this.datePattern); formatter.withLocale(Locale.GERMANY); final SessionViewModel model = new SessionViewModel(); model.setId(Integer.parseInt(record.get("id"))); model.setSecret(record.get("secret")); return model; // ###(csv_headers) You can edit above this line ### }
From source file:edu.emory.mathcs.nlp.zzz.CSVSentiment.java
public void toTXT(String inputFile) throws Exception { CSVParser parser = new CSVParser(IOUtils.createBufferedReader(inputFile), CSVFormat.DEFAULT); PrintStream fout = IOUtils.createBufferedPrintStream(inputFile + ".txt"); List<CSVRecord> records = parser.getRecords(); CSVRecord record; System.out.println(inputFile); for (int i = 0; i < records.size(); i++) { if (i == 0) continue; record = records.get(i);//from w w w. ja v a 2 s. co m fout.println(record.get(6)); } fout.close(); parser.close(); }
From source file:com.github.jferard.pgloaderutils.sniffer.csv.RowSignaturesAnalyzer.java
public char[] getSignature(final CSVRecord record, final int firstRowSize) { final char[] signature = new char[firstRowSize]; for (int col = 0; col < firstRowSize; col++) { if (col < record.size()) { final String s = record.get(col); signature[col] = this.getType(s); } else//from ww w . j av a 2 s . co m signature[col] = '?'; } return signature; }