1 package org.unicode.cldr.util; 2 3 import java.util.HashMap; 4 import java.util.Map; 5 import java.util.TreeMap; 6 7 public class VoterProgress { 8 9 /** 10 * The number of paths for which this user is expected to vote (in this locale, limited by the 11 * coverage level) 12 */ 13 private int votablePathCount = 0; 14 15 /** 16 * The number of paths for which this user already has voted (in this locale, limited by the 17 * coverage level) 18 */ 19 private int votedPathCount = 0; 20 21 /** 22 * The number of paths for which this user already has voted, broken down by specific VoteType 23 */ 24 private Map<VoteType, Integer> votedTypeCount = null; 25 26 /* 27 * These "get" methods are called automatically by the API to produce json 28 */ getVotablePathCount()29 public int getVotablePathCount() { 30 return votablePathCount; 31 } 32 getVotedPathCount()33 public int getVotedPathCount() { 34 return votedPathCount; 35 } 36 getTypeCount()37 public Map<String, Integer> getTypeCount() { 38 if (votedTypeCount == null) { 39 return null; 40 } 41 // JSON serialization requires String (not VoteType) for key 42 Map<String, Integer> map = new TreeMap(); 43 for (VoteType voteType : votedTypeCount.keySet()) { 44 map.put(voteType.name(), votedTypeCount.get(voteType)); 45 } 46 return map; 47 } 48 incrementVotablePathCount()49 public void incrementVotablePathCount() { 50 votablePathCount++; 51 } 52 incrementVotedPathCount(VoteType voteType)53 public void incrementVotedPathCount(VoteType voteType) { 54 if (voteType == null || voteType == VoteType.NONE) { 55 throw new IllegalArgumentException("null/NONE not allowed for incrementVotedPathCount"); 56 } 57 votedPathCount++; 58 if (votedTypeCount == null) { 59 votedTypeCount = new HashMap<>(); 60 } 61 votedTypeCount.put(voteType, votedTypeCount.getOrDefault(voteType, 0) + 1); 62 } 63 } 64