TeamResolver teamResolver = new TeamResolver(teams);
while ((line = ridersReader.readLine()) != null) {
if (StringUtils.isNotBlank(line)) {
String[] tokens = line.trim().split(";");
String riderName = tokens[0].trim();
Rider rider = new Rider(riderName);
rider.setTeamsHistory(new ArrayList<TeamRiderHistory>());
for (int i = 1; i < tokens.length; i += 2) {
Integer year = Integer.valueOf(tokens[i].trim());
String teamName = tokens[i + 1].trim();
Team team = teamResolver.resolve(teamName);
if (team != null) {
TeamRiderHistory trh = new TeamRiderHistory();
trh.setYear(year);
trh.setRider(rider);
trh.setTeam(team);
rider.getTeamsHistory().add(trh);
} else {
System.out.println("Unable to resolve: " + teamName);
}
}
em.persist(rider);