private Player fromLine(String[] line) { Player m = new Player(); m.setName(line[0]); m.setEmail(line[1]); List<String> instruments = Splitter.on(',').splitToList(line[2]); for (String i : instruments) { Instrument instr = Instrument.valueOf(i); if (i != null) m.addPlayedInstrument(instr); } return m; }
@SuppressWarnings("resource") @LogPerformances(layer = "domain", operation = "loadFile") protected void loadFile() { try { URL resource = PlayerRepositoryImpl.class.getResource(resourceName); CSVReader reader = new CSVReader(new FileReader(resource.getFile()), ';'); String[] line; while ((line = reader.readNext()) != null) { logger.info("Loading record '{}'", Joiner.on("//").join(line)); Player m = fromLine(line); playerById.put(m.getId(), m); } } catch (IOException e) { throw new RuntimeException("Unable to read resource;" + resourceName); } }