001package org.gbif.api.util.iterables;
002
003import org.gbif.api.model.common.paging.PagingRequest;
004import org.gbif.api.model.common.paging.PagingResponse;
005import org.gbif.api.model.registry.Organization;
006import org.gbif.api.service.registry.OrganizationService;
007import org.gbif.api.vocabulary.Country;
008
009import javax.annotation.Nullable;
010
011/**
012 * Pages through all organizations optionally filtering by country.
013 */
014public class OrganizationPager extends EntityPager<Organization> {
015
016    private final OrganizationService service;
017    private final @Nullable Country country;
018
019    public OrganizationPager(OrganizationService service, @Nullable Country country, int pageSize) {
020        super(pageSize);
021        this.service = service;
022        this.country = country;
023    }
024
025    @Override
026    PagingResponse<Organization> nextPage(PagingRequest page) {
027        if (country != null) {
028            return service.listByCountry(country, page);
029        } else {
030            return service.list(page);
031        }
032    }
033
034}