Skip to content

Commit

Permalink
Use collector for dominion gatherUnknownCandidates function
Browse files Browse the repository at this point in the history
  • Loading branch information
artoonie committed Jan 9, 2025
1 parent 9a6f4a6 commit e2ec8be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/main/java/network/brightspots/rcv/DominionCvrReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,12 @@ public Set<RawContestConfig.Candidate> gatherUnknownCandidates(
}

Set<String> knownNames = config.getCandidateNames();
Set<Map.Entry<String, Candidate>> codesFoundInManifest = candidateCodesToCandidates.entrySet();

Set<RawContestConfig.Candidate> unknownCandidates = new HashSet<>();
for (Map.Entry<String, Candidate> entry : codesFoundInManifest) {
Candidate candidate = entry.getValue();
if (knownNames.contains(candidate.name)) {
continue;
}
unknownCandidates.add(new RawContestConfig.Candidate(candidate.name, entry.getKey(), false));
}

return unknownCandidates;
// Return the candidate codes that are not in the knownNames set
return candidateCodesToCandidates.entrySet().stream()
.filter(entry -> !knownNames.contains(entry.getValue().name))
.map(entry -> new RawContestConfig.Candidate(entry.getValue().name, entry.getKey()))
.collect(Collectors.toSet());
}

// parse the CVR file or files into a List of CastVoteRecords for tabulation
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/network/brightspots/rcv/RawContestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,10 @@ public static class Candidate {
this(name, null, false);
}

Candidate(String name, String newlineSeparatedAliases) {
this(name, newlineSeparatedAliases, false);
}

Candidate(String name, String newlineSeparatedAliases, boolean excluded) {
this.name.setValue(name);
this.excluded.setValue(excluded);
Expand Down

0 comments on commit e2ec8be

Please sign in to comment.