1 package civitas.common.ballot;
2
3 import org.springframework.beans.factory.annotation.Autowired;
4 import org.springframework.stereotype.Controller;
5
6 import civitas.common.VoteChoice;
7 import civitas.common.ballotdesign.CalculateBallotLength;
8
9 @Controller
10 public class CreateEmptyBallot {
11
12 @Autowired
13 CalculateBallotLength calculateBallotLength;
14
15 public Ballot apply(final int numCandidates) {
16 if (numCandidates < 2) {
17 throw new IllegalArgumentException("A ballot must contain at least one candidate and none of above");
18 }
19 int size = calculateBallotLength.apply(numCandidates);
20 VoteChoice[] matrix = new VoteChoice[size];
21 return new Ballot(size, matrix);
22 }
23 }