List<HobbyPractician> hobbyPracticianList = new ArrayList<HobbyPractician>(guestSize * 3);
Map<String, Job> jobMap = new HashMap<String, Job>(JobType.values().length * 5);
int jobNextId = 0;
int hobbyPracticianJobId = 0;
for (int i = 0; i < guestSize; i++) {
Guest guest = new Guest();
guest.setId((long) i);
String line = bufferedReader.readLine();
String[] lineTokens = line.split("\\,");
if (lineTokens.length < 5) {
throw new IllegalArgumentException("Read line (" + line
+ ") is expected to contain at least 5 tokens.");
}
guest.setCode(lineTokens[0].trim());
JobType jobType = JobType.valueOfCode(lineTokens[1].trim());
String jobName = lineTokens[2].trim();
String jobMapKey = jobType + "/" + jobName;
Job job = jobMap.get(jobMapKey);
if (job == null) {
job = new Job();
job.setId((long) jobNextId);
jobNextId++;
job.setJobType(jobType);
job.setName(jobName);
jobMap.put(jobMapKey, job);
}
guest.setJob(job);
guest.setGender(Gender.valueOfCode(lineTokens[3].trim()));
List<HobbyPractician> hobbyPracticianOfGuestList = new ArrayList<HobbyPractician>(lineTokens.length - 4);
for (int j = 4; j < lineTokens.length; j++) {
HobbyPractician hobbyPractician = new HobbyPractician();
hobbyPractician.setId((long) hobbyPracticianJobId);
hobbyPracticianJobId++;
hobbyPractician.setGuest(guest);
hobbyPractician.setHobby(Hobby.valueOfCode(lineTokens[j].trim()));
hobbyPracticianOfGuestList.add(hobbyPractician);
hobbyPracticianList.add(hobbyPractician);
}
guest.setHobbyPracticianList(hobbyPracticianOfGuestList);
guestList.add(guest);
}
manners2009.setJobList(new ArrayList<Job>(jobMap.values()));
manners2009.setGuestList(guestList);
manners2009.setHobbyPracticianList(hobbyPracticianList);