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

org.n3r.quartz.glass.util.Page Maven / Gradle / Ivy

There is a newer version: 0.0.9
Show newest version
package org.n3r.quartz.glass.util;

import java.util.ArrayList;
import java.util.List;

/**
 * A page of results.
 *
 * @author damien bourdette
 */
public class Page {
    /**
     * Query that have been used to get this page.
     */
    private Query query;

    /**
     * All items in current page.
     */
    private List items = new ArrayList();

    /**
     * Total count of items in store.
     */
    private int totalCount;

    private Page() {
        super();
    }

    public static  Page fromQuery(Query query) {
        Page page = new Page();

        page.query = query;

        return page;
    }

    public int getCount() {
        if (totalCount == 0) {
            return 1;
        }

        int pageCount = totalCount / query.getSize();

        if (pageCount * query.getSize() != totalCount) {
            pageCount += 1;
        }

        return pageCount;
    }

    public Query getQuery() {
        return query;
    }

    public List getItems() {
        return new ArrayList(items);
    }

    public void setItems(List items) {
        if (items == null) {
            throw new IllegalArgumentException("Items can not be null");
        }

        this.items = new ArrayList(items);
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy