Project

General

Profile

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

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

    
13
import java.util.List;
14

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

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

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

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

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

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

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

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

    
88
    /**
89
     * Returns the index of the first record in this result set
90
     * @return
91
     */
92
    public Integer getFirstRecord();
93

    
94
    /**
95
     * Returns the index of the last record in this result set
96
     * @return
97
     */
98
    public Integer getLastRecord();
99

    
100
    /**
101
     * Returns the records in this page.
102
     * @return
103
     */
104
    public List<T> getRecords();
105

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

    
114
}
(1-1/2)