class SourceOrigins {

    public ApiLevel getApiLevelByVersion(Version version) {
        ApiLevel last = null;

        Iterator<ApiLevel> reviter = apilevels.descendingIterator();
        int diff;
        while (reviter.hasNext()) {
            ApiLevel api = reviter.next();
            diff = api.getVersion().compareTo(version);
            if (diff > 0) {
                // Too small
                last = api;
                continue; // Skip
            } else if (diff == 0) {
                // Exact match
                return api;
            } else {
                // Too large
                return last;
            }
        }
        return last;
    }

}