public List<DirtyBicycle> getDirtyBicycles(final Year year, final String file) throws PriceReaderException { List<DirtyBicycle> toReturn = new ArrayList<DirtyBicycle>(); HSSFSheet sheet = getSheet(file, 0); List<PriceRow> rows = getPriceRows(sheet, Brand.STELS); for (PriceRow row : rows) { String dirtyName = row.getModelName().trim(); List<SimpleBicycle> km; if (year.equals(Year.YEAR_2016)) { km = knownModels; } else if (year.equals(Year.YEAR_2015)) { km = knownModels2015; } else { LOGGER.error("YEAR is not defined"); return Collections.emptyList(); } for (SimpleBicycle simpleBicycle : km) { if (simpleBicycle.getDirtyModel().equals(dirtyName.trim())) { DirtyBicycle bicycle = new DirtyBicycle(simpleBicycle); bicycle.setPrice(getRoundedPrice(row.getRetailPrice())); bicycle.setDescription(row.getDescription()); bicycle.setProdCode(CodeGenerator.generateCode(bicycle)); toReturn.add(bicycle); } } } return toReturn; }
private List<SimpleBicycle> getKnownModelList(String filename) { List<SimpleBicycle> list = new ArrayList<SimpleBicycle>(); File file = new File(filename); try { InputStream inputStream = new FileInputStream(file); // CsvReader csvReader = new CsvReader(inputStream, Charset.forName("CP1251")); CsvReader csvReader = new CsvReader(inputStream, Charset.forName("UTF-8")); csvReader.setDelimiter(';'); while (csvReader.readRecord()) { String[] values = csvReader.getValues(); SimpleBicycle simpleBicycle = new SimpleBicycle(); simpleBicycle.setDirtyModel(values[0].trim()); simpleBicycle.setModel(values[1].trim()); simpleBicycle.setWheelSize(WheelSize.getSizeByValue(values[2].trim())); list.add(simpleBicycle); } } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } return list; }