package github.pasiahopelto.scorelib.reader;

import java.util.List;

import github.pasiahopelto.scorelib.model.Candidate;
import github.pasiahopelto.scorelib.model.Election;
import github.pasiahopelto.scorelib.model.Party;
import github.pasiahopelto.scorelib.model.Vote;
import github.pasiahopelto.scorelib.model.Voting;

public class EntityJoiner {

	public Election populateWithIds(List<Party> parties, List<Vote> votes, List<Voting> votings) {
		addPartyIds(parties);
		addVotingIds(votings);
		return makeElection(parties, votes, votings);
	}

	private Election makeElection(List<Party> parties, List<Vote> votes, List<Voting> votings) {
		Election election = new Election();
		election.setParties(parties);
		election.setVotes(votes);
		election.setVotings(votings);
		return election;
	}

	private void addVotingIds(List<Voting> votings) {
		int votingId = 1;
		for(Voting voting : votings) {
			voting.setId(votingId++);
		}
	}

	private void addPartyIds(List<Party> parties) {
		int partyId = 1;
		int candidateId = 1;
		for(Party party : parties) {
			party.setId(partyId++);
			for(Candidate candidate : party.getCandidates()) {
				candidate.setId(candidateId++);
			}
		}
	}
}

@@ -443,19 +443,24 @@
 gs) %7B%0A%09%09
-add
+generate
 PartyIds
@@ -472,19 +472,24 @@
 ies);%0A%09%09
-add
+generate
 VotingId
@@ -813,19 +813,24 @@
 te void 
-add
+generate
 VotingId
@@ -963,11 +963,16 @@
 oid 
-add
+generate
 Part

rename entity joiner's id methods