Author: tchemit Date: 2012-11-21 00:59:00 +0100 (Wed, 21 Nov 2012) New Revision: 3748 Url: http://chorem.org/repositories/revision/pollen/3748 Log: refs #855: Coomb vote type does not work if there is some null vote (avoid NPE but must recheck results now) Modified: trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategy.java Modified: trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategy.java =================================================================== --- trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategy.java 2012-11-20 23:58:38 UTC (rev 3747) +++ trunk/pollen-votecounting-coombs/src/main/java/org/chorem/pollen/votecounting/CoombsVoteCountingStrategy.java 2012-11-20 23:59:00 UTC (rev 3748) @@ -30,6 +30,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; @@ -77,10 +78,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, @@ -90,8 +91,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,8 +189,8 @@ } protected void guessChoiceIdsToRemove(Set<String> idsToInclude, - Set<String> idsToExclude, - Map<Voter, List<Set<String>>> results) { + Set<String> idsToExclude, + Map<Voter, List<Set<String>>> results) { // pour chaque choix restant on calcule son score lorsqu'il est le dernier @@ -222,13 +223,15 @@ // puis revers (pour avoir les meilleurs scores au début) Collections.reverse(scores); - double maxScore = scores.get(0).getScoreValue().doubleValue(); + BigDecimal firstScoreValue = scores.get(0).getScoreValue(); + double maxScore = firstScoreValue == null ? 0 : firstScoreValue.doubleValue(); idsToExclude.clear(); for (ChoiceScore choiceScore : scores) { - if (maxScore == choiceScore.getScoreValue().doubleValue()) { + BigDecimal scoreValue = choiceScore.getScoreValue(); + if (maxScore == (scoreValue == null ? 0 : scoreValue.doubleValue())) { idsToExclude.add(choiceScore.getChoiceId()); } else {