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

org.sejda.model.pdf.page.PredefinedSetOfPages Maven / Gradle / Ivy

There is a newer version: 5.1.6
Show newest version
package org.sejda.model.pdf.page;

import java.util.SortedSet;
import java.util.TreeSet;

import org.sejda.model.FriendlyNamed;

/**
 * Represent a predefined set of pages like odd or even pages.
 * 
 * @author Andrea Vacondio
 * 
 */
public enum PredefinedSetOfPages implements PagesSelection, FriendlyNamed {
    ALL_PAGES("all") {
        @Override
        public SortedSet getPages(int totalNumberOfPage) {
            SortedSet retSet = new TreeSet<>();
            for (int i = 1; i <= totalNumberOfPage; i++) {
                retSet.add(i);
            }
            return retSet;
        }

        @Override
        public boolean includes(int page) {
            return true;
        }
    },
    EVEN_PAGES("even") {
        @Override
        public SortedSet getPages(int totalNumberOfPage) {
            SortedSet retSet = new TreeSet<>();
            for (int i = 2; i <= totalNumberOfPage; i = i + 2) {
                retSet.add(i);
            }
            return retSet;
        }

        @Override
        public boolean includes(int page) {
            return page % 2 == 0;
        }
    },
    ODD_PAGES("odd") {
        @Override
        public SortedSet getPages(int totalNumberOfPage) {
            SortedSet retSet = new TreeSet<>();
            for (int i = 1; i <= totalNumberOfPage; i = i + 2) {
                retSet.add(i);
            }
            return retSet;
        }

        @Override
        public boolean includes(int page) {
            return page % 2 == 1;
        }

    },
    NONE("none") {
        @Override
        public SortedSet getPages(int totalNumberOfPage) {
            return new TreeSet<>();
        }

        @Override
        public boolean includes(int page) {
            return false;
        }
    };

    /**
     * @param totalNumberOfPage
     *            the number of pages of the document (upper limit).
     * @return the selected set of pages ordered using their natural ordering.
     * @see PagesSelection#getPages(int)
     */
    @Override
    public abstract SortedSet getPages(int totalNumberOfPage);

    public abstract boolean includes(int page);

    private final String displayName;

    PredefinedSetOfPages(String displayName) {
        this.displayName = displayName;
    }

    @Override
    public String getFriendlyName() {
        return displayName;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy