# Reference patch — 03-minimum-ratings-threshold

The answer key for how the reference absorbs this change. **Never shipped to the candidate.**

1. **Replace** `reference/src/RatingSystem.java` with the version in this directory. The change is
   two `@Override` methods appended after `topN(int)`: `leaderboard(int minimumRatings)` filters
   the existing `leaderboard()` by `AgentRating::ratingCount`, and `topN(int, int)` delegates to
   `Rankings.topN` over that filtered list. See `edits.json` for the exact insertion.
2. `contract-delta/RatingSystemApi.java` is the given, revised interface — the two new overloads
   and their javadoc. Contract files are excluded from the diff measurement.

No other file was opened. `AgentRatingBook`, `InMemoryAgentRatingBook`, `RankingOrder`, `Rankings`,
`AveragingStrategy`, `SimpleMeanStrategy`, `RatingSystemFactory` and `Validation` all stayed
exactly as they were.

Measured: `reference_diff = 11` (one file touched, eleven lines added, zero removed, no new
files), so `diff_budget = max(3, 11 + ceil(11/2)) = 17`.

## Why this cost so little

`leaderboard()` was already a pure function from the book's current contents to an ordered list —
nothing about it needed to become "aware" of a threshold to be filtered afterwards. Filtering an
already-ordered list preserves the order for free, which is why `leaderboard(int)` does not need
to sort again or restate the tie-break rule: the eleven lines added here contain no comparator at
all, because `RankingOrder` already owns the only one that exists.

The instinct that would have cost more is threading a `minimumRatings` parameter down into
`AgentRatingBook` or `Rankings` themselves — either would have opened an interface that four other
call sites already depend on, for a rule that is purely about which rows a caller wants to see,
not about how ratings are stored or how a tie is broken. Filtering above both of those seams,
rather than inside either of them, is what kept them untouched.

The test worth watching in a candidate's design is the third one, which checks that the tie-break
rule still applies correctly among the agents who survive the filter — a design that filtered
after truncating to N, rather than before, would produce a top-N shorter than N even when enough
qualifying agents exist.
