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.Dataset;
006import org.gbif.api.service.registry.DatasetService;
007import org.gbif.api.vocabulary.DatasetType;
008
009import javax.annotation.Nullable;
010
011/**
012 * Pages through all datasets filtering by type only.
013 */
014public class DatasetPager extends DatasetBasePager {
015
016    private final DatasetService ds;
017    private final DatasetType type;
018
019    public DatasetPager(DatasetService ds, @Nullable DatasetType type, int pageSize) {
020        super(type, pageSize);
021        this.ds = ds;
022        this.type = type;
023    }
024
025    @Override
026    PagingResponse<Dataset> nextPage(PagingRequest page) {
027        if (type == null) {
028            return ds.list(page);
029        } else {
030            return ds.listByType(type, page);
031        }
032    }
033
034}