All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sejda.model.parameter.ExcludedPagesSelection Maven / Gradle / Ivy

/*
 * Copyright 2016 by Eduard Weissmann ([email protected]).
 *
 * This file is part of the Sejda source code
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see .
 */
package org.sejda.model.parameter;

import java.util.Collection;
import java.util.Set;

import org.sejda.commons.collection.NullSafeSet;
import org.sejda.model.pdf.page.PageRange;

public interface ExcludedPagesSelection {

    Set getExcludedPagesSelection();

    default void addExcludedPage(Integer page) {
        addExcludedPageRange(new PageRange(page, page));
    }

    default void addExcludedPageRange(PageRange range) {
        getExcludedPagesSelection().add(range);
    }

    default void addAllExcludedPageRanges(Collection ranges) {
        getExcludedPagesSelection().addAll(ranges);
    }

    /**
     * @param upperLimit
     *            the number of pages of the document (upper limit).
     * @return the set of excluded pages.
     */
    default Set getExcludedPages(int upperLimit) {
        Set pages = new NullSafeSet<>();
        for (PageRange range : getExcludedPagesSelection()) {
            pages.addAll(range.getPages(upperLimit));
        }
        return pages;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy