Author: tchemit Date: 2012-11-21 00:58:38 +0100 (Wed, 21 Nov 2012) New Revision: 3747 Url: http://chorem.org/repositories/revision/pollen/3747 Log: refs #854: Instantoff vote type does not work if there is some null vote (avoid NPE but must recheck results now) Modified: trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategy.java Modified: trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategy.java =================================================================== --- trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategy.java 2012-11-20 23:58:03 UTC (rev 3746) +++ trunk/pollen-votecounting-instant-runoff/src/main/java/org/chorem/pollen/votecounting/InstantRunoffVoteCountingStrategy.java 2012-11-20 23:58:38 UTC (rev 3747) @@ -29,6 +29,7 @@ import org.chorem.pollen.votecounting.model.VoteCountingResult; import org.chorem.pollen.votecounting.model.Voter; +import java.math.BigDecimal; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -63,7 +64,7 @@ Set<String> choiceIdsToExclude = Sets.newHashSet(); Set<String> choiceIdsToKeep = Sets.newHashSet(scores.keySet()); - //FIXME Must use round of elemination to order scores + //FIXME Must use round of elimination to order scores round(topRankChoices, choiceIdsToExclude, choiceIdsToKeep, @@ -76,10 +77,10 @@ } protected void round(Map<Voter, List<Set<String>>> topRankChoices, - Set<String> idsToExclude, - Set<String> idsToInclude, - Map<String, ChoiceScore> resultByChoice, - double totalWeight) { + Set<String> idsToExclude, + Set<String> idsToInclude, + Map<String, ChoiceScore> resultByChoice, + double totalWeight) { List<ChoiceScore> results = applyScores(topRankChoices, idsToExclude, @@ -89,8 +90,8 @@ if (!results.isEmpty()) { // get best score - double max = - results.get(results.size() - 1).getScoreValue().doubleValue(); + BigDecimal scoreValue = results.get(results.size() - 1).getScoreValue(); + double max = scoreValue == null ? 0 : scoreValue.doubleValue(); if (max < totalWeight) { @@ -117,9 +118,9 @@ } protected List<ChoiceScore> applyScores(Map<Voter, List<Set<String>>> topRankChoices, - Set<String> idsToExclude, - Set<String> idsToInclude, - Map<String, ChoiceScore> resultByChoice) { + Set<String> idsToExclude, + Set<String> idsToInclude, + Map<String, ChoiceScore> resultByChoice) { if (CollectionUtils.isNotEmpty(idsToExclude)) { @@ -188,7 +189,7 @@ } protected void guessChoiceIdsToRemove(Set<String> idsToExclude, - List<ChoiceScore> results) { + List<ChoiceScore> results) { double min = results.get(0).getScoreValue().doubleValue(); @@ -196,7 +197,8 @@ for (ChoiceScore choiceScore : results) { - if (min == choiceScore.getScoreValue().doubleValue()) { + BigDecimal scoreValue = choiceScore.getScoreValue(); + if (min == (scoreValue==null?0:scoreValue.doubleValue())) { idsToExclude.add(choiceScore.getChoiceId()); } else {