public static new ApprovalBallot Parse(int candidateCount, string source) { var approvalsByCanidate = new bool[candidateCount]; foreach (var c in source) { approvalsByCanidate[ParsingUtility.DecodeCandidateIndex(c)] = true; } return(new ApprovalBallot(approvalsByCanidate)); }
public static BucketBallot <T> Parse(int candidateCount, string source) { var bucketsByCandidate = new T[candidateCount]; foreach (var bucket in source.Split(' ')) { var splits = bucket.Split(':'); var bucketValue = Enum.Parse <T>(splits[0]); foreach (var c in splits[1]) { bucketsByCandidate[ParsingUtility.DecodeCandidateIndex(c)] = bucketValue; } } return(new BucketBallot <T>(bucketsByCandidate)); }
public static ScoreBallot Parse(int candidateCount, string source) { var scoresByCandidate = new int[candidateCount]; foreach (var bucket in source.Split(' ')) { var splits = bucket.Split(':'); if (splits.Length != 2) { throw new InvalidOperationException($"Expected exactly one `:`, got '{bucket}' instead."); } var bucketValue = int.Parse(splits[0]); foreach (var c in splits[1]) { scoresByCandidate[ParsingUtility.DecodeCandidateIndex(c)] = bucketValue; } } return(new ScoreBallot(scoresByCandidate)); }