Project

General

Profile

Download (3.22 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2009 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9

    
10
package eu.etaxonomy.cdm.api.service.pager;
11

    
12
import java.util.List;
13

    
14
/**
15
 * Abstract class that represents a single page in a set of objects
16
 * returned from a query (possibly a subset of the total number of matching objects
17
 * available).
18
 *
19
 * NOTE: Indices for objects and pages are 0-based.
20
 * @author ben
21
 */
22
public interface Pager<T> {
23
    /**
24
     * The total number of pages available for this query, or 0 if there are
25
     * no matching objects
26
     *
27
     * @return The number of pages available
28
     */
29
    public Integer getPagesAvailable();
30

    
31
    /**
32
     * The index of the next page in this result set, or null if this is the
33
     * last page in the result set.
34
     * @return The index of the next page
35
     */
36
    public Integer getNextIndex();
37

    
38
    /**
39
     * The index of the previous page in this result set, or null if this is the
40
     * first page in the result set.
41
     * @return The index of the previous page
42
     */
43
    public Integer getPrevIndex();
44

    
45
    /**
46
     * The index of this page.
47
     *
48
     * NOTE: Indices for objects and pages are 0-based.
49
     * @return The index of this page
50
     */
51
    public Integer getCurrentIndex();
52

    
53
    /**
54
     * Get a string label for a given page
55
     * (NOTE: Labels may not be calculated for each page in the result set,
56
     *  especially if the result set is large or the operation for calculating the
57
     *  label is expensive. The indices of the pages for which labels are available
58
     *  are given by {@link #getIndices()}.
59
     *
60
     * @param index
61
     * @return A label for the page indicated or null if this pager has not calculated a label for that page
62
     */
63
    public String getPageNumber(int index);
64

    
65
    /**
66
     * Gets the size of pages in this result set. Can be null if all matching
67
     * objects should be returned.
68
     * @return The page size
69
     */
70
    public Integer getPageSize();
71

    
72
    /**
73
     * Get a list of page indices for which labels are available.
74
     * @return A list of indices
75
     */
76
    public List<Integer> getIndices();
77

    
78
    /**
79
     * Get the total number of objects in this result set (not in this page).
80
     * If count > {@link #getPageSize()} then {@link #getPagesAvailable()} > 1
81
     * @return the total number of objects available.
82
     */
83
    public Long getCount();
84

    
85
    /**
86
     * Returns the index of the first record in this result set
87
     * @return
88
     */
89
    public Integer getFirstRecord();
90

    
91
    /**
92
     * Returns the index of the last record in this result set
93
     * @return
94
     */
95
    public Integer getLastRecord();
96

    
97
    /**
98
     * Returns the records in this page.
99
     * @return
100
     */
101
    public List<T> getRecords();
102

    
103
    /**
104
     * Returns a suggested query string (only applicable for free-text / lucene queries).
105
     *
106
     * Usually only calculated if there were no matching results for the original query.
107
     * @return
108
     */
109
    public String getSuggestion();
110

    
111
}
(1-1/3)