List of usage examples for org.apache.commons.csv CSVRecord get
public String get(final String name)
From source file:loternik.MyService.java
public ArrayList<CSVRecord> getRecords(String teryt, String okreg) throws FileNotFoundException, IOException { FileReader file = new FileReader("kandydaci.csv"); CSVParser parser = new CSVParser(file, CSVFormat.EXCEL.withHeader().withDelimiter(';')); ArrayList<CSVRecord> output = new ArrayList<CSVRecord>(); for (CSVRecord csvRecord : parser) { if (teryt.equals(csvRecord.get("teryt")) && okreg.equals(csvRecord.get("Okreg"))) { output.add(csvRecord);/*from w w w . j a v a2 s .co m*/ } } return output; }
From source file:loternik.MyService.java
public ArrayList<CSVRecord> getRecordsByName(String name, String okreg) throws FileNotFoundException, IOException { FileReader file = new FileReader("kandydaci.csv"); CSVParser parser = new CSVParser(file, CSVFormat.EXCEL.withHeader().withDelimiter(';')); ArrayList<CSVRecord> output = new ArrayList<CSVRecord>(); for (CSVRecord csvRecord : parser) { if (name.equals(csvRecord.get("Kandydat_do")) && okreg.equals(csvRecord.get("Okreg"))) { output.add(csvRecord);//from w ww . j a v a 2 s . c o m } } return output; }
From source file:com.ibm.g11n.pipeline.example.CSVFilter.java
@Override public LanguageBundle parse(InputStream inStream, FilterOptions options) throws IOException, ResourceFilterException { LanguageBundleBuilder bundleBuilder = new LanguageBundleBuilder(true); CSVParser parser = CSVParser.parse(inStream, StandardCharsets.UTF_8, CSVFormat.RFC4180.withHeader("key", "value").withSkipHeaderRecord(true)); for (CSVRecord record : parser) { String key = record.get(0); String value = record.get(1); bundleBuilder.addResourceString(key, value); }/*from www .j av a 2 s . c o m*/ return bundleBuilder.build(); }
From source file:de.thomasvolk.genexample.model.CSVPassagierFactory.java
@Override protected List<Passagier> lesePassagiere(InputStream is, int anzahl) throws IOException { List<Passagier> passagiere = new ArrayList<>(); Reader in = new InputStreamReader(is); Iterator<CSVRecord> records = CSVFormat.EXCEL.withHeader().parse(in).iterator(); int i = 0;//from w w w.ja v a 2 s . c om while (records.hasNext() && i < anzahl) { CSVRecord record = records.next(); i++; int fahrtrichtung = getWertung(record.get(IN_FAHRTRICHTUNG)); int fensterplatz = getWertung(record.get(FENSTERPLATZ)); int abteil = getWertung(record.get(ABTEIL)); Wertung wertung = new Wertung(fensterplatz, abteil, fahrtrichtung); passagiere.add(new Passagier(i, wertung)); } return passagiere; }
From source file:algoritma.LoadData.java
public void read(String filePath, int confi) throws FileNotFoundException, IOException { FileReader fileReader = null; CSVParser csvFileParser = null;//from www . java 2 s .c om CSVFormat csvFileFormat = CSVFormat.EXCEL.withFirstRecordAsHeader(); fileReader = new FileReader(filePath); csvFileParser = new CSVParser(fileReader, csvFileFormat); List csvRecords = csvFileParser.getRecords(); for (int i = 0; i < csvRecords.size(); i++) { CSVRecord record = (CSVRecord) csvRecords.get(i); double confidence = Double.parseDouble(record.get("confidence")); if (confidence >= confi) { Point p = new Point(); p.setBrightness(Double.parseDouble(record.get("brightness"))); p.setBright_t31(Double.parseDouble(record.get("bright_t31"))); p.setFrp(Double.parseDouble(record.get("frp"))); p.add(p); } } }
From source file:com.ibm.g11n.pipeline.example.CSVFilter.java
@Override public void merge(InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle, FilterOptions options) throws IOException, ResourceFilterException { // create key-value map Map<String, String> kvMap = new HashMap<String, String>(); for (ResourceString resString : languageBundle.getResourceStrings()) { kvMap.put(resString.getKey(), resString.getValue()); }//from ww w . j a v a 2 s . c om CSVParser parser = CSVParser.parse(baseStream, StandardCharsets.UTF_8, CSVFormat.RFC4180.withHeader("key", "value").withSkipHeaderRecord(true)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outStream, StandardCharsets.UTF_8)); CSVPrinter printer = CSVFormat.RFC4180.withHeader("key", "value").print(writer); for (CSVRecord record : parser) { String key = record.get(0); String value = record.get(1); String trValue = kvMap.get(key); if (trValue != null) { value = trValue; } printer.printRecord(key, value); } printer.flush(); }
From source file:com.chargebee.CSV.PhoneBook.PhoneBook2.PhoneBook.java
private void directory(CSVParser parser) { HashMap<String, ArrayList> map = new HashMap(); for (CSVRecord record : parser) { ArrayList<Person> person = new ArrayList(); Person p = new Person(record.get("Name"), record.get("Address"), new Phone(record.get("Mobile"), record.get("Home"), record.get("Work"))); if (!map.containsKey(record.get("Name"))) { person.add(p);/*from ww w . ja v a 2s. c o m*/ map.put(record.get("Name"), person); continue; } person = map.get(record.get("Name")); person.add(p); map.put(record.get("Name"), person); } display(map); }
From source file:com.publictransitanalytics.scoregenerator.datalayer.directories.GTFSReadingTripDetailsDirectory.java
private void parseTripsFile(final Reader tripReader) throws IOException, InterruptedException { final CSVParser tripParser = new CSVParser(tripReader, CSVFormat.DEFAULT.withHeader()); final List<CSVRecord> tripRecords = tripParser.getRecords(); for (CSVRecord record : tripRecords) { final String rawTripId = record.get("trip_id"); final String routeId = record.get("route_id"); final String serviceType = record.get("service_id"); populateTripDetail(rawTripId, routeId, serviceType); }//ww w .j a va 2s . c om }
From source file:loternik.MyService.java
public String getHelloMessage(String teryt, String okreg) { FileReader file = null;/* ww w .ja v a2 s . co m*/ try { String output = ""; file = new FileReader("kandydaci.csv"); CSVParser parser = new CSVParser(file, CSVFormat.EXCEL.withHeader().withDelimiter(';')); for (CSVRecord csvRecord : parser) { if (teryt.equals(csvRecord.get("teryt")) && okreg.equals(csvRecord.get("Okreg"))) { output += "<p>" + csvRecord.toString() + "</p>"; } } return output; } catch (FileNotFoundException ex) { Logger.getLogger(MyService.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(MyService.class.getName()).log(Level.SEVERE, null, ex); } finally { try { file.close(); } catch (IOException ex) { Logger.getLogger(MyService.class.getName()).log(Level.SEVERE, null, ex); } } return null; }
From source file:io.heming.accountbook.util.Importer.java
public int importRecords(File file) throws Exception { Iterable<CSVRecord> csvRecords; List<Record> records = new ArrayList<>(); try (Reader in = new FileReader(file)) { csvRecords = CSVFormat.EXCEL.withQuote('"') .withHeader("ID", "CATEGORY", "PRICE", "PHONE", "DATE", "NOTE").parse(in); DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); // ??/*from w w w.j av a 2 s. c om*/ categoryFacade.clear(); int i = 0; for (CSVRecord csvRecord : csvRecords) { Integer id = Integer.parseInt(csvRecord.get("ID")); Category category = new Category(csvRecord.get("CATEGORY")); Double price = Double.parseDouble(csvRecord.get("PRICE")); String phone = csvRecord.get("PHONE"); Date date = new Date(format.parse(csvRecord.get("DATE")).getTime()); String note = csvRecord.get("NOTE"); // category? if (!categoryFacade.list().contains(category)) { categoryFacade.add(category); } Record record = new Record(category, price, phone, date); record.setId(id); record.setNote(note); records.add(record); } } // ?? recordFacade.clear(); int i = 0; int total = records.size(); for (Record record : records) { recordFacade.add(record); } return records.size(); }