parent
845ed67a21
commit
b8739d61f7
@ -0,0 +1,35 @@
|
|||||||
|
package fr.mieuxvoter.mj;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
|
||||||
|
public class TallyWithDefaultGrade extends Tally implements TallyInterface {
|
||||||
|
|
||||||
|
protected Integer defaultGrade = 0;
|
||||||
|
|
||||||
|
public TallyWithDefaultGrade(ProposalTallyInterface[] proposalsTallies, Integer amountOfJudges, Integer defaultGrade) {
|
||||||
|
super(proposalsTallies, amountOfJudges);
|
||||||
|
this.defaultGrade = defaultGrade;
|
||||||
|
fillWithDefaultGrade();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TallyWithDefaultGrade(ProposalTallyInterface[] proposalsTallies, Long amountOfJudges, Integer defaultGrade) {
|
||||||
|
super(proposalsTallies, amountOfJudges);
|
||||||
|
this.defaultGrade = defaultGrade;
|
||||||
|
fillWithDefaultGrade();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fillWithDefaultGrade() {
|
||||||
|
int amountOfProposals = getAmountOfProposals();
|
||||||
|
for (int i = 0 ; i < amountOfProposals ; i++) {
|
||||||
|
ProposalTallyInterface proposal = getProposalsTallies()[i];
|
||||||
|
BigInteger amountOfJudgments = proposal.getAmountOfJudgments();
|
||||||
|
BigInteger missingAmount = BigInteger.valueOf(this.amountOfJudges).subtract(amountOfJudgments);
|
||||||
|
int missingSign = missingAmount.compareTo(BigInteger.ZERO);
|
||||||
|
assert(0 <= missingSign); // More judgments than judges!
|
||||||
|
if (0 < missingSign) {
|
||||||
|
proposal.getTally()[this.defaultGrade] = proposal.getTally()[this.defaultGrade] + missingAmount.longValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue