Skip to content

Commit e2ec8be

Browse files
committed
Use collector for dominion gatherUnknownCandidates function
1 parent 9a6f4a6 commit e2ec8be

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/main/java/network/brightspots/rcv/DominionCvrReader.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,12 @@ public Set<RawContestConfig.Candidate> gatherUnknownCandidates(
247247
}
248248

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

252-
Set<RawContestConfig.Candidate> unknownCandidates = new HashSet<>();
253-
for (Map.Entry<String, Candidate> entry : codesFoundInManifest) {
254-
Candidate candidate = entry.getValue();
255-
if (knownNames.contains(candidate.name)) {
256-
continue;
257-
}
258-
unknownCandidates.add(new RawContestConfig.Candidate(candidate.name, entry.getKey(), false));
259-
}
260-
261-
return unknownCandidates;
251+
// Return the candidate codes that are not in the knownNames set
252+
return candidateCodesToCandidates.entrySet().stream()
253+
.filter(entry -> !knownNames.contains(entry.getValue().name))
254+
.map(entry -> new RawContestConfig.Candidate(entry.getValue().name, entry.getKey()))
255+
.collect(Collectors.toSet());
262256
}
263257

264258
// parse the CVR file or files into a List of CastVoteRecords for tabulation

src/main/java/network/brightspots/rcv/RawContestConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ public static class Candidate {
304304
this(name, null, false);
305305
}
306306

307+
Candidate(String name, String newlineSeparatedAliases) {
308+
this(name, newlineSeparatedAliases, false);
309+
}
310+
307311
Candidate(String name, String newlineSeparatedAliases, boolean excluded) {
308312
this.name.setValue(name);
309313
this.excluded.setValue(excluded);

0 commit comments

Comments
 (0)