Skip to content

Commit

Permalink
simplify conversion from names to candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
artoonie committed Jan 9, 2025
1 parent ac138db commit 9a6f4a6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/main/java/network/brightspots/rcv/BaseCvrReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javafx.util.Pair;
import network.brightspots.rcv.RawContestConfig.Candidate;
import network.brightspots.rcv.RawContestConfig.CvrSource;
Expand Down Expand Up @@ -118,15 +119,9 @@ public Map<Candidate, Integer> gatherUnknownCandidateCounts(
}
}

Map<Candidate, Integer> unrecognizedCandidateCounts = new HashMap<>();
for (Map.Entry<String, Integer> entry : unrecognizedNameCounts.entrySet()) {
String candidateName = entry.getKey();
int count = entry.getValue();
Candidate candidate = new Candidate(candidateName, null, false);
unrecognizedCandidateCounts.put(candidate, count);
}

return unrecognizedCandidateCounts;
// Change the map to use Candidate objects instead of names
return unrecognizedNameCounts.entrySet().stream()
.collect(Collectors.toMap(entry -> new Candidate(entry.getKey()), Map.Entry::getValue));
}

Set<Candidate> gatherUnknownCandidates(List<CastVoteRecord> castVoteRecords)
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 @@ -300,6 +300,10 @@ public static class Candidate {

Candidate() {}

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

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

0 comments on commit 9a6f4a6

Please sign in to comment.